Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package randomizer;
- import java.awt.Graphics;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import java.util.Scanner;
- import javax.imageio.ImageIO;
- import org.apache.commons.io.FileUtils;
- // Alternate version of the program that moves everything right into the pack folder and deletes the previous mod!
- public class RunAndMove {
- // Set filepath
- static String path = "E:\\User\\Documents\\Game Stuff\\Spelunky 2\\Randomizing\\Biome skins";
- static String dest_path = "D:\\Program Files (x86)\\Steam\\steamapps\\common\\Spelunky 2\\Mods\\Packs\\Cool_tilesets";
- static String alreadyUsed = "";
- static String blockedSkins = "";
- public static void main(String[] args) throws IOException {
- // Clean the output folder first
- System.out.println("Cleaning pack folder...\n");
- File directory = new File(dest_path);
- FileUtils.cleanDirectory(directory);
- // Read the list of tilesets
- // Create array
- List<String> skinGroups = new ArrayList<String>();
- //Start the scanner
- File f = new File(path + "\\source_files\\folder_list.txt");
- Scanner s = new Scanner(f);
- System.out.println("Reading folder list...\n");
- //Go through the lines and save them into the array
- while(s.hasNext()) {
- String line = s.nextLine();
- if(!line.substring(0,2).equals("//")){
- skinGroups.add(line);
- }
- }
- s.close();
- // Read the list of globally blocked skins
- //Start the scanner
- File fNew = new File(path + "\\source_files\\blacklist.txt");
- Scanner sNew = new Scanner(fNew);
- System.out.println("Reading blacklist...");
- //Go through the lines and save them into the array
- while(sNew.hasNext()) {
- String lineNew = sNew.nextLine();
- if(!lineNew.substring(0,2).equals("//")){
- blockedSkins = blockedSkins + "," + lineNew + ",";
- }
- }
- sNew.close();
- System.out.println("Skin blacklist:\n" + blockedSkins + "\n");
- // Call the actual function once for each skin pack
- for(int x = 0; x < skinGroups.size(); x++) {
- randomize(skinGroups.get(x));
- }
- System.out.println("\nCompletely done!");
- }
- public static void combineImages(File source, File dest) throws IOException {
- // Load source images
- BufferedImage base = ImageIO.read(dest);
- BufferedImage overlay = ImageIO.read(source);
- // Create the new image, canvas size is the max. of both image sizes
- int w = Math.max(base.getWidth(), overlay.getWidth());
- int h = Math.max(base.getHeight(), overlay.getHeight());
- BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
- // Paint both images, preserving the alpha channels
- Graphics g = combined.getGraphics();
- g.drawImage(base, 0, 0, null);
- g.drawImage(overlay, 0, 0, null);
- g.dispose();
- // Overwrite the first image (used in output)
- ImageIO.write(combined, "PNG", dest);
- }
- // Function that basically does everything
- public static void randomize(String biomeName) throws IOException {
- // Create skins array
- List<String> skinList = new ArrayList<String>();
- //Start the scanner with our specified folder path from the main
- File f2 = new File(path + "\\source_files\\" + biomeName + "_skins\\skin_list.txt");
- Scanner s2 = new Scanner(f2);
- //Go through the lines and save them into the array unless they are commented out or have already been used or are on the blocklist
- while(s2.hasNext()) {
- String line2 = s2.nextLine();
- if(!line2.substring(0,2).equals("//") && !alreadyUsed.contains("," + line2 + ",") && !blockedSkins.contains("," + line2 + ",")){
- skinList.add(line2);
- }
- }
- s2.close();
- System.out.println("\n" + biomeName + " skin list:\n" + skinList);
- // Create file names array
- List<String> targetFiles = new ArrayList<String>();
- //Start the scanner with our specified folder path from the main
- File f3 = new File(path + "\\source_files\\" + biomeName + "_skins\\target_filenames.txt");
- Scanner s3 = new Scanner(f3);
- //Go through the lines and save them into the array unless they are commented out
- while(s3.hasNext()) {
- String line3 = s3.nextLine();
- if(!line3.substring(0,2).equals("//")){
- targetFiles.add(line3);
- }
- }
- s3.close();
- // Pick random skin from the first array
- Random random = new Random();
- String chosenSkin = skinList.get(random.nextInt(skinList.size()));
- // Save the chosen skin to the list of already used ones
- alreadyUsed = alreadyUsed + "," + chosenSkin + ",";
- // Copy the correct files to the output folder
- System.out.println("Copying " + biomeName + " files...");
- for(int i = 0; i < targetFiles.size(); i++) {
- // If the filename needs to be exact then do it differently!
- if(targetFiles.get(i).contains("exact=")) {
- // Modify the filename first
- File source = new File(path + "\\source_files\\" + biomeName + "_skins\\" + chosenSkin + "\\" + targetFiles.get(i).substring(6) + ".png");
- File dest = new File(dest_path + "\\" + targetFiles.get(i).substring(6) + ".png");
- // If the destination file already exists then combine it with the new one
- if(dest.isFile()) {
- combineImages(source, dest);
- } else {
- FileUtils.copyFile(source, dest);
- }
- } else {
- File source = new File(path + "\\source_files\\" + biomeName + "_skins\\" + chosenSkin + "\\" + targetFiles.get(i) + chosenSkin + ".png");
- File dest = new File(dest_path + "\\" + targetFiles.get(i) + biomeName + ".png");
- // If the destination file already exists, combine it with the new one
- if(dest.isFile()) {
- combineImages(source, dest);
- } else {
- FileUtils.copyFile(source, dest);
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment