Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Need Java Help and Ideas for Ambitious Project  (Read 596 times)

RebelZhouYuWu

  • Bay Watcher
    • View Profile
Need Java Help and Ideas for Ambitious Project
« on: September 30, 2009, 09:19:10 am »

I am currently working on a project to help make modding much easier.  Most of the time, modding gets difficult because you are working with tons of tags coded in notepad and having no easy way to check your tags to see if you get them right.  What this project intends to do is to take notepad out of the equation.  This program will basically be a GUI dwarf mod editor that includes list of all the tags in the game, descriptions on all the tags, and the ability to check the mod for common mistakes.  I have already began work on this project (My happiest moment was when the program successfully determined that the notepad document contained a list of body parts), but I have some problems that unless I find a solution for will make the program a lot less user friendly.

1.  How can I easily make a runnable program out of the java class files that doesn't require the user to manually open command prompt and tell the computer to run the files.

2.  How can I tell a java program to check all text documents in a folder, the best workaround to this that I have is that it will store data on all the files of a mod but it will require a user to have to manually type in each file name for a mod when trying to upload a mod to the program.


Also, one of the main features I plan to include in this project is a scanner that will check the mod for any errors that might mess up game play, I know to check for stuff like duplicate sets of creatures, but is there any other errors that you can think of that I could program the scanner to check for, and what other features might you want in this program.
Logged

Slogo

  • Bay Watcher
    • View Profile
Re: Need Java Help and Ideas for Ambitious Project
« Reply #1 on: September 30, 2009, 09:34:52 am »

Use a batch file (Windows) and a shell script (Unix/Linux) would be the easiest way I think.  You can also make an executable jar: http://www.excelsior-usa.com/articles/java-to-exe.html

http://www.exampledepot.com/egs/java.io/GetFiles.html

DgnBiscuit

  • Bay Watcher
  • Has been nauseated by the sun lately.
    • View Profile
Re: Need Java Help and Ideas for Ambitious Project
« Reply #2 on: October 01, 2009, 02:33:32 pm »

1.  How can I easily make a runnable program out of the java class files that doesn't require the user to manually open command prompt and tell the computer to run the files.

Self-executing jars are the best way to do this. If you're writing your java code in Eclipse, right-click on the program file (the one with the main class) and select "Export". You'll have to select which file you want as the main class and be guided through the rest of the process with a wizard. At the end you'll have a jar that you can double click in the UI of any operating system that supports java.

2.  How can I tell a java program to check all text documents in a folder, the best workaround to this that I have is that it will store data on all the files of a mod but it will require a user to have to manually type in each file name for a mod when trying to upload a mod to the program.

This takes a little more logic. If you look at the File class in the java 6 api you'll see that you can filter a folder for files of a given type (I suggest using the listFiles(FilenameFilter)method). What you'll probably want to do is write a recursive algorithm that extracts the locations of all of the text files, e.g.

Code: [Select]

FilenameFilter filter = new FilenameFilter(){

     public boolean accept(File dir, String name) {
          return dir.isDirectory() || name.endsWith(".txt");
     }
};

Vector<File> myRecursiveAlgorithm(File folder, Vector<File> files){
     if(files == null) files = new Vector<File>();

     for(File file : folder.listFiles(filter))
           if(file.isDirectory()){
                myRecursiveAlgorithm(file,files);
           }else{
                files.add(file);
           }     
     }
     return files;
}

That will give you all ".txt" files in all directories under and including the one that you give it as a Vector of files.

-DB
Logged
Urist McKitten has been ecstatic lately. Urist McKitten can has cheezburger lately.
Here at Bay12, we're constantly looking for ways to set the world on fire.