diff --git a/EU3_Scenario_Editor/src/editor/mapmode/Utilities.java b/EU3_Scenario_Editor/src/editor/mapmode/Utilities.java index 2160288..784753e 100644 --- a/EU3_Scenario_Editor/src/editor/mapmode/Utilities.java +++ b/EU3_Scenario_Editor/src/editor/mapmode/Utilities.java @@ -125,6 +125,8 @@ static boolean isNotACountry(final String tag) { private static final java.util.Map cultureGroups = new HashMap<>(); private static final List geographyColors = new ArrayList<>(); + + private static java.util.Map namedColors; private static FilenameResolver resolver; @@ -143,7 +145,7 @@ private static void initReligions() { religions = EUGFileIO.load(resolver.resolveFilename("common/religion.txt"), settings); if (religions == null) religions = EUGFileIO.loadAll(resolver.listFiles("common/religions"), settings); - if (religions == null) + if (religions == null || religions.isEmpty()) religions = EUGFileIO.loadAllUTF8(resolver.listFiles("common/religion/religions"), settings); } @@ -159,7 +161,7 @@ private static void initCultures() { cultures = EUGFileIO.load(resolver.resolveFilename("common/cultures.txt"), settings); if (cultures == null) cultures = EUGFileIO.loadAll(resolver.listFiles("common/cultures"), settings); - if (cultures == null) + if (cultures == null || cultures.isEmpty()) initCK3Cultures(); // go ahead and set up the colors here since we need to keep track of @@ -214,7 +216,7 @@ private static void initCultures() { } private static void initCK3Cultures() { - java.util.Map namedColors = readCK3NamedColors(); + initNamedColors(); cultures = EUGFileIO.loadAllUTF8(resolver.listFiles("common/culture/cultures"), settings); for (GenericObject culture : cultures.children) { Color color = parseColorMaybeHsv(culture, "color"); @@ -224,20 +226,21 @@ private static void initCK3Cultures() { } } - private static java.util.Map readCK3NamedColors() { - java.util.Map ret = new HashMap<>(); - GenericObject namedColors = EUGFileIO.loadUTF8(new java.io.File(resolver.resolveFilename("common/named_colors/culture_colors.txt")), ParserSettings.getQuietSettings()); - GenericObject colorsRoot = namedColors.getChild("colors"); - for (int i = 0; i < colorsRoot.getAllWritable().size(); i++) { - WritableObject obj = colorsRoot.getAllWritable().get(i); - if (obj instanceof GenericList) { - GenericList list = (GenericList) obj; - ret.put(list.getName(), parseColor(list)); - } else if (obj instanceof ObjectVariable) { - ret.put(((ObjectVariable) obj).varname, parseColorHsv((GenericList)colorsRoot.getAllWritable().get(++i))); + private static void initNamedColors() { + if (namedColors == null) { + namedColors = new HashMap<>(); + GenericObject namedColorsObj = EUGFileIO.loadUTF8(new java.io.File(resolver.resolveFilename("common/named_colors/culture_colors.txt")), ParserSettings.getQuietSettings()); + GenericObject colorsRoot = namedColorsObj.getChild("colors"); + for (int i = 0; i < colorsRoot.getAllWritable().size(); i++) { + WritableObject obj = colorsRoot.getAllWritable().get(i); + if (obj instanceof GenericList) { + GenericList list = (GenericList) obj; + namedColors.put(list.getName(), parseColor(list)); + } else if (obj instanceof ObjectVariable) { + namedColors.put(((ObjectVariable) obj).varname, parseColorHsv((GenericList)colorsRoot.getAllWritable().get(++i))); + } } } - return ret; } private static void initGeographyColors() { @@ -312,6 +315,11 @@ private static Color parseColorMaybeHsv(GenericObject parent, String key) { if (shouldBeColorObj instanceof GenericList) { return parseColorHsv((GenericList) shouldBeColorObj); } + } else if (maybeColorVar.varname.equalsIgnoreCase(key) && maybeColorVar.getValue().equalsIgnoreCase("rgb")) { + WritableObject shouldBeColorObj = parent.getAllWritable().get(i+1); + if (shouldBeColorObj instanceof GenericList) { + return parseColor((GenericList) shouldBeColorObj); + } } } } @@ -428,13 +436,15 @@ static Color getReligionColor(String religion) { } private static Color cacheReligion(GenericObject group, String religion) { - GenericList color = group.getList("color"); - if (color == null) { + Color ret = parseColorMaybeHsv(group, "color"); + if (ret == null && group.hasString("color")) { + initNamedColors(); + ret = namedColors.get(group.getString("color")); + } + if (ret == null) { log.log(Level.WARNING, "color for {0} is null", religion); - relColorCache.put(religion, COLOR_NO_RELIGION_DEF); - return COLOR_NO_RELIGION_DEF; + ret = COLOR_NO_RELIGION_DEF; } - Color ret = parseColor(color); relColorCache.put(religion, ret); return ret; } @@ -462,7 +472,7 @@ static Color getCultureColor(String culture) { } public static String getCultureGroup(String culture) { - if (cultureGroups.isEmpty()) + if (cultures == null) initCultures(); return cultureGroups.get(culture); }