-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
377 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
common/src/main/java/dev/ithundxr/createnumismatics/config/CCommon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.config; | ||
|
||
import com.simibubi.create.foundation.config.ConfigBase; | ||
import dev.ithundxr.createnumismatics.content.backend.Coin; | ||
|
||
@SuppressWarnings("unused") | ||
public class CCommon extends ConfigBase { | ||
|
||
public final ConfigGroup coins = group(0, "coins", Comments.coins); | ||
|
||
public final ConfigEnum<Coin> defaultCoin = e(Coin.SPUR, "defaultCoin", Comments.defaultCoin); | ||
|
||
// Based off of https://github.com/Layers-of-Railways/Railway/blob/68713f0fbb20080b7e207c070b1595bdbbc1bc00/common/src/main/java/com/railwayteam/railways/config/CCommon.java | ||
|
||
@Override | ||
public String getName() { | ||
return "common"; | ||
} | ||
|
||
private static class Comments { | ||
static final String coins = "Coin settings"; | ||
|
||
static final String defaultCoin = "The default coin to be used in UI related displays"; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
common/src/main/java/dev/ithundxr/createnumismatics/config/CServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.config; | ||
|
||
import com.simibubi.create.foundation.config.ConfigBase; | ||
import dev.ithundxr.createnumismatics.content.backend.Coin; | ||
|
||
@SuppressWarnings("unused") | ||
public class CServer extends ConfigBase { | ||
|
||
public final ConfigGroup coins = group(0, "coins", Comments.coins); | ||
|
||
public final ConfigGroup starter_currency = group(1, "starter_currency", Comments.starterMoney); | ||
|
||
public final ConfigInt starter_spurs = i(0, 0, "starter_spurs"); | ||
public final ConfigInt starter_bevels = i(0, 0, "starter_bevels"); | ||
public final ConfigInt starter_sprockets = i(0, 0, "starter_sprockets"); | ||
public final ConfigInt starter_cogs = i(0, 0, "starter_cogs"); | ||
public final ConfigInt starter_crowns = i(0, 0, "starter_crowns"); | ||
public final ConfigInt starter_suns = i(0, 0, "starter_suns"); | ||
|
||
|
||
//public final ConfigGroup misc = group(0, "misc", Comments.misc); | ||
|
||
// Based off of https://github.com/Layers-of-Railways/Railway/blob/68713f0fbb20080b7e207c070b1595bdbbc1bc00/common/src/main/java/com/railwayteam/railways/config/CServer.java | ||
|
||
@Override | ||
public String getName() { | ||
return "server"; | ||
} | ||
|
||
private static class Comments { | ||
static final String coins = "Coin settings"; | ||
|
||
static final String starterMoney = "How much of this coin type should players receive in their bank account on first join";; | ||
|
||
static final String misc = "Miscellaneous settings"; | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
common/src/main/java/dev/ithundxr/createnumismatics/config/NumismaticsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.config; | ||
|
||
import com.simibubi.create.foundation.config.ConfigBase; | ||
import net.minecraftforge.common.ForgeConfigSpec; | ||
import net.minecraftforge.fml.config.ModConfig; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.EnumMap; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
@SuppressWarnings("unused") | ||
public class NumismaticsConfig { | ||
@ApiStatus.Internal | ||
public static final Map<ModConfig.Type, ConfigBase> CONFIGS = new EnumMap<>(ModConfig.Type.class); | ||
|
||
//private static CClient client; | ||
private static CCommon common; | ||
private static CServer server; | ||
|
||
// public static CClient client() { | ||
// return client; | ||
// } | ||
|
||
public static CCommon common() { | ||
return common; | ||
} | ||
|
||
public static CServer server() { | ||
return server; | ||
} | ||
|
||
public static ConfigBase byType(ModConfig.Type type) { | ||
return CONFIGS.get(type); | ||
} | ||
|
||
private static <T extends ConfigBase> T register(Supplier<T> factory, ModConfig.Type side) { | ||
Pair<T, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(builder -> { | ||
T config = factory.get(); | ||
config.registerAll(builder); | ||
return config; | ||
}); | ||
|
||
T config = specPair.getLeft(); | ||
config.specification = specPair.getRight(); | ||
CONFIGS.put(side, config); | ||
return config; | ||
} | ||
|
||
@ApiStatus.Internal | ||
public static void registerCommon() { | ||
//client = register(CClient::new, ModConfig.Type.CLIENT); | ||
common = register(CCommon::new, ModConfig.Type.COMMON); | ||
server = register(CServer::new, ModConfig.Type.SERVER); | ||
} | ||
|
||
public static void onLoad(ModConfig modConfig) { | ||
for (ConfigBase config : CONFIGS.values()) | ||
if (config.specification == modConfig | ||
.getSpec()) | ||
config.onLoad(); | ||
} | ||
|
||
public static void onReload(ModConfig modConfig) { | ||
for (ConfigBase config : CONFIGS.values()) | ||
if (config.specification == modConfig | ||
.getSpec()) | ||
config.onReload(); | ||
} | ||
|
||
private static class TomlGroup { | ||
private final Map<String, TomlGroup> subgroups = new HashMap<>(); | ||
private final Map<String, String> entries = new HashMap<>(); | ||
private final String path; | ||
|
||
private static TomlGroup root() { | ||
return new TomlGroup(""); | ||
} | ||
|
||
private TomlGroup(String path) { | ||
this.path = path; | ||
} | ||
|
||
public boolean isRoot() { | ||
return path.isEmpty(); | ||
} | ||
|
||
public void add(String key, String value) { | ||
if (!isRoot()) | ||
throw new NotImplementedException(); | ||
|
||
String[] pieces = key.split("\\."); | ||
String subKey = pieces[pieces.length - 1]; | ||
TomlGroup targetedGroup = this; | ||
for (int i = 0; i < pieces.length - 1; i++) { | ||
targetedGroup = targetedGroup.getOrCreateSubGroup(pieces[i]); | ||
} | ||
targetedGroup.entries.put(subKey, value); | ||
} | ||
|
||
private TomlGroup getOrCreateSubGroup(String subKey) { | ||
return subgroups.computeIfAbsent(subKey, (sk) -> new TomlGroup(path.isEmpty() ? sk : path + "." + sk)); | ||
} | ||
|
||
private void write(StringBuilder b) { | ||
if (!isRoot()) { | ||
b.append("\n[").append(path).append("]"); | ||
} | ||
|
||
for (Map.Entry<String, String> entry : entries.entrySet()) { | ||
b.append("\n").append(entry.getKey()).append(" = ").append(entry.getValue()); | ||
} | ||
|
||
for (TomlGroup subGroup : subgroups.values()) { | ||
subGroup.write(b); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.