Page 1 of 3

I/O reworking

PostPosted: 20 Aug 2009, 20:54
by silly freak
hi!

I want to rework the current system of finding files, which is mostly "everything is in the current working directory". In my opinion, it's only necessary to keep one file in an expected location, and everything else can be referenced there. this would save the "save all-decks and move it back" by just pointing to the old one.
i have already worked out a class for handling this in a very flexible and easy-to-use way (both from programmer's and user's perspective). the important thing now is to know at what places forge metions external sources, from card images to decks, rarities and so on. would be nice if someone already had a list ;)

PS: i would post the source now, but don't have my USB stick handy...

Re: I/O reworking

PostPosted: 21 Aug 2009, 17:28
by mtgrares
The important thing now is to know at what places forge metions external sources, from card images to decks, rarities and so on. would be nice if someone already had a list.
Let me try to briefly explain all of the external files that MTG Forge reads.


all-decks2 - holds all of the decks, I think DeckIO creates this file

AllTokens.txt - holds info relating to tokens
booster-decks - holds only booster decks, this tries to prevent some booster deck IO problems
card-pictures.txt - gets card pics and URL
cards.txt - raw text on Magic cards
common.txt, uncommon.txt, rare.txt - used to create packs for sealed and booster draft, I think ReadBoosterPack or something like it reads these files

name-mutator.txt - Used by NameChanger.java (I think) and CardFactory, this is old and can be removed except that some of the code tries to read it, so I haven't deleted it just to make everything work, this renames all of the Magic cards (at the time).
quest-common.txt, quest-rare.txt, quest-uncommon.txt - used by Quest_ReadBoosterDraft to create packs that are won during a quest

questData - holds quest save data, cardpool, human and AI decks
questDecks-easy.txt, questDecks-hard.txt, questDecks-medium.txt - stores which AI decks are easy, med, or hard read by QuestData.java (I think)

tokens.txt - I don't know if this file is currently used or is old

Technically the Gui_DeckEditor.java reads up.gif and down.gif and uses the pictures for the add and remove buttons but these files aren't required (apparantly).

Re: I/O reworking

PostPosted: 21 Aug 2009, 19:58
by Rob Cashwalker
tokens.txt isn't part of MTGForge proper. I put it together at one point to support the card generator.

Re: I/O reworking

PostPosted: 21 Aug 2009, 23:34
by silly freak
thanks for the tips, I was more interested in references in the source code ;)
nonetheless, i have something to present. changing all the file accesses in forge will take a little longer, but two things are ready:
the first is the source of my property files mechanism. the class javadoc of TreeProperties should explain it quite well

the second are properties-files and the normal forge files in a new structure that I prefer. the structure is of course not mandatory, it's just my two cents
Interesting is that the only line in forge.properties states that the real properties are somewhere else ;)

EDIT: i replaced the properties-archive, it contained the out-of-date quest data. and now, i don't get errors anymore, so i can also share the changes I had to make to the forge code

Re: I/O reworking

PostPosted: 11 Sep 2009, 17:38
by silly freak
i'm pretty much done with what i wanted to do. that is:

  • all file accesses in forge now use configurable locations from the properties files
  • forge is somewhat "internationalization-ready".
    the parts that can be translated are
    • some dialogs of the BoosterDraft screen
    • big parts of GuiDisplay3 - including menus and zones
    • the picture download window
    • the error viewer (it will also work - in english - if the language files are missing)
    • the how to play window - uses the new version by chris
    • the menus of Gui_NewGame
  • the L&F list is generated from UIManager.getInstalledLookAndFeels
  • Gui_NewGame and GuiDisplay3 contain a menu item for showing an error report. this may help for the "computer is thinking" error, if it doesn't shut down the gui
  • i have renewed the list choosing dialog:
    • you can close the dialog by double clicking an option
    • it uses generics - you don't have to cast the result to the original type
    • it's possible to specify both the minimum and the maximum number of choices: 0,1 is an optional choice, 1,1 is a mandatory choice. 1,Integer.MAX_VALUE would be one or more.
    • the new dialog is used in Display.getChoice[Optional], and for the card size and L&F choosers
before I release my sources, i'd like to know what about packages? however, here is the resource file structure

Re: I/O reworking

PostPosted: 14 Sep 2009, 00:15
by DennisBergkamp
Do these files include your updates ? (which, looking at the list, look awesome by the way!)
I think it's time for a new version soon, so I'm starting to merge everything that's been submitted :)

I like your new way of packaging the Forge, I think we should go for that one.

Re: I/O reworking

PostPosted: 14 Sep 2009, 09:35
by silly freak
these two archives include the same information. that is, the external forge files (such as cards.txt, all-decks2 and so on), including additional property files by me for internationalization and such. these files include the how-to as discussed

the difference between the both is that the "classic" archive contains all existing files in the root folder, and the "new" archive contains them in a separate folder.

so, if you're okay with it, i'll move all existing classes to the "forge" packages, and you get the files that changed beyond that.

Re: I/O reworking

PostPosted: 14 Sep 2009, 10:52
by silly freak
ok, i've tried to move the classes in the forge package, but it makes a few problems. deserialization doesn't work when the class name changes from "Deck" to "forge.Deck".
i'm trying to find a solution...

Re: I/O reworking

PostPosted: 15 Sep 2009, 20:32
by silly freak
okay, I need more time to figure the serialization problems out. for the next version, this is the code without packages. some new classes don't need anything from forge, they are in packages already.

new classes added are

forge.gui.ListChooser - The new dialog already metioned
ForgeAction - a javax.swing.Action subclass that makes internationalization easy.
ForgeProps - the access point for getting properties
forge.properties.NewConstants - the property keys to use with ForgeProps

changed classes are mostly for file location- and language changes. in CardFactory, this means only the first ~100 lines.

small update to the code: the language is configured in res/lang/lang.properties. my new version takes the language of the default locale if that key is not present, so i'd recommend to take the key out of the released version

Re: I/O reworking

PostPosted: 19 Sep 2009, 09:01
by silly freak
oops, i forgot the attachment :oops:

btw, I moved the ErrorViewer to package forge.error, so there are a few imports to add. That way, i could move more classes into packages (namely ForgeProps and ForgeAction). i'd suggest to move ErrorViewer before merging the new code, then eclipse does the imports by itself.

and finally, here are the classes.

Re: I/O reworking

PostPosted: 19 Sep 2009, 16:45
by DennisBergkamp
Alright. I'll see if I can figure out how to merge everything :)

Re: I/O reworking

PostPosted: 21 Sep 2009, 01:17
by DennisBergkamp
Silly Freak,

Hmm, I get a bunch of errors in ForgeProps.java when I add these packages to the project. It says it can't find TreeProperties :(
Can't even find the import (treeproperties.TreeProperties). Where do I get it ?

Re: I/O reworking

PostPosted: 21 Sep 2009, 09:49
by silly freak
again a piece of code i forgot to upload :?

Re: I/O reworking

PostPosted: 21 Sep 2009, 20:34
by DennisBergkamp
Ok, I think I've merged everything (impressive changes!). But I think the forge.properties file is missing? I can't find it anywhere, and after compiling I can't run the program without it :(

Also, I think you forgot to post the changes you made to PicturePanel.java, I kind of changed it myself so that it accepts a File instead of a String (and I think it should work - no compilation errors). But maybe you could post your version just to be sure :)

Re: I/O reworking

PostPosted: 21 Sep 2009, 21:22
by silly freak
I said it - i'm continuously forgetting code. but seriously, i don't know how i missed that one:
Code: Select all
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import forge.error.ErrorViewer;


public class PicturePanel extends JPanel {
    private static final long serialVersionUID = 2282867940272644768L;
   
    public PicturePanel(File f) {
        if(!f.exists()) {
            ErrorViewer.showError("PicturePanel : file does not exist - %s", f);
            throw new RuntimeException("PicturePanel : file does not exist - " + f);
        }
       
        ImageIcon i = new ImageIcon(f.getPath());
        this.add(new JLabel(i));
    }
}
the forge.properties file is contained in both versions of forge-ressources-*.rar; it should work if you extract one version in the forge folder (keep track of duplicate files!).
and don't forget to delete the lang-entry from lang/lang.properties for the released version ;)