name-mutator.txt and NameChanger.java files
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
4 posts
• Page 1 of 1
name-mutator.txt and NameChanger.java files
by Chris H. » 16 Dec 2009, 23:57
In a brief and lucid moment I removed the name-mutator.txt file from my local copy and edited the NameChanger.java file. I built the project and there were no errors or warnings. I ran this version of the game and it works. Both the Deck Editor and the game itself. wow.
I will attach my edited NameChanger.java file and will let Dennis do a file compare to see what I did. If he feels that there will be no repercussions with my work, great. Merge this with the SVN and remove that pesky name-mutator.txt file!
I will attach my edited NameChanger.java file and will let Dennis do a file compare to see what I did. If he feels that there will be no repercussions with my work, great. Merge this with the SVN and remove that pesky name-mutator.txt file!

- Code: Select all
package forge;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import forge.error.ErrorViewer;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
@SuppressWarnings("unused")
public class NameChanger implements NewConstants {
private Map<String, String> mutatedMap = new HashMap<String, String>();
private Map<String, String> originalMap = new HashMap<String, String>();
private boolean changeCardName;
public NameChanger() {
// readFile();
setShouldChangeCardName(false);
}
//should change card name?
public boolean shouldChangeCardName() {
return changeCardName;
}
public void setShouldChangeCardName(boolean b) {
changeCardName = b;
}
//returns an array of copies
public Card[] changeCard(Card c[]) {
for(int i = 0; i < c.length; i++)
changeCard(c[i]);
return c;
}
//changes card name, getText(), and all SpellAbility getStackDescription() and toString()
public Card changeCard(Card c) {
//change name
String newName = changeName(c.getName());
c.setName(newName);
//change text
String s;
s = c.getSpellText();
c.setText(changeString(c, s));
//change all SpellAbilities
SpellAbility[] spell = c.getSpellAbility();
for(int i = 0; i < spell.length; i++) {
s = spell[i].getStackDescription();
spell[i].setStackDescription(changeString(c, s));
s = spell[i].toString();
spell[i].setDescription(changeString(c, s));
}
return c;
}//getMutatedCard()
public String changeString(Card c, String in) {
//String name = getOriginalName(c.getName()); // unused
// in = in.replaceAll(name, changeName(name));
return in;
}
//always returns mutated (alias) for the card name
//if argument is a mutated name, it returns the same mutated name
public String changeName(String originalName) {
Object o = mutatedMap.get(originalName);
if(o == null) return originalName;
return o.toString();
}//getMutatedName()
//always returns the original cardname
//if argument is a original name, it returns the same original name
public String getOriginalName(String mutatedName) {
Object o = originalMap.get(mutatedName);
if(o == null) return mutatedName;
return o.toString();
}//getOriginalName()
/*
private void readFile() {
try {
BufferedReader in = new BufferedReader(new FileReader(ForgeProps.getFile(NAME_MUTATOR)));
String line = in.readLine();
//stop reading if end of file or blank line is read
while(line != null && (line.trim().length() != 0)) {
processLine(line.trim());
line = in.readLine();
}//while
}//try
catch(Exception ex) {
//~ throw new RuntimeException("NameMutator : readFile() error, " +ex);
//~ (could be cleaner...)
try {
BufferedReader in = new BufferedReader(new FileReader(ForgeProps.getFile(NAME_MUTATOR)));
String line;
//stop reading if end of file or blank line is read
while((line = in.readLine()) != null && (line.trim().length() != 0)) {
processLine(line.trim());
}//while
} catch(Exception ex2) {
// Show orig exception
ErrorViewer.showError(ex2);
throw new RuntimeException(String.format("NameMutator : readFile() error, %s", ex), ex);
}
//~
}
}//readFile()
*/
//line is formated "original card name : alias card name"
// @SuppressWarnings("unused")
private void processLine(String line) {
StringTokenizer tok = new StringTokenizer(line, ":");
if(tok.countTokens() != 2)
throw new RuntimeException(
"NameMutator : processLine() error, invalid line in file name-mutator.txt - " + line);
String original = tok.nextToken().trim();
String mutated = tok.nextToken().trim();
mutatedMap.put(original, mutated);
originalMap.put(mutated, original);
}
// @SuppressWarnings("unused")
// printMap
private void printMap(Map<String, String> map) {
Iterator<String> it = map.keySet().iterator();
String key;
for(int i = 0; i < 5; i++) {
key = it.next().toString();
System.out.println(key + " : " + map.get(key));
}
}
public static void main(String[] args) {}//main()
}
- Attachments
-
NameChanger.java.zip
- (1.57 KiB) Downloaded 282 times
-
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: name-mutator.txt and NameChanger.java files
by Chris H. » 17 Dec 2009, 02:46
OK, I spent some more time analyzing the NameChanger.java file and found a very simple way to achieve the same result.
All we have to do is comment out line 21. This line calls the readFile method which in turn reads in the data from the name-mutator.txt file.
All we have to do is comment out line 21. This line calls the readFile method which in turn reads in the data from the name-mutator.txt file.
- Code: Select all
20 public NameChanger() {
21 // readFile();
22 setShouldChangeCardName(false);
23 }
-
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: name-mutator.txt and NameChanger.java files
by DennisBergkamp » 17 Dec 2009, 03:24
Sure, looks good to me, thanks Chris 

-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: name-mutator.txt and NameChanger.java files
by Chris H. » 17 Dec 2009, 18:12
OK, r205 on the SVN contains this update and we can say goodbye to the name mutator file. 

-
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
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 32 guests