Skip to content

Commit

Permalink
extract identifier constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Nov 8, 2024
1 parent c4b9b92 commit 5eb5f79
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.mojang.serialization.JsonOps;
import folk.sisby.switchy.client.api.module.SwitchyClientModuleRegistry;
import folk.sisby.switchy.client.api.modules.CardinalSerializerClientModule;
import folk.sisby.switchy.util.Feedback;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.command.argument.NbtPathArgumentType;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class CardinalClientModuleLoader extends JsonDataLoader implements Identi
* The global instance for this resource loader.
*/
public static final CardinalClientModuleLoader INSTANCE = new CardinalClientModuleLoader(new Gson());
private static final Identifier ID = new Identifier(SwitchyCardinalClient.ID, "module_loader");
private static final Identifier ID = Feedback.identifier(SwitchyCardinalClient.ID, "module_loader");
private static final String KEY_CONDITION = "condition";
private static final String KEY_ICON = "icon";
private static final String KEY_ICON_PATH = "path";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class CardinalModuleLoader extends JsonDataLoader implements Identifiable
* The global instance for this resource loader.
*/
public static final CardinalModuleLoader INSTANCE = new CardinalModuleLoader(new Gson());
private static final Identifier ID = new Identifier(SwitchyCardinal.ID, "module_loader");
private static final Identifier ID = Feedback.identifier(SwitchyCardinal.ID, "module_loader");
private static final String KEY_DEFAULT = "default";
private static final String KEY_EDITABLE = "editable";
private static final String KEY_IF_MODS_LOADED = "ifModsLoaded";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import folk.sisby.switchy.api.module.SwitchyModuleEditable;
import folk.sisby.switchy.api.presets.SwitchyPresets;
import folk.sisby.switchy.presets.SwitchyPresetsImpl;
import folk.sisby.switchy.util.Feedback;
import folk.sisby.switchy.util.PresetConverter;
import folk.sisby.switchy.util.SwitchyCommand;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
Expand Down Expand Up @@ -44,62 +45,62 @@ public class SwitchyClientServerNetworking {
/**
* Request serialized presets for exporting.
*/
public static final Identifier C2S_REQUEST_PRESETS = new Identifier(Switchy.ID, "c2s_presets");
public static final Identifier C2S_REQUEST_PRESETS = Feedback.identifier(Switchy.ID, "c2s_presets");
/**
* Request client-compatible serialized presets for client addon use.
*/
public static final Identifier C2S_REQUEST_CLIENT_PRESETS = new Identifier(Switchy.ID, "c2s_client_presets");
public static final Identifier C2S_REQUEST_CLIENT_PRESETS = Feedback.identifier(Switchy.ID, "c2s_client_presets");

// Actions
/**
* Send serialized presets to import.
* Must be sent twice to finalize - outputs confirmation text in chat.
*/
public static final Identifier C2S_IMPORT_CONFIRM = new Identifier(Switchy.ID, "c2s_import_confirm");
public static final Identifier C2S_IMPORT_CONFIRM = Feedback.identifier(Switchy.ID, "c2s_import_confirm");
/**
* Send serialized presets to import.
*/
public static final Identifier C2S_IMPORT = new Identifier(Switchy.ID, "c2s_import");
public static final Identifier C2S_IMPORT = Feedback.identifier(Switchy.ID, "c2s_import");
/**
* Send switch action with preset name.
*/
public static final Identifier C2S_SWITCH = new Identifier(Switchy.ID, "c2s_switch");
public static final Identifier C2S_SWITCH = Feedback.identifier(Switchy.ID, "c2s_switch");
/**
* Send new preset action with preset name.
*/
public static final Identifier C2S_PRESETS_NEW = new Identifier(Switchy.ID, "c2s_presets_new");
public static final Identifier C2S_PRESETS_NEW = Feedback.identifier(Switchy.ID, "c2s_presets_new");
/**
* Send delete preset action with preset name.
*/
public static final Identifier C2S_PRESETS_DELETE = new Identifier(Switchy.ID, "c2s_presets_delete");
public static final Identifier C2S_PRESETS_DELETE = Feedback.identifier(Switchy.ID, "c2s_presets_delete");
/**
* Send rename preset action with preset name and new name.
*/
public static final Identifier C2S_PRESETS_RENAME = new Identifier(Switchy.ID, "c2s_presets_rename");
public static final Identifier C2S_PRESETS_RENAME = Feedback.identifier(Switchy.ID, "c2s_presets_rename");
/**
* Send disable module action with module ID.
*/
public static final Identifier C2S_PRESETS_MODULE_DISABLE = new Identifier(Switchy.ID, "c2s_presets_module_disable");
public static final Identifier C2S_PRESETS_MODULE_DISABLE = Feedback.identifier(Switchy.ID, "c2s_presets_module_disable");
/**
* Send enable module action with module ID.
*/
public static final Identifier C2S_PRESETS_MODULE_ENABLE = new Identifier(Switchy.ID, "c2s_presets_module_enable");
public static final Identifier C2S_PRESETS_MODULE_ENABLE = Feedback.identifier(Switchy.ID, "c2s_presets_module_enable");

// Responses
/**
* Serialized presets for exporting.
*/
public static final Identifier S2C_PRESETS = new Identifier(Switchy.ID, "s2c_presets");
public static final Identifier S2C_PRESETS = Feedback.identifier(Switchy.ID, "s2c_presets");
/**
* Client-compatible serialized presets for previewing.
*/
public static final Identifier S2C_CLIENT_PRESETS = new Identifier(Switchy.ID, "s2c_client_presets");
public static final Identifier S2C_CLIENT_PRESETS = Feedback.identifier(Switchy.ID, "s2c_client_presets");

// Events
/**
* @see SwitchyEvents.Switch
*/
public static final Identifier S2C_EVENT_SWITCH = new Identifier(Switchy.ID, "s2c_event_switch");
public static final Identifier S2C_EVENT_SWITCH = Feedback.identifier(Switchy.ID, "s2c_event_switch");

// NBT Keys
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import folk.sisby.switchy.util.Feedback;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
Expand Down Expand Up @@ -76,7 +77,7 @@ public List<Identifier> parse(StringReader reader) throws CommandSyntaxException
while (reader.canRead() && isPathCharacterValid(reader.peek())) {
reader.skip();
}
outList.add(new Identifier(reader.getString().substring(start, reader.getCursor())));
outList.add(Feedback.identifier(reader.getString().substring(start, reader.getCursor())));
if (reader.canRead() && reader.peek() == ',') {
reader.skip();
if (!reader.canRead() || reader.peek() == ' ') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class OriginsClientModule implements SwitchyClientModule, SwitchyUIModule
* Identifier for this module.
* Must match {@link OriginsModule}.
*/
public static final Identifier ID = new Identifier("switchy", "origins");
public static final Identifier ID = Feedback.identifier("switchy", "origins");

/**
* The NBT key where the list of origins is stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import folk.sisby.switchy.modules.StyledNicknamesModule;
import folk.sisby.switchy.ui.api.SwitchyUIPosition;
import folk.sisby.switchy.ui.api.module.SwitchyUIModule;
import folk.sisby.switchy.util.Feedback;
import io.wispforest.owo.ui.component.Components;
import io.wispforest.owo.ui.core.Component;
import net.minecraft.nbt.NbtCompound;
Expand All @@ -26,7 +27,7 @@ public class StyledNicknamesClientModule implements SwitchyClientModule, Switchy
* Identifier for this module.
* Must match {@link StyledNicknamesModule}.
*/
public static final Identifier ID = new Identifier("switchy", "styled_nicknames");
public static final Identifier ID = Feedback.identifier("switchy", "styled_nicknames");
/**
* The NBT key where the nickname (in serialized text format) is stored.
* Must match {@link StyledNicknamesModule#toClientNbt()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import folk.sisby.switchy.api.module.SwitchyModuleInfo;
import folk.sisby.switchy.api.module.SwitchyModuleRegistry;
import folk.sisby.switchy.config.ApoliModuleConfig;
import folk.sisby.switchy.util.Feedback;
import io.github.apace100.apoli.component.PowerHolderComponent;
import io.github.apace100.apoli.power.InventoryPower;
import io.github.apace100.apoli.power.Power;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class ApoliModule implements SwitchyModule {
/**
* Identifier for this module.
*/
public static final Identifier ID = new Identifier("switchy", "apoli");
public static final Identifier ID = Feedback.identifier("switchy", "apoli");
/**
* The config object for the apoli module, containing the current state of {@code /config/switchy/apoli.toml}.
*/
Expand All @@ -53,7 +54,7 @@ public class ApoliModule implements SwitchyModule {
* The NBT key where the list of power data is stored.
*/
public static final String KEY_POWER_DATA_LIST = "PowerData";
private static final Identifier COMMAND_SOURCE = new Identifier("apoli", "command");
private static final Identifier COMMAND_SOURCE = Feedback.identifier("apoli", "command");
/**
* The NBT data for each power.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DrogtorModuleData implements SwitchySerializable {
/**
* Identifier for this module.
*/
public static final Identifier ID = new Identifier("switchy", "drogtor");
public static final Identifier ID = Feedback.identifier("switchy", "drogtor");

/**
* The NBT key where the nickname is stored.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package folk.sisby.switchy.modules;

import folk.sisby.switchy.api.SwitchySerializable;
import folk.sisby.switchy.util.Feedback;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
Expand All @@ -17,7 +18,7 @@ public class FabricTailorModuleData implements SwitchySerializable {
/**
* Identifier for this module.
*/
public static final Identifier ID = new Identifier("switchy", "fabric_tailor");
public static final Identifier ID = Feedback.identifier("switchy", "fabric_tailor");

/**
* The NBT key where the base64 encoded json skin value is stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import folk.sisby.switchy.api.module.SwitchyModuleEditable;
import folk.sisby.switchy.api.module.SwitchyModuleInfo;
import folk.sisby.switchy.api.module.SwitchyModuleRegistry;
import folk.sisby.switchy.util.Feedback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -42,7 +43,7 @@ public class FabricationArmorModule implements SwitchyModule {
/**
* Identifier for this module.
*/
public static final Identifier ID = new Identifier("switchy", "hidearmor");
public static final Identifier ID = Feedback.identifier("switchy", "hidearmor");

/**
* The NBT key where the list of EquipmentSlots to hide is stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import folk.sisby.switchy.api.module.SwitchyModuleInfo;
import folk.sisby.switchy.api.module.SwitchyModuleRegistry;
import folk.sisby.switchy.api.module.SwitchyModuleTransferable;
import folk.sisby.switchy.util.Feedback;
import io.github.apace100.origins.component.OriginComponent;
import io.github.apace100.origins.origin.Origin;
import io.github.apace100.origins.origin.OriginLayer;
Expand Down Expand Up @@ -35,7 +36,7 @@ public class OriginsModule implements SwitchyModule, SwitchyModuleTransferable {
/**
* Identifier for this module.
*/
public static final Identifier ID = new Identifier("switchy", "origins");
public static final Identifier ID = Feedback.identifier("switchy", "origins");

/**
* The NBT key where the list of origins is stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import folk.sisby.switchy.api.module.SwitchyModuleInfo;
import folk.sisby.switchy.api.module.SwitchyModuleRegistry;
import folk.sisby.switchy.config.PehkuiModuleConfig;
import folk.sisby.switchy.util.Feedback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -30,7 +31,7 @@ public class PehkuiModule implements SwitchyModule {
/**
* Identifier for this module.
*/
public static final Identifier ID = new Identifier("switchy", "pehkui");
public static final Identifier ID = Feedback.identifier("switchy", "pehkui");
/**
* The config object for the pehkui module, containing the current state of {@code /config/switchy/pehkui.toml}.
*/
Expand All @@ -41,7 +42,7 @@ public class PehkuiModule implements SwitchyModule {
public final Map<ScaleType, @Nullable Float> scaleValues = new HashMap<>();

PehkuiModule() {
CONFIG.scaleTypes.forEach(id -> scaleValues.put(ScaleRegistries.SCALE_TYPES.get(new Identifier(id)), null));
CONFIG.scaleTypes.forEach(id -> scaleValues.put(ScaleRegistries.SCALE_TYPES.get(Feedback.identifier(id)), null));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import folk.sisby.switchy.api.module.SwitchyModuleInfo;
import folk.sisby.switchy.api.module.SwitchyModuleRegistry;
import folk.sisby.switchy.api.module.SwitchyModuleTransferable;
import folk.sisby.switchy.util.Feedback;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand All @@ -32,7 +33,7 @@ public class StyledNicknamesModule implements SwitchyModule, SwitchyModuleTransf
/**
* Identifier for this module.
*/
public static final Identifier ID = new Identifier("switchy", "styled_nicknames");
public static final Identifier ID = Feedback.identifier("switchy", "styled_nicknames");

/**
* The NBT key where the nickname is stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import folk.sisby.switchy.api.exception.PresetNotFoundException;
import folk.sisby.switchy.api.presets.SwitchyPresetData;
import folk.sisby.switchy.api.presets.SwitchyPresetsData;
import folk.sisby.switchy.util.Feedback;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void fillFromNbt(NbtCompound nbt) {
NbtCompound configCompound = nbt.getCompound(KEY_MODULE_CONFIGS);
for (String key : configCompound.getKeys()) {
try {
SwitchySerializable config = setConfig(new Identifier(key));
SwitchySerializable config = setConfig(Feedback.identifier(key));
if (config != null) {
config.fillFromNbt(configCompound.getCompound(key));
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/folk/sisby/switchy/util/Feedback.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public static void sendMessage(ServerPlayerEntity player, Text text) {
player.sendMessage(literal("[Switchy] ").setStyle(Style.EMPTY.withColor(Formatting.AQUA)).append(text), false);
}

public static Identifier identifier(String identifier) {
return new Identifier(identifier);
}

public static Identifier identifier(String namespace, String key) {
return new Identifier(namespace, key);
}

/**
* Creates translatable text from a key.
*
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ compatUiId=switchy-compat-ui
compatUiName=Switchy Compat UI
compatUiDescription=UI previews for Switchy Compat modules for Switchy UI
# Mod Version
baseVersion=2.9.4
baseVersion=2.9.5
# Branch Metadata
branch=1.19
tagBranch=1.19
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ public void refresh() {
leftModulesFlow.clearChildren();
rightModulesFlow.clearChildren();
int labelSize = 100;
leftModulesFlow.child(getModuleFlow(new Identifier("placeholder", "placeholder"), Feedback.literal(""), (b, i) -> {
leftModulesFlow.child(getModuleFlow(Feedback.identifier("placeholder", "placeholder"), Feedback.literal(""), (b, i) -> {
}, true, Feedback.translatable("screen.switchy.manage.modules.disable"), Feedback.literal(""), labelSize).verticalSizing(Sizing.fixed(0)));
rightModulesFlow.child(getModuleFlow(new Identifier("placeholder", "placeholder"), Feedback.literal(""), (b, i) -> {
rightModulesFlow.child(getModuleFlow(Feedback.identifier("placeholder", "placeholder"), Feedback.literal(""), (b, i) -> {
}, true, Feedback.translatable("screen.switchy.manage.modules.disable"), Feedback.literal(""), labelSize).verticalSizing(Sizing.fixed(0)));

// Disabled Modules
Expand Down Expand Up @@ -496,9 +496,9 @@ protected void refreshDataModulesFlow() {
moduleSelector.leftModulesFlow.clearChildren();
moduleSelector.rightModulesFlow.clearChildren();
int labelSize = 100;
moduleSelector.leftModulesFlow.child(ModuleSelectorFlow.getModuleFlow(new Identifier("placeholder", "placeholder"), Feedback.literal(""), (b, i) -> {
moduleSelector.leftModulesFlow.child(ModuleSelectorFlow.getModuleFlow(Feedback.identifier("placeholder", "placeholder"), Feedback.literal(""), (b, i) -> {
}, false, Feedback.translatable("screen.switchy.manage.data.add"), Feedback.literal(""), labelSize).verticalSizing(Sizing.fixed(0)));
moduleSelector.rightModulesFlow.child(ModuleSelectorFlow.getModuleFlow(new Identifier("placeholder", "placeholder"), Feedback.literal(""), (b, i) -> {
moduleSelector.rightModulesFlow.child(ModuleSelectorFlow.getModuleFlow(Feedback.identifier("placeholder", "placeholder"), Feedback.literal(""), (b, i) -> {
}, false, Feedback.translatable("screen.switchy.manage.data.remove"), Feedback.literal(""), labelSize).verticalSizing(Sizing.fixed(0)));

if (isImporting) {
Expand Down

0 comments on commit 5eb5f79

Please sign in to comment.