It is currently 15 Sep 2025, 21:57
   
Text Size

Splitting CardFactory

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Re: Splitting CardFactory

Postby zerker2000 » 26 Oct 2009, 05:45

Nice!!! Would you be so kind as to commit them to svn? Also, if the plan is to make more than 10 of them, maybe CardFactory should be made into a seperate package?
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Splitting CardFactory

Postby silly freak » 26 Oct 2009, 10:23

the main problem with packages is serialization. for example, the created decks are stored in a map, and that map is serialized and stored in a file. if we just move the deck class into a package, it will be incompatible with the serialized file
this prevents us from moving moving all the classes that use deck as well, because you can't import classes from the default package. I doubt that CardFactory is independent enough to be moved into a package...


btw, who's antechno777?
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Splitting CardFactory

Postby silly freak » 26 Oct 2009, 12:48

good news, i managed to do something in that direction:
first, I moved the default package, which doesn't result in compile-time errors but fails when trying to load the decks.
after that , I created the Deck class in the default package again like that:
Code: Select all
public class Deck implements Serializable {
    private static final long serialVersionUID = -2188987217361601903L;
   
    private String            deckType;
   
    private boolean           isRegular;
    private boolean           isSealed;
    private boolean           isDraft;
   
    private ArrayList<String> main             = new ArrayList<String>();
    private ArrayList<String> sideboard        = new ArrayList<String>();
   
    //very important, do NOT change this
    private String            name             = "";
   
    private Object readResolve() throws ObjectStreamException {
        System.out.println("resolving obsolete Deck");
        forge.Deck d = new forge.Deck(deckType);
        d.setName(name);
        for(String s:main)
            d.addMain(s);
        for(String s:sideboard)
            d.addSideboard(s);
        return d;
    }
}
as you see, the class is Serializable, has the same serialVersionUID as the original Deck class, declares all the attributes, but has only one method: readResolve()
that method is used during deserialization to replace the read object with another. In this case, it replaces the Deck object with a forge.Deck object, and it seems to work!

i'm testing a little to find other classes that need similar treatment, but if you know of some, that would be great! so far, i have
  • Deck
  • QuestData_State
    I'm getting NullPointerExceptions with that. is it also with the version on SVN? are the quest files there up to date, or have broken the app myself?
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Splitting CardFactory

Postby DennisBergkamp » 26 Oct 2009, 14:52

AWESOME!!!
=D> =D> =D> =D> =D> =D> =D> =D>

Should split the keywords out to their own file too. And yeah, when you have the chance, separating the spells into Instants and Sorceries would rock. I don't think splitting by color would be necessary. We may need to end up with a Creatures1 and Creatures2 sort of idea after a while.

What was the trick?
I'm not exactly sure what we were doing wrong initially, but as I was debugging the stuff I tried last, it became clear that the SpellAbilities were added the other way around.
For instance, The Hive looked like:

SpellAbility[0] = "{5}, {T}: Put a 1/1 colorless Insect artifact creature token with flying named Wasp onto the battlefield."
SpellAbility[1] = "The Hive"

Which is why nothing worked. So I just moved things around a bit, and after some trial and error, it actually worked :)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Splitting CardFactory

Postby DennisBergkamp » 26 Oct 2009, 14:59

Ah yes, I will commit all of these changes to SVN. By the way, are you still having trouble with ArrayList<Command>? If so, I have no objections changing them to CommandLists.

I'm not sure if this is a really big deal, but I also changed each 'if(cardName.equals("some card")' into 'else if(cardName.equals("some card")', combined with the CardFactory split, this *should* increase performance quite a bit when starting up MTGForge or when opening the Deck Editor.
I could even bring this is a step further, and do a "return card;" at the end of each if statement (which would make the "else if" change I just made pretty useless though I guess :mrgreen: ), but the problem with that is that we currently add cycling abilities at the end of CardFactory.java and also CardFactory_Creatures.java.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Splitting CardFactory

Postby zerker2000 » 27 Oct 2009, 05:10

Don't we have some spells who get their code from more than one if block? Also, would it be possible to keyword buyback(e.g. "String Spell.Buyback = "none"; ", "boolean buybackpayed", "if(!sa.Buyback.equals "none") StopSetNext(new InputPayBuyback(sa))", "setbuttonBoth; ... cancel:sa.buybackpayed = false; ok:"sa .setManaCost(sa.getManaCost() + " " + sa.Buyback); sa.buybackpaid=true; ", "if(!sorceCard.isPermanent) {if(buyack paid) moveToHand(sourceCard) else moveToGrave(sourceCard)}").
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Splitting CardFactory

Postby Chris H. » 29 Dec 2009, 02:33

While looking through CardFactory.java I found 2 creatures that may have been overlooked in the move to CardFactory_Creatures.java.

Should we move Kinsbaile Borderguard and Lockjaw Snapper over?
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: Splitting CardFactory

Postby DennisBergkamp » 29 Dec 2009, 19:25

Ahh yes, that also explains why Kinsbaile Borderguard doesn't work anymore (someone reported it on the bug page).
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Splitting CardFactory

Postby Chris H. » 29 Dec 2009, 21:06

I enjoy squashing the occasional bug. :D

I was scanning through the CardFactory.java file originally to find cards which can be converted from code to keyword. I found about two dozen of them. :shock:

It will keep me busy. :D
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: Splitting CardFactory

Postby Rob Cashwalker » 29 Dec 2009, 21:12

What effects were you looking at doing?

I'm going to touch up the spPumpTgt code to fit with the new tech, and then revise spLoseLife.

Another thing to try to work on is adapting some abilities to spells and vice-versa, like making abDraw[Tgt].
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Splitting CardFactory

Postby Chris H. » 29 Dec 2009, 22:00

There are some spells which can be converted from code to keyword. The keywords were created some time ago. And not every existing card was converted over at the time. For example:

Ice Storm
Lay Waste
Sinkhole
Stone Rain
Terminate
Shatter
Brute Force
Wildsize
Might of Oaks
Vindicate

...

and others. :wink:
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: Splitting CardFactory

Postby Rob Cashwalker » 29 Dec 2009, 23:54

Oh.. right....
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Splitting CardFactory

Postby DennisBergkamp » 30 Dec 2009, 00:42

Converting those should get rid of a lot of redundant lines of code :)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Splitting CardFactory

Postby Chris H. » 30 Dec 2009, 00:56

I spent several weeks prior to the SVN trying to complete the modification of the spRaiseDead keyword and got stuck. I meant at that time to ask for some guidance to get past where I was stuck.

We have had several new people contribute material. :D They needed some guidance and I did not want to interrupt there efforts by asking for help at that time.

Then Dennis set up the SVN and it took me several weeks to get up to speed. The SVN is great. It allows me to address the TODO list that I have. Granted, for the most part, my TODO list is fairly simple. :mrgreen: The list is getting shorter.

I want to get back to keywords pretty soon. I should probably finish the modification of the spRaiseDead keyword first.

I had fun with the Disciple of Kangee and zerkers keyword. There are several land cards that need a similar treatment. It looks like we need some sort of a utility method(s) that could be reused when needed for these types of color changing cards.

I have spent some time recently trying to finish the Funeral Charm card. At some point I want to hear from you about your plans for charms. I am currently using a setText() (???) command to print a "Choose one\r\n". The text panel looks nice and is readable. The choice window only lists the three choices and does not include the Choose one\r\n" string.

For charms based on only keywords and not on code we could consider having a Charm keyword which would do the setText() command to print a "Choose one\r\n".
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: Splitting CardFactory

Postby Chris H. » 30 Dec 2009, 01:02

DennisBergkamp wrote:Converting those should get rid of a lot of redundant lines of code :)
Yeah. CardFactory is now only about 18### lines long. =D>

With a little work and a substantial portion of that will be large sections that have been commented out. 8)
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

PreviousNext

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 28 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 28 users online :: 0 registered, 0 hidden and 28 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 28 guests

Login Form