Skip to content

Commit

Permalink
ref: added 1.12 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Oct 10, 2024
1 parent fe3b234 commit 5ea2311
Show file tree
Hide file tree
Showing 36 changed files with 1,227 additions and 584 deletions.
18 changes: 14 additions & 4 deletions src/main/java/com/troblecodings/signals/config/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static class Client {
public final ConfigValue<Integer> signalboxUsedColor;
public final ConfigValue<Integer> signalboxPreparedColor;
public final ConfigValue<Integer> signalboxTrainNumberColor;
public final ConfigValue<Integer> signalboxShuntingColor;
public final ConfigValue<Integer> signalboxTrainnumberBackgroundColor;

public Client(final ForgeConfigSpec.Builder builder) {
String desc;
Expand All @@ -69,9 +71,17 @@ public Client(final ForgeConfigSpec.Builder builder) {
signalboxPreparedColor = builder.comment(desc).define("Signalbox prepared color",
0xffff00);

desc = "Change the color of the TrainNumber in the UI. Default: -1";
signalboxTrainNumberColor = builder.comment(desc).define("Signalbox TrainNumber color",
0xFFFFFFFF);
desc = "Change the color of a selected shunting path. Default: -16711936";
signalboxShuntingColor = builder.comment(desc).define("Signalbox shunting color",
0xFF00FF00);

desc = "Change the color of trainnumber in the signalbox. Default: -65536";
signalboxTrainNumberColor = builder.comment(desc)
.define("Signalbox trainnumber text color", 0xFFFF0000);

desc = "Change the background color of trainnumber in the signalbox. Default: -11534336";
signalboxTrainnumberBackgroundColor = builder.comment(desc)
.define("Signalbox trainnumber background color", 0xFF500000);

desc = "Change the color of a default text. Default: -16777216";
GuiConfigHandler.basicTextColor = builder.comment(desc).define("Basic text color",
Expand All @@ -91,4 +101,4 @@ public Client(final ForgeConfigSpec.Builder builder) {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,97 +53,105 @@ public static void loadChangeConfigs() {
private static void loadConfigForPair(final String fileName, final String currentSignal,
final String nextSignal, final Map<String, String> savedPredicates,
final Map<String, List<String>> values) {
final Signal start = Signal.SIGNALS.get(currentSignal.toLowerCase());
final Signal end = Signal.SIGNALS.get(nextSignal.toLowerCase());
if (start == null || end == null) {
OpenSignalsMain.getLogger()
.warn("The signal '" + nextSignal + "' or the signal '" + nextSignal
+ "' doen't exists! " + "This config with filename '" + fileName
+ "' will be skiped!");
return;
}
final Map.Entry<Signal, Signal> pair = Maps.immutableEntry(start, end);
if (CHANGECONFIGS.containsKey(pair)) {
throw new LogicalParserException(
"A signalconfig with the signals [" + start.getSignalTypeName() + ", "
+ end.getSignalTypeName() + "] does alredy exists! '" + fileName
+ "' tried to register a chaneconfig for the same signalpair!");
}
final FunctionParsingInfo startInfo = new FunctionParsingInfo(start);
final FunctionParsingInfo endInfo = new FunctionParsingInfo(
LogicParser.UNIVERSAL_TRANSLATION_TABLE, end);
final List<ConfigProperty> properties = new ArrayList<>();

for (final Map.Entry<String, List<String>> entry : values.entrySet()) {

String valueToParse = entry.getKey().toLowerCase();
Predicate<Map<Class<?>, Object>> predicate = t -> true;

if (valueToParse.contains("map(") && savedPredicates != null
&& !savedPredicates.isEmpty()) {
final char[] chars = entry.getKey().toCharArray();
String names = "";
boolean readKey = false;
final StringBuilder builder = new StringBuilder();
String mapKey = "";
for (final char letter : chars) {

final String current = builder.append(letter).toString();
final boolean isOpenBracket = current.equals("(");
final boolean isCloseBracket = current.equals(")");
builder.setLength(0);

if (readKey) {
try {
if (isCloseBracket) {
valueToParse = valueToParse.replace("map(" + mapKey + ")",
"(" + savedPredicates.get(mapKey).toLowerCase() + ")");
names = "";
mapKey = "";
readKey = false;
try {

final Signal start = Signal.SIGNALS.get(currentSignal.toLowerCase());
final Signal end = Signal.SIGNALS.get(nextSignal.toLowerCase());
if (start == null || end == null) {
OpenSignalsMain.getLogger()
.warn("The signal '" + nextSignal + "' or the signal '" + nextSignal
+ "' doen't exists! " + "This config with filename '" + fileName
+ "' will be skiped!");
return;
}
final Map.Entry<Signal, Signal> pair = Maps.immutableEntry(start, end);
if (CHANGECONFIGS.containsKey(pair)) {
throw new LogicalParserException(
"A signalconfig with the signals [" + start.getSignalTypeName() + ", "
+ end.getSignalTypeName() + "] does alredy exists! '" + fileName
+ "' tried to register a chaneconfig for the same signalpair!");
}
final FunctionParsingInfo startInfo = new FunctionParsingInfo(start);
final FunctionParsingInfo endInfo = new FunctionParsingInfo(
LogicParser.UNIVERSAL_TRANSLATION_TABLE, end);
final List<ConfigProperty> properties = new ArrayList<>();

for (final Map.Entry<String, List<String>> entry : values.entrySet()) {

String valueToParse = entry.getKey().toLowerCase();
Predicate<Map<Class<?>, Object>> predicate = t -> true;

if (valueToParse.contains("map(") && savedPredicates != null
&& !savedPredicates.isEmpty()) {
final char[] chars = entry.getKey().toCharArray();
String names = "";
boolean readKey = false;
final StringBuilder builder = new StringBuilder();
String mapKey = "";
for (final char letter : chars) {

final String current = builder.append(letter).toString();
final boolean isOpenBracket = current.equals("(");
final boolean isCloseBracket = current.equals(")");
builder.setLength(0);

if (readKey) {
try {
if (isCloseBracket) {
valueToParse = valueToParse.replace("map(" + mapKey + ")",
"(" + savedPredicates.get(mapKey).toLowerCase() + ")");
names = "";
mapKey = "";
readKey = false;
continue;
}
mapKey += current;
continue;
} catch (final Exception e) {
OpenSignalsMain.exitMinecraftWithMessage(
"Something went wrong with the predicate saver in "
+ fileName + "! Did you used it correctly?");
}
mapKey += current;
}
if (current.equals("(") && names.equals("map")) {
readKey = true;
mapKey = "";
continue;
} catch (final Exception e) {
OpenSignalsMain.exitMinecraftWithMessage(
"Something went wrong with the predicate saver in " + fileName
+ "! Did you used it correctly?");
}
final boolean isBracket = isCloseBracket || isOpenBracket;
if (Character.isWhitespace(letter) || current.equals("!") || isBracket) {
names = "";
mapKey = "";
continue;
}
names += current;
}
if (current.equals("(") && names.equals("map")) {
readKey = true;
mapKey = "";
continue;
}
final boolean isBracket = isCloseBracket || isOpenBracket;
if (Character.isWhitespace(letter) || current.equals("!") || isBracket) {
names = "";
mapKey = "";
continue;
}
names += current;
}
}

if (valueToParse != null && !valueToParse.isEmpty()
&& !valueToParse.equalsIgnoreCase("true")) {
predicate = LogicParser.predicate(valueToParse, endInfo);
}
if (valueToParse != null && !valueToParse.isEmpty()
&& !valueToParse.equalsIgnoreCase("true")) {
predicate = LogicParser.predicate(valueToParse, endInfo);
}

final Map<SEProperty, String> propertiesToSet = new HashMap<>();
final Map<SEProperty, String> propertiesToSet = new HashMap<>();

for (final String value : entry.getValue()) {
for (final String value : entry.getValue()) {

final String[] valuetoChange = value.split("\\.");
final SEProperty property = (SEProperty) startInfo.getProperty(valuetoChange[0]);
propertiesToSet.put(property, valuetoChange[1]);
}
final String[] valuetoChange = value.split("\\.");
final SEProperty property = (SEProperty) startInfo
.getProperty(valuetoChange[0]);
propertiesToSet.put(property, valuetoChange[1]);
}

properties.add(new ConfigProperty(predicate, propertiesToSet));
properties.add(new ConfigProperty(predicate, propertiesToSet));

}
CHANGECONFIGS.put(pair, properties);
} catch (final Exception e) {
OpenSignalsMain.getLogger().error("There was a problem loading the ChangeConfig ["
+ fileName + "]! Please check the file!");
e.printStackTrace();
}
CHANGECONFIGS.put(pair, properties);
}

private static class ChangeConfigParserV2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,45 @@ public static void loadOneSignalNonPredicateConfig(final Map<Signal, List<Config
final OneSignalNonPredicateConfigParserV2 parser = GSON.fromJson(files.getValue(),
OneSignalNonPredicateConfigParserV2.class);
for (final String currentSignal : parser.currentSignals) {
loadConfig(map, files.getKey(), currentSignal, parser.values);
loadConfig(map, files.getKey(), currentSignal, parser.values, path);
}
} catch (final Exception e) {
OpenSignalsMain.getLogger().error("Please update your config [" + files.getKey()
+ "] located in [" + path + "]!");
final OneSignalNonPredicateConfigParser parser = GSON.fromJson(files.getValue(),
OneSignalNonPredicateConfigParser.class);
loadConfig(map, files.getKey(), parser.currentSignal, parser.values);
loadConfig(map, files.getKey(), parser.currentSignal, parser.values, path);
}

}

private static void loadConfig(final Map<Signal, List<ConfigProperty>> map,
final String fileName, final String currentSignal, final List<String> values) {
final Signal signal = checkSignal(currentSignal, fileName);
if (signal == null)
return;

if (map.containsKey(signal)) {
throw new LogicalParserException("A signalconfig with the signals ["
+ signal.getSignalTypeName() + "] does alredy exists! '" + fileName
+ "' tried to register the same signalconfig!");
}
final String fileName, final String currentSignal, final List<String> values,
final String path) {
try {
final Signal signal = checkSignal(currentSignal, fileName);
if (signal == null)
return;

if (map.containsKey(signal)) {
throw new LogicalParserException("A signalconfig with the signals ["
+ signal.getSignalTypeName() + "] does alredy exists! '" + fileName
+ "' tried to register the same signalconfig!");
}

final FunctionParsingInfo info = new FunctionParsingInfo(signal);
final List<ConfigProperty> propertes = new ArrayList<>();
for (final String property : values) {
final String[] value = property.split("\\.");
propertes.add(new ConfigProperty(t -> true,
ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1])));
final FunctionParsingInfo info = new FunctionParsingInfo(signal);
final List<ConfigProperty> propertes = new ArrayList<>();
for (final String property : values) {
final String[] value = property.split("\\.");
propertes.add(new ConfigProperty(t -> true,
ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1])));
}
map.put(signal, propertes);
} catch (final Exception e) {
OpenSignalsMain.getLogger().error("There was a problem loading the config [" + fileName
+ "] located in [" + path + "]! Please check the file!");
e.printStackTrace();
}
map.put(signal, propertes);
}

private static Signal checkSignal(final String signalName, final String filename) {
Expand Down
Loading

0 comments on commit 5ea2311

Please sign in to comment.