mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Refactor so profile props can be loaded for mobile game
This commit is contained in:
@@ -27,12 +27,12 @@ import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.item.PaperCard;
|
||||
import forge.match.input.InputQueue;
|
||||
import forge.properties.ForgeProfileProperties;
|
||||
import forge.sound.IAudioClip;
|
||||
import forge.util.ITriggerEvent;
|
||||
|
||||
|
||||
public interface IGuiBase {
|
||||
boolean isRunningOnDesktop();
|
||||
void invokeInEdtLater(Runnable runnable);
|
||||
void invokeInEdtAndWait(final Runnable proc);
|
||||
boolean isGuiThread();
|
||||
@@ -86,7 +86,6 @@ public interface IGuiBase {
|
||||
LobbyPlayer createAiPlayer();
|
||||
LobbyPlayer createAiPlayer(String name, int avatarIndex);
|
||||
LobbyPlayer getQuestPlayer();
|
||||
ForgeProfileProperties getProfileProps();
|
||||
IAudioClip createAudioClip(String filename);
|
||||
void startAltSoundSystem(String filename, boolean isSynchronized);
|
||||
void clearImageCache();
|
||||
|
||||
@@ -86,7 +86,7 @@ public final class ForgeConstants {
|
||||
public static final Map<String, String> CACHE_CARD_PICS_SUBDIR;
|
||||
public static final int SERVER_PORT_NUMBER;
|
||||
static {
|
||||
ForgeProfileProperties profileProps = GuiBase.getInterface().getProfileProps();
|
||||
ForgeProfileProperties profileProps = new ForgeProfileProperties();
|
||||
USER_DIR = profileProps.userDir;
|
||||
CACHE_DIR = profileProps.cacheDir;
|
||||
CACHE_CARD_PICS_DIR = profileProps.cardPicsDir;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package forge.properties;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.util.FileSection;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -54,6 +55,26 @@ public class ForgeProfileProperties {
|
||||
cardPicsDir = cacheDir + "pics/cards/";
|
||||
cardPicsSubDir = new HashMap<String, String>();
|
||||
serverPort = 0;
|
||||
}
|
||||
|
||||
public ForgeProfileProperties() {
|
||||
Properties props = new Properties();
|
||||
File propFile = new File(ForgeConstants.PROFILE_FILE);
|
||||
try {
|
||||
if (propFile.canRead()) {
|
||||
props.load(new FileInputStream(propFile));
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("error while reading from profile properties file");
|
||||
}
|
||||
|
||||
Pair<String, String> defaults = _getDefaultDirs();
|
||||
userDir = _getDir(props, _USER_DIR_KEY, defaults.getLeft());
|
||||
cacheDir = _getDir(props, _CACHE_DIR_KEY, defaults.getRight());
|
||||
cardPicsDir = _getDir(props, _CARD_PICS_DIR_KEY, cacheDir + "pics/cards/");
|
||||
cardPicsSubDir = _getMap(props, _CARD_PICS_SUB_DIRS_KEY);
|
||||
serverPort = _getInt(props, _SERVER_PORT, 0);
|
||||
|
||||
//ensure directories exist
|
||||
File dir = new File(userDir);
|
||||
@@ -66,25 +87,6 @@ public class ForgeProfileProperties {
|
||||
}
|
||||
}
|
||||
|
||||
public ForgeProfileProperties(String filename) {
|
||||
Properties props = new Properties();
|
||||
File propFile = new File(filename);
|
||||
try {
|
||||
if (propFile.canRead()) {
|
||||
props.load(new FileInputStream(propFile));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("error while reading from profile properties file: " + filename);
|
||||
}
|
||||
|
||||
Pair<String, String> defaults = _getDefaultDirs();
|
||||
userDir = _getDir(props, _USER_DIR_KEY, defaults.getLeft());
|
||||
cacheDir = _getDir(props, _CACHE_DIR_KEY, defaults.getRight());
|
||||
cardPicsDir = _getDir(props, _CARD_PICS_DIR_KEY, cacheDir + "pics/cards/");
|
||||
cardPicsSubDir = _getMap(props, _CARD_PICS_SUB_DIRS_KEY);
|
||||
serverPort = _getInt(props, _SERVER_PORT, 0);
|
||||
}
|
||||
|
||||
private Map<String,String> _getMap(Properties props, String propertyKey) {
|
||||
String strMap = props.getProperty(propertyKey, "").trim();
|
||||
return FileSection.parseToMap(strMap, "->", "|");
|
||||
@@ -113,9 +115,14 @@ public class ForgeProfileProperties {
|
||||
}
|
||||
return retDir + File.separatorChar;
|
||||
}
|
||||
|
||||
|
||||
// returns a pair <userDir, cacheDir>
|
||||
private static Pair<String, String> _getDefaultDirs() {
|
||||
if (!GuiBase.getInterface().isRunningOnDesktop()) { //special case for mobile devices
|
||||
String assetsDir = ForgeConstants.ASSETS_DIR;
|
||||
return Pair.of(assetsDir + "data/", assetsDir + "cache/");
|
||||
}
|
||||
|
||||
String osName = System.getProperty("os.name");
|
||||
String homeDir = System.getProperty("user.home");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user