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