Add debug configs

This commit is contained in:
Sollace 2022-10-11 17:19:50 +02:00
parent 5d368d50e9
commit 2eaefdad9b
9 changed files with 43 additions and 11 deletions

View file

@ -15,6 +15,8 @@ public class Config extends JsonConfig {
public final Setting<Set<Race>> speciesWhiteList = value("server", "speciesWhiteList", new HashSet<>());
public final Setting<Boolean> enableCheats = value("server", "enableCheats", false);
/*private final String preferredRaceComment =
"The default preferred race. " +
"This is the race a client requests when first joining a game. " +

View file

@ -0,0 +1,16 @@
package com.minelittlepony.unicopia;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.impl.util.Arguments;
public final class Debug {
public static final boolean DEBUG_SPELLBOOK_CHAPTERS;
public static final boolean DEBUG_COMMANDS;
static {
Arguments args = new Arguments();
args.parse(FabricLoader.getInstance().getLaunchArguments(true));
DEBUG_SPELLBOOK_CHAPTERS = "true".equalsIgnoreCase(args.getOrDefault("unicopia.debug.spellbookChapters", "false"));
DEBUG_COMMANDS = "true".equalsIgnoreCase(args.getOrDefault("unicopia.debug.commands", "false"));
}
}

View file

@ -62,7 +62,7 @@ public class Unicopia implements ModInitializer {
ServerTickEvents.END_WORLD_TICK.register(w -> {
((BlockDestructionManager.Source)w).getDestructionManager().tick();
ZapAppleStageStore.get(w).tick();
if (SpellbookChapterLoader.DEBUG) {
if (Debug.DEBUG_SPELLBOOK_CHAPTERS) {
SpellbookChapterLoader.INSTANCE.sendUpdate(w.getServer());
}
});

View file

@ -77,6 +77,13 @@ public class LanSettingsScreen extends GameGui {
content.addButton(new Label(LEFT, row += 20)).getStyle().setText("unicopia.options.lan");
content.addButton(new Toggle(LEFT, row += 20, config.enableCheats.get()))
.onChange(v -> {
config.enableCheats.set(v);
return v;
})
.getStyle().setText("unicopia.options.cheats");
Set<Race> whitelist = config.speciesWhiteList.get();
boolean whitelistEnabled = (forceShowWhitelist || !whitelist.isEmpty()) && !forceHideWhitelist;

View file

@ -5,8 +5,8 @@ import java.util.function.BiConsumer;
import java.util.stream.Stream;
import com.minelittlepony.common.client.gui.IViewRoot;
import com.minelittlepony.unicopia.Debug;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.container.SpellbookChapterLoader;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
@ -39,7 +39,7 @@ public class SpellbookChapterList {
}
public Chapter getCurrentChapter() {
if (SpellbookChapterLoader.DEBUG) {
if (Debug.DEBUG_SPELLBOOK_CHAPTERS) {
ClientChapters.getChapters().forEach(chapter -> {
Optional.ofNullable(chapters.get(chapter.id())).flatMap(Chapter::content).ifPresent(old -> {
chapter.content().ifPresent(neu -> neu.copyStateFrom(old));

View file

@ -8,6 +8,7 @@ import com.minelittlepony.common.client.gui.IViewRoot;
import com.minelittlepony.common.client.gui.dimension.Bounds;
import com.minelittlepony.common.client.gui.element.Button;
import com.minelittlepony.common.client.gui.sprite.TextureSprite;
import com.minelittlepony.unicopia.Debug;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.*;
import com.minelittlepony.unicopia.container.*;
@ -139,7 +140,7 @@ public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> imple
drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight, 512, 256);
if (SpellbookChapterLoader.DEBUG) {
if (Debug.DEBUG_SPELLBOOK_CHAPTERS) {
clearAndInit();
}

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.command;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import com.minelittlepony.unicopia.Debug;
import com.minelittlepony.unicopia.Unicopia;
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
@ -17,13 +18,17 @@ public class Commands {
new EnumArgumentType.Serializer()
);
CommandRegistrationCallback.EVENT.register((dispatcher, access, environment) -> {
SpeciesCommand.register(dispatcher);
RacelistCommand.register(dispatcher);
GravityCommand.register(dispatcher);
DisguiseCommand.register(dispatcher);
TraitCommand.register(dispatcher);
EmoteCommand.register(dispatcher);
ManaCommand.register(dispatcher);
if (Unicopia.getConfig().enableCheats.get()) {
SpeciesCommand.register(dispatcher);
GravityCommand.register(dispatcher);
DisguiseCommand.register(dispatcher);
if (Debug.DEBUG_COMMANDS) {
TraitCommand.register(dispatcher);
ManaCommand.register(dispatcher);
}
}
});
Object game = FabricLoader.getInstance().getGameInstance();
if (game instanceof MinecraftServer) {

View file

@ -9,6 +9,7 @@ import org.slf4j.Logger;
import com.google.gson.*;
import com.minelittlepony.common.client.gui.dimension.Bounds;
import com.minelittlepony.unicopia.Debug;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.magic.spell.crafting.IngredientWithSpell;
import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.*;
@ -30,7 +31,6 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
private static final Logger LOGGER = LogUtils.getLogger();
private static final Identifier ID = Unicopia.id("spellbook/chapters");
private static final Executor EXECUTOR = CompletableFuture.delayedExecutor(5, TimeUnit.SECONDS);
public static boolean DEBUG = false;
public static final SpellbookChapterLoader INSTANCE = new SpellbookChapterLoader();
@ -73,7 +73,7 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
LOGGER.error("Could not load spellbook chapters due to exception", e);
}
if (DEBUG) {
if (Debug.DEBUG_SPELLBOOK_CHAPTERS) {
CompletableFuture.runAsync(() -> {
try {
Util.waitAndApply(executor -> reload(CompletableFuture::completedFuture, manager, profiler, profiler, Util.getMainWorkerExecutor(), executor)).get();

View file

@ -466,6 +466,7 @@
"unicopia.options.whitelist": "Enable Whitelist",
"unicopia.options.whitelist.race": "Allow %ss",
"unicopia.options.whitelist.details": "* Select the races you wish to allow",
"unicopia.options.cheats": "Enable Cheats",
"unicopia.options.client": "Client Settings",
"unicopia.options.world": "World Settings",
"unicopia.options.world.default_race": "Default Race: %s",