Fix back-compat bugs
This commit is contained in:
parent
02e2916ce1
commit
b51b9828ac
@ -9,6 +9,7 @@ import me.bionicbeanie.mods.savecoords.IKeyBinds;
|
||||
import me.bionicbeanie.mods.savecoords.IKeyBinds.IKeyBinding;
|
||||
import me.bionicbeanie.mods.savecoords.model.ConfigData;
|
||||
import me.bionicbeanie.mods.savecoords.model.ConfigData.Config;
|
||||
import net.minecraft.client.util.InputUtil.Type;
|
||||
|
||||
public class SaveConfigsOperation extends ViewOperationBase<List<IKeyBinding>>{
|
||||
|
||||
@ -29,7 +30,7 @@ public class SaveConfigsOperation extends ViewOperationBase<List<IKeyBinding>>{
|
||||
for (IKeyBinding binding : state) {
|
||||
Config config = new Config();
|
||||
config.setName(binding.getName());
|
||||
config.setType(binding.getType());
|
||||
config.setType(parseTypeInt(binding.getType()));
|
||||
config.setCode(binding.getCode());
|
||||
|
||||
keyBinds.updateKeyBind(binding.getName(), binding.getType(), binding.getCode());
|
||||
@ -41,4 +42,12 @@ public class SaveConfigsOperation extends ViewOperationBase<List<IKeyBinding>>{
|
||||
|
||||
fileStore.writeConfigs(configData);
|
||||
}
|
||||
|
||||
private int parseTypeInt(Type type) {
|
||||
if(type == Type.KEYSYM) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,11 +55,11 @@ class FileStore implements IFileStore {
|
||||
return data.getConfigData();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeDefaultWorldName(String defaultWorldName) throws IOException {
|
||||
ModData data = load();
|
||||
data.setDefaultWorldName(defaultWorldName);;
|
||||
data.setDefaultWorldName(defaultWorldName);
|
||||
;
|
||||
|
||||
dump(data);
|
||||
}
|
||||
@ -134,6 +134,10 @@ class FileStore implements IFileStore {
|
||||
data.setConfigData(new ConfigData());
|
||||
}
|
||||
|
||||
if (data.getConfigData().getKeyConfigs() == null) {
|
||||
data.getConfigData().setKeyConfigs(new ConfigData.Config[] {});
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -95,11 +95,9 @@ class KeyBinds implements IKeyBinds {
|
||||
return defaultCode;
|
||||
}
|
||||
|
||||
public void setBoundKey(Type type, int code) {
|
||||
super.setBoundKey(type.createFromCode(code));
|
||||
|
||||
this.type = type;
|
||||
this.code = code;
|
||||
@Override
|
||||
public boolean wasPressed() {
|
||||
return super.wasPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -116,11 +114,24 @@ class KeyBinds implements IKeyBinds {
|
||||
public Text getNameLocalizedText() {
|
||||
return new TranslatableText(getTranslationKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getBoundKeyLocalizedText() {
|
||||
return super.getBoundKeyLocalizedText();
|
||||
}
|
||||
|
||||
void setBoundKey(Type type, int code) {
|
||||
super.setBoundKey(type.createFromCode(code));
|
||||
|
||||
this.type = type;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
try {
|
||||
ConfigData configData = fileStore.readConfigData();
|
||||
|
||||
Config[] configs = configData.getKeyConfigs();
|
||||
|
||||
if (configs == null) {
|
||||
@ -129,7 +140,7 @@ class KeyBinds implements IKeyBinds {
|
||||
|
||||
for (int i = 0; i < configs.length; ++i) {
|
||||
String name = configs[i].getName();
|
||||
Type type = configs[i].getType();
|
||||
Type type = parseType(configs[i].getType());
|
||||
int code = configs[i].getCode();
|
||||
|
||||
if (keyBinds.containsKey(name)) {
|
||||
@ -142,4 +153,12 @@ class KeyBinds implements IKeyBinds {
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Type parseType(int type) {
|
||||
if(type == 0) {
|
||||
return Type.KEYSYM;
|
||||
}
|
||||
|
||||
return Type.MOUSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,6 @@ package me.bionicbeanie.mods.savecoords.model;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import net.minecraft.client.util.InputUtil.Type;
|
||||
|
||||
public class ConfigData {
|
||||
|
||||
private Config[] keyConfigs;
|
||||
@ -12,13 +10,15 @@ public class ConfigData {
|
||||
private int defaultKeyBindingCode;
|
||||
|
||||
public ConfigData() {
|
||||
this.defaultKeyBindingCode = GLFW.GLFW_KEY_H; //Default value
|
||||
this.defaultKeyBindingCode = GLFW.GLFW_KEY_H;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setDefaultKeyBindingCode(int defaultKeyBindingCode) {
|
||||
this.defaultKeyBindingCode = defaultKeyBindingCode;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getDefaultKeyBindingCode() {
|
||||
return defaultKeyBindingCode;
|
||||
}
|
||||
@ -33,7 +33,7 @@ public class ConfigData {
|
||||
|
||||
public static class Config{
|
||||
private String name;
|
||||
private Type type;
|
||||
private int type;
|
||||
private int code;
|
||||
|
||||
public int getCode() {
|
||||
@ -42,10 +42,10 @@ public class ConfigData {
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
public Type getType() {
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(Type type) {
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
public String getName() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user