-
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
1 parent
e5f7fac
commit 568808c
Showing
15 changed files
with
213 additions
and
181 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
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
19 changes: 19 additions & 0 deletions
19
common/src/main/java/dev/schmarrn/lighty/config/BooleanConfig.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,19 @@ | ||
package dev.schmarrn.lighty.config; | ||
|
||
public class BooleanConfig extends ConfigType<Boolean> { | ||
BooleanConfig(String key, Boolean defaultValue) { | ||
super(key, defaultValue); | ||
|
||
Config.register(key, this); | ||
} | ||
|
||
@Override | ||
String serialize() { | ||
return Boolean.toString(getValue()); | ||
} | ||
|
||
@Override | ||
void deserialize(String value) { | ||
setValue(Boolean.valueOf(value)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
common/src/main/java/dev/schmarrn/lighty/config/ColorConfig.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,25 @@ | ||
package dev.schmarrn.lighty.config; | ||
|
||
public class ColorConfig extends ConfigType<Integer> { | ||
public ColorConfig(String key, Integer defaultValue) { | ||
super(key, defaultValue); | ||
|
||
Config.register(key, this); | ||
} | ||
|
||
@Override | ||
String serialize() { | ||
int color = getValue(); | ||
StringBuilder ret = new StringBuilder("0x"); | ||
for (int ii = 5; ii >= 0; --ii) { | ||
int nibble = (color & (0xF << (4*ii))) >> (4*ii); | ||
ret.append(Integer.toHexString(nibble)); | ||
} | ||
return ret.toString(); | ||
} | ||
|
||
@Override | ||
void deserialize(String color) { | ||
setValue(Integer.parseUnsignedInt(color.replace("0x", ""), 16)); | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
common/src/main/java/dev/schmarrn/lighty/config/ConfigSerDe.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,6 @@ | ||
package dev.schmarrn.lighty.config; | ||
|
||
public abstract class ConfigSerDe { | ||
abstract String serialize(); | ||
abstract void deserialize(String value); | ||
} |
34 changes: 34 additions & 0 deletions
34
common/src/main/java/dev/schmarrn/lighty/config/ConfigType.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,34 @@ | ||
package dev.schmarrn.lighty.config; | ||
|
||
abstract class ConfigType<T> extends ConfigSerDe{ | ||
public void onChange(T value){} | ||
|
||
private final T DEFAULT_VALUE; | ||
private final String KEY; | ||
|
||
private T value; | ||
|
||
public T getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(T newValue) { | ||
value = newValue; | ||
onChange(newValue); | ||
Config.save(); | ||
} | ||
|
||
public void resetToDefault() { | ||
value = DEFAULT_VALUE; | ||
} | ||
|
||
public String getKey() { | ||
return KEY; | ||
} | ||
|
||
ConfigType(String key, T defaultValue) { | ||
this.KEY = key; | ||
this.DEFAULT_VALUE = defaultValue; | ||
this.value = defaultValue; | ||
} | ||
} |
Oops, something went wrong.