Skip to content

Instantly share code, notes, and snippets.

@cypherdare
Created January 20, 2016 00:14
Show Gist options
  • Save cypherdare/bbe26946a2155c82a33d to your computer and use it in GitHub Desktop.
Save cypherdare/bbe26946a2155c82a33d to your computer and use it in GitHub Desktop.
/*******************************************************************************
* Copyright 2016 Cypher Cove LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.cyphercove.dayinspace.desktop;
import com.badlogic.gdx.tools.texturepacker.TexturePacker;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import java.io.File;
import java.util.Collection;
public class TexturePackerRunner {
static final String SOURCE_DIR = "planning/Texture Atlas";
static final String TARGET_DIR = "core/assets";
static final String ATLAS_EXTENSION = ".pack";
static final String ATLAS_NAME = "myAtlas";
public static void main (String[] args) throws Exception {
//Delete old pack
File oldPackFile = new File(TARGET_DIR + "/" + ATLAS_NAME + ATLAS_EXTENSION);
if (oldPackFile.exists()){
System.out.println("Deleting old pack file");
oldPackFile.delete();
}
//Delete old font files
Collection<File> oldFontFiles = FileUtils.listFiles(
new File(TARGET_DIR),
new RegexFileFilter(".*\\.fnt"),
TrueFileFilter.INSTANCE
);
for (File file : oldFontFiles){
System.out.println("Copying font file: " + file.getName());
FileUtils.deleteQuietly(file);
}
//Pack them
TexturePacker.Settings settings = new TexturePacker.Settings();
settings.atlasExtension = ATLAS_EXTENSION;
TexturePacker.process(
settings,
SOURCE_DIR,
TARGET_DIR,
ATLAS_NAME);
//Copy over any fonts
Collection<File> fontFiles = FileUtils.listFiles(
new File(SOURCE_DIR),
new RegexFileFilter(".*\\.fnt"),
TrueFileFilter.INSTANCE
);
File destDir = new File(TARGET_DIR);
for (File file : fontFiles){
System.out.println("Copying font file: " + file.getName());
FileUtils.copyFileToDirectory(file, destDir);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment