Skip to content

Commit

Permalink
support configuring booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
AlurienFlame committed Dec 21, 2024
1 parent d8ebe05 commit 5ff9e9c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/main/java/net/balancedrecall/BalancedRecall.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
public class BalancedRecall implements ModInitializer {
public static final String MODID = "balancedrecall";

public static final BalancedRecallConfig config = new BalancedRecallConfig();

// Items
private static final RegistryKey<Item> magic_mirror_key = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MODID, "magic_mirror"));
public static final Item MAGIC_MIRROR = new MagicMirror(new Item.Settings().registryKey(magic_mirror_key).maxDamage(256).repairable(Items.ENDER_PEARL).useCooldown(1));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/balancedrecall/BalancedRecallConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BalancedRecallConfig {
static File configFile = configPath.toFile();

// Configs
public JsonObject config;
public static JsonObject config;

// Constructor creates the config file if it doesn't exist
public BalancedRecallConfig() {
Expand Down Expand Up @@ -64,7 +64,7 @@ private void read() {
}

// Write the current config to the file.
public void write() {
public static void write() {
try {
FileWriter writer = new FileWriter(configFile);
new GsonBuilder().setPrettyPrinting().create().toJson(config, writer);
Expand Down
36 changes: 22 additions & 14 deletions src/main/java/net/balancedrecall/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ protected void init() {

// Mirror settings
// TODO: Save booleans
column.add(CheckboxWidget.builder(Text.of("Taking damage interrupts recall"), this.textRenderer).checked(true).build());
column.add(CheckboxWidget.builder(Text.of("Taking damage puts mirror on cooldown"), this.textRenderer).checked(true).build());
column.add(CheckboxWidget.builder(Text.of("Recalling is impossible when mosters are nearby"), this.textRenderer).checked(true).build());
column.add(CheckboxWidget.builder(Text.of("Taking damage interrupts recall"), this.textRenderer).checked(BalancedRecallConfig.config.get("take_damage_interrupts_recall").getAsBoolean()).callback((checkbox, checked)->{
BalancedRecallConfig.config.addProperty("take_damage_interrupts_recall", checked);
}).build());
column.add(CheckboxWidget.builder(Text.of("Taking damage puts mirror on cooldown"), this.textRenderer).checked(BalancedRecallConfig.config.get("take_damage_puts_mirror_on_cooldown").getAsBoolean()).callback((checkbox, checked)->{
BalancedRecallConfig.config.addProperty("take_damage_puts_mirror_on_cooldown", checked);
}).build());
column.add(CheckboxWidget.builder(Text.of("Recalling is impossible when mosters are nearby"), this.textRenderer).checked(BalancedRecallConfig.config.get("recall_impossible_when_monsters_nearby").getAsBoolean()).callback((checkbox, checked)->{
BalancedRecallConfig.config.addProperty("recall_impossible_when_monsters_nearby", checked);
}).build());

GridWidget grid = new GridWidget();
grid.getMainPositioner().margin(4).alignHorizontalCenter();
Expand All @@ -51,39 +57,41 @@ protected void init() {
TextFieldWidget magicMirrorUseTime = new TextFieldWidget(this.textRenderer, 100, 20, Text.of("Magic Mirror Use Time"));
magicMirrorUseTime.setChangedListener((value)->{
// TODO: validate
BalancedRecall.config.config.addProperty("magic_mirror_use_time_ticks", Integer.parseInt(value));
BalancedRecallConfig.config.addProperty("magic_mirror_use_time_ticks", Integer.parseInt(value));
});
magicMirrorUseTime.setText(BalancedRecall.config.config.get("magic_mirror_use_time_ticks").getAsString());
magicMirrorUseTime.setText(BalancedRecallConfig.config.get("magic_mirror_use_time_ticks").getAsString());
adder.add(magicMirrorUseTime);

adder.add(new TextWidget(Text.of("Magic Mirror Cooldown Time"), this.textRenderer));
TextFieldWidget magicMirrorCooldownTime = new TextFieldWidget(this.textRenderer, 100, 20, Text.of("Magic Mirror Cooldown Time"));
magicMirrorCooldownTime.setChangedListener((value)->{
BalancedRecall.config.config.addProperty("magic_mirror_cooldown_time_seconds", Integer.parseInt(value));
BalancedRecallConfig.config.addProperty("magic_mirror_cooldown_time_seconds", Integer.parseInt(value));
});
magicMirrorCooldownTime.setText(BalancedRecall.config.config.get("magic_mirror_cooldown_time_seconds").getAsString());
magicMirrorCooldownTime.setText(BalancedRecallConfig.config.get("magic_mirror_cooldown_time_seconds").getAsString());
adder.add(magicMirrorCooldownTime);

adder.add(new TextWidget(Text.of("Dimensional Mirror Use Time"), this.textRenderer));
TextFieldWidget dimensionalMirrorUseTime = new TextFieldWidget(this.textRenderer, 100, 20, Text.of("Dimensional Mirror Use Time"));
dimensionalMirrorUseTime.setChangedListener((value)->{
BalancedRecall.config.config.addProperty("dimensional_mirror_use_time_ticks", Integer.parseInt(value));
BalancedRecallConfig.config.addProperty("dimensional_mirror_use_time_ticks", Integer.parseInt(value));
});
dimensionalMirrorUseTime.setText(BalancedRecall.config.config.get("dimensional_mirror_use_time_ticks").getAsString());
dimensionalMirrorUseTime.setText(BalancedRecallConfig.config.get("dimensional_mirror_use_time_ticks").getAsString());
adder.add(dimensionalMirrorUseTime);

adder.add(new TextWidget(Text.of("Dimensional Mirror Cooldown Time"), this.textRenderer));
TextFieldWidget dimensionalMirrorCooldownTime = new TextFieldWidget(this.textRenderer, 100, 20, Text.of("Dimensional Mirror Cooldown Time"));
dimensionalMirrorCooldownTime.setChangedListener((value)->{
BalancedRecall.config.config.addProperty("dimensional_mirror_cooldown_time_seconds", Integer.parseInt(value));
BalancedRecallConfig.config.addProperty("dimensional_mirror_cooldown_time_seconds", Integer.parseInt(value));
});
dimensionalMirrorCooldownTime.setText(BalancedRecall.config.config.get("dimensional_mirror_cooldown_time_seconds").getAsString());
dimensionalMirrorCooldownTime.setText(BalancedRecallConfig.config.get("dimensional_mirror_cooldown_time_seconds").getAsString());
adder.add(dimensionalMirrorCooldownTime);

column.add(grid);

// Recall settings
column.add(CheckboxWidget.builder(Text.of("Sleeping mat resets phantom timer"), this.textRenderer).build());
// Mat settings
column.add(CheckboxWidget.builder(Text.of("Sleeping mat resets phantom timer"), this.textRenderer).checked(BalancedRecallConfig.config.get("sleeping_mat_resets_phantom_timer").getAsBoolean()).callback((checkbox, checked)->{
BalancedRecallConfig.config.addProperty("sleeping_mat_resets_phantom_timer", checked);
}).build());

this.layout.addBody(column);

Expand All @@ -104,7 +112,7 @@ protected void refreshWidgetPositions() {

@Override
public void close() {
BalancedRecall.config.write();
BalancedRecallConfig.write();
this.client.setScreen(this.parent);
}
}

0 comments on commit 5ff9e9c

Please sign in to comment.