mirror of
https://github.com/JonasunderscoreJones/Microcraft.git
synced 2025-10-26 20:19:19 +01:00
updated .gitignore
This commit is contained in:
parent
733b6bc37b
commit
c9b2e9ef3e
43 changed files with 435 additions and 53 deletions
41
src/main/java/me/jonasjones/microcraft/Microcraft.java
Normal file
41
src/main/java/me/jonasjones/microcraft/Microcraft.java
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package me.jonasjones.microcraft;
|
||||
|
||||
import me.jonasjones.microcraft.config.ModConfigs;
|
||||
import me.jonasjones.microcraft.util.boardmanager.SerialNumberScanner;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Microcraft implements ClientModInitializer {
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
|
||||
public static final String MOD_ID = "microcraft";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
public static Logger VERBOSELOGGER = LoggerFactory.getLogger(MOD_ID + " - VERBOSE LOGGER");
|
||||
|
||||
public static boolean enabled = true;
|
||||
|
||||
public static void toggle() {
|
||||
enabled = !enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
//message from mod to confirm that it has been loaded
|
||||
LOGGER.info("Microcraft Initialized!");
|
||||
|
||||
// register configs
|
||||
ModConfigs.registerConfigs();
|
||||
|
||||
//blink LED on startup
|
||||
/*try {
|
||||
LedBlink.initialisation();
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.info("Failed to make Arduino LED blink. ARDUINO NOT CONNECTED!");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package me.jonasjones.microcraft.config;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
public class BoardsConfig {
|
||||
|
||||
public BoardsConfig() {
|
||||
}
|
||||
|
||||
// DON'T TOUCH THE FOLLOWING CODE
|
||||
private static BoardsConfig instance;
|
||||
|
||||
public static BoardsConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = fromDefaults();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void load(File file) {
|
||||
instance = fromFile(file);
|
||||
|
||||
// no config file found
|
||||
if (instance == null) {
|
||||
instance = fromDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
public static void load(String file) {
|
||||
load(new File(file));
|
||||
}
|
||||
|
||||
private static BoardsConfig fromDefaults() {
|
||||
BoardsConfig config = new BoardsConfig();
|
||||
return config;
|
||||
}
|
||||
|
||||
public void toFile(String file) {
|
||||
toFile(new File(file));
|
||||
}
|
||||
|
||||
public void toFile(File file) {
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String jsonConfig = gson.toJson(this);
|
||||
FileWriter writer;
|
||||
try {
|
||||
writer = new FileWriter(file);
|
||||
writer.write(jsonConfig);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static BoardsConfig fromFile(File configFile) {
|
||||
try {
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile)));
|
||||
return gson.fromJson(reader, BoardsConfig.class);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
return gson.toJson(this);
|
||||
}}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package me.jonasjones.microcraft.config;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import me.jonasjones.microcraft.config.SimpleConfig.DefaultConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModConfigProvider implements DefaultConfig {
|
||||
|
||||
private String configContents = "";
|
||||
|
||||
public List<Pair> getConfigsList() {
|
||||
return configsList;
|
||||
}
|
||||
|
||||
private final List<Pair> configsList = new ArrayList<>();
|
||||
|
||||
public void addKeyValuePair(Pair<String, ?> keyValuePair, String comment) {
|
||||
configsList.add(keyValuePair);
|
||||
configContents += keyValuePair.getFirst() + "=" + keyValuePair.getSecond() + " #"
|
||||
+ comment + " | default: " + keyValuePair.getSecond() + "\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String namespace) {
|
||||
return configContents;
|
||||
}
|
||||
}
|
||||
116
src/main/java/me/jonasjones/microcraft/config/ModConfigs.java
Normal file
116
src/main/java/me/jonasjones/microcraft/config/ModConfigs.java
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
package me.jonasjones.microcraft.config;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import me.jonasjones.microcraft.Microcraft;
|
||||
import me.jonasjones.microcraft.util.VerboseLogger;
|
||||
|
||||
public class ModConfigs {
|
||||
public static SimpleConfig CONFIGMAIN;
|
||||
public static SimpleConfig CONFIGLISTS;
|
||||
private static ModConfigProvider configMain;
|
||||
private static ModConfigProvider configLists;
|
||||
|
||||
//configMain
|
||||
public static Boolean ISENABLED;
|
||||
public static String DEFAULTBOARDFALLBACK;
|
||||
public static int LOOPINTERVAL;
|
||||
public static Boolean BOARDMELTING;
|
||||
public static Boolean VERBOSE = false; //needs to be set to false since the verbose logger is called before config file is fully loaded
|
||||
public static String EDITOR;
|
||||
public static String CUSTOMEDITOR;
|
||||
|
||||
//configList
|
||||
public static Boolean DISPLAYENTRYALL;
|
||||
public static Boolean DISPLAYENTRYPLAYERJUMP;
|
||||
public static Boolean DISPLAYENTRYPLAYERSPRINT;
|
||||
public static Boolean DISPLAYENTRYPLAYERWALKFORWARDS;
|
||||
public static Boolean DISPLAYENTRYPLAYERWALKBACKWARDS;
|
||||
public static Boolean DISPLAYENTRYPLAYERWALKRIGHT;
|
||||
public static Boolean DISPLAYENTRYPLAYERWALKLEFT;
|
||||
public static Boolean DISPLAYENTRYPLAYERSNEAK;
|
||||
public static Boolean DISPLAYENTRYISALL;
|
||||
public static Boolean DISPLAYENTRYISPLAYERJUMP;
|
||||
public static Boolean DISPLAYENTRYISPLAYERSPRINT;
|
||||
public static Boolean DISPLAYENTRYISPLAYERWALKFORWARDS;
|
||||
public static Boolean DISPLAYENTRYISPLAYERWALKBACKWARDS;
|
||||
public static Boolean DISPLAYENTRYISPLAYERWALKRIGHT;
|
||||
public static Boolean DISPLAYENTRYISPLAYERWALKLEFT;
|
||||
public static Boolean DISPLAYENTRYISPLAYERSNEAK;
|
||||
|
||||
|
||||
public static void registerConfigs() {
|
||||
configMain = new ModConfigProvider();
|
||||
configLists = new ModConfigProvider();
|
||||
|
||||
createConfigs();
|
||||
|
||||
CONFIGMAIN = SimpleConfig.of(Microcraft.MOD_ID + "-main").provider(configMain).request();
|
||||
CONFIGLISTS = SimpleConfig.of(Microcraft.MOD_ID + "-lists").provider(configLists).request();
|
||||
|
||||
assignConfigs();
|
||||
|
||||
//make verbose logger show that it is active and print configs to logger
|
||||
VerboseLogger.info("Verbose Logger is now logging.");
|
||||
VerboseLogger.info("Loaded config file CONFIGMAIN successfully: " + configMain.getConfigsList().size() + " configurations have been set properly");
|
||||
VerboseLogger.info("Loaded config file CONFIGMAIN successfully: " + configLists.getConfigsList().size() + " configurations have been set properly");
|
||||
}
|
||||
|
||||
private static void createConfigs() {
|
||||
//configMain
|
||||
configMain.addKeyValuePair(new Pair<>("basic.isEnabled", true), "whether or not the mod is enabled");
|
||||
configMain.addKeyValuePair(new Pair<>("basic.defaultBoardFallback", "A-nano"), "The board to automatically be selected if failed to detect automatically. All valid ID's can be found at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Microcontroller-Boards#supported-boards");
|
||||
configMain.addKeyValuePair(new Pair<>("advanced.loopInterval", 50), "The Delay in ms between each check.");
|
||||
configMain.addKeyValuePair(new Pair<>("fun.boardMelting", false), "Whether or not the board should have a flame overlay instead of being greyed out when not connected.");
|
||||
configMain.addKeyValuePair(new Pair<>("debug.verbose", false), "Toggle verbose console output.");
|
||||
configMain.addKeyValuePair(new Pair<>("editor.default", "ingame"), "The default editor for the board program. All valid default Editors can be found at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Board-Program-Editors#available-editors");
|
||||
configMain.addKeyValuePair(new Pair<>("editor.custom", "None"), "The editor to choose if 'editor.default' is set to 'custom'.");
|
||||
|
||||
//configLists
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntry.all", false), "Whether or not to display all entries. This overrides all other states except for debug and experimental entries. More infos can be found at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Pin-Map-Entries#list-of-all-entries");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntry.playerJump", true), "Display Player Jump Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntry.playerSprint", true), "Display Player Sprint Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkForwards", true), "Display Player Walk Forwards Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkBackwards", true), "Display Player Walk Backwards Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkRight", true), "Display Player Walk Right Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkLeft", true), "Display Player Walk Left Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntry.playerSneak", true), "Display Player Sneak Entry");
|
||||
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntryIs.all", false), "Whether or not to display all 'Is' entries. This overrides all other states except for debug and experimental entries. More infos can be found at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Pin-Map-Entries#list-of-all-entries");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerJump", true), "Display Is Player Jumping Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerSprint", true), "Display Is Player Sprinting Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkForwards", true), "Display Is Player Walking Forwards Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkBackwards", true), "Display Is Player Walking Backwards Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkRight", true), "Display Is Player Walking Right Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkLeft", true), "Display Is Player Walking Left Entry");
|
||||
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerSneak", true), "Display Is Player Sneaking Entry");
|
||||
}
|
||||
|
||||
private static void assignConfigs() {
|
||||
ISENABLED = CONFIGMAIN.getOrDefault("basic.isEnabled", true);
|
||||
DEFAULTBOARDFALLBACK = CONFIGMAIN.getOrDefault("basic.defaultBoardFallback", "A-nano");
|
||||
LOOPINTERVAL = CONFIGMAIN.getOrDefault("advanced.loopInterval", 50);
|
||||
BOARDMELTING = CONFIGMAIN.getOrDefault("fun.boardMelting", false);
|
||||
VERBOSE = CONFIGMAIN.getOrDefault("debug.verbose", false);
|
||||
EDITOR = CONFIGMAIN.getOrDefault("editor.default", "ingame");
|
||||
CUSTOMEDITOR = CONFIGMAIN.getOrDefault("editor.custom", "None");
|
||||
|
||||
DISPLAYENTRYALL = CONFIGLISTS.getOrDefault("displayEntry.all", false);
|
||||
DISPLAYENTRYPLAYERJUMP = CONFIGLISTS.getOrDefault("displayEntry.playerJump", true);
|
||||
DISPLAYENTRYPLAYERSPRINT = CONFIGLISTS.getOrDefault("displayEntry.playerSprint", true);
|
||||
DISPLAYENTRYPLAYERWALKFORWARDS = CONFIGLISTS.getOrDefault("displayEntry.playerWalkForwards", true);
|
||||
DISPLAYENTRYPLAYERWALKBACKWARDS = CONFIGLISTS.getOrDefault("displayEntry.playerWalkBackwards", true);
|
||||
DISPLAYENTRYPLAYERWALKRIGHT = CONFIGLISTS.getOrDefault("displayEntry.playerWalkRight", true);
|
||||
DISPLAYENTRYPLAYERWALKLEFT = CONFIGLISTS.getOrDefault("displayEntry.playerWalkRight", true);
|
||||
DISPLAYENTRYPLAYERSNEAK = CONFIGLISTS.getOrDefault("displayEntry.playerSneak", true);
|
||||
|
||||
DISPLAYENTRYISALL = CONFIGLISTS.getOrDefault("displayEntryIs.all", false);
|
||||
DISPLAYENTRYISPLAYERJUMP = CONFIGLISTS.getOrDefault("displayEntryIs.playerJump", true);
|
||||
DISPLAYENTRYISPLAYERSPRINT = CONFIGLISTS.getOrDefault("displayEntryIs.playerSprint", true);
|
||||
DISPLAYENTRYISPLAYERWALKFORWARDS = CONFIGLISTS.getOrDefault("displayEntryIs.playerWalkForwards", true);
|
||||
DISPLAYENTRYISPLAYERWALKBACKWARDS = CONFIGLISTS.getOrDefault("displayEntryIs.playerWalkBackwards", true);
|
||||
DISPLAYENTRYISPLAYERWALKRIGHT = CONFIGLISTS.getOrDefault("displayEntryIs.playerWalkRight", true);
|
||||
DISPLAYENTRYISPLAYERWALKLEFT = CONFIGLISTS.getOrDefault("displayEntryIs.playerWalkLeft", true);
|
||||
DISPLAYENTRYISPLAYERSNEAK = CONFIGLISTS.getOrDefault("displayEntryIs.playerSneak", true);
|
||||
}
|
||||
}
|
||||
251
src/main/java/me/jonasjones/microcraft/config/SimpleConfig.java
Normal file
251
src/main/java/me/jonasjones/microcraft/config/SimpleConfig.java
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
package me.jonasjones.microcraft.config;
|
||||
/*
|
||||
* Copyright (c) 2021 magistermaks
|
||||
* Slightly modified by Jonas_Jones 2022
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import me.jonasjones.microcraft.Microcraft;
|
||||
import me.jonasjones.microcraft.util.VerboseLogger;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SimpleConfig {
|
||||
private final HashMap<String, String> config = new HashMap<>();
|
||||
private final ConfigRequest request;
|
||||
private boolean broken = false;
|
||||
|
||||
public interface DefaultConfig {
|
||||
String get(String namespace);
|
||||
|
||||
static String empty(String namespace) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigRequest {
|
||||
|
||||
private final File file;
|
||||
private final String filename;
|
||||
private DefaultConfig provider;
|
||||
|
||||
private ConfigRequest(File file, String filename) {
|
||||
this.file = file;
|
||||
this.filename = filename;
|
||||
this.provider = DefaultConfig::empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default config provider, used to generate the
|
||||
* config if it's missing.
|
||||
*
|
||||
* @param provider default config provider
|
||||
* @return current config request object
|
||||
* @see DefaultConfig
|
||||
*/
|
||||
public ConfigRequest provider(DefaultConfig provider) {
|
||||
this.provider = provider;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the config from the filesystem.
|
||||
*
|
||||
* @return config object
|
||||
* @see SimpleConfig
|
||||
*/
|
||||
public SimpleConfig request() {
|
||||
return new SimpleConfig(this);
|
||||
}
|
||||
|
||||
private String getConfig() {
|
||||
return provider.get(filename) + "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new config request object, ideally `namespace`
|
||||
* should be the name of the mod id of the requesting mod
|
||||
*
|
||||
* @param filename - name of the config file
|
||||
* @return new config request object
|
||||
*/
|
||||
public static ConfigRequest of(String filename) {
|
||||
Path path = FabricLoader.getInstance().getConfigDir();
|
||||
return new ConfigRequest(path.resolve(filename + ".properties").toFile(), filename);
|
||||
}
|
||||
|
||||
private void createConfig() throws IOException {
|
||||
|
||||
// try creating missing files
|
||||
request.file.getParentFile().mkdirs();
|
||||
Files.createFile(request.file.toPath());
|
||||
|
||||
// write default config data
|
||||
PrintWriter writer = new PrintWriter(request.file, "UTF-8");
|
||||
writer.write(request.getConfig());
|
||||
writer.close();
|
||||
|
||||
}
|
||||
|
||||
private void loadConfig() throws IOException {
|
||||
Scanner reader = new Scanner(request.file);
|
||||
for (int line = 1; reader.hasNextLine(); line++) {
|
||||
parseConfigEntry(reader.nextLine(), line);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseConfigEntry(String entry, int line) {
|
||||
if (!entry.isEmpty() && !entry.startsWith("#")) {
|
||||
String[] parts = entry.split("=", 2);
|
||||
if (parts.length == 2) {
|
||||
//Recognise comments after a value
|
||||
String temp = parts[1].split(" #")[0];
|
||||
config.put(parts[0], temp);
|
||||
} else {
|
||||
throw new RuntimeException("Syntax error in config file on line " + line + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SimpleConfig(ConfigRequest request) {
|
||||
this.request = request;
|
||||
String identifier = "Config '" + request.filename + "'";
|
||||
|
||||
if (!request.file.exists()) {
|
||||
Microcraft.LOGGER.info(identifier + " is missing, generating default one...");
|
||||
|
||||
try {
|
||||
createConfig();
|
||||
} catch (IOException e) {
|
||||
Microcraft.LOGGER.error(identifier + " failed to generate!");
|
||||
Microcraft.LOGGER.trace(String.valueOf(e));
|
||||
broken = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!broken) {
|
||||
try {
|
||||
loadConfig();
|
||||
} catch (Exception e) {
|
||||
Microcraft.LOGGER.error(identifier + " failed to load!");
|
||||
Microcraft.LOGGER.trace(String.valueOf(e));
|
||||
broken = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries a value from config, returns `null` if the
|
||||
* key does not exist.
|
||||
*
|
||||
* @return value corresponding to the given key
|
||||
* @see SimpleConfig#getOrDefault
|
||||
*/
|
||||
@Deprecated
|
||||
public String get(String key) {
|
||||
return config.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string value from config corresponding to the given
|
||||
* key, or the default string if the key is missing.
|
||||
*
|
||||
* @return value corresponding to the given key, or the default value
|
||||
*/
|
||||
public String getOrDefault(String key, String def) {
|
||||
String val = get(key);
|
||||
return val == null ? def : val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns integer value from config corresponding to the given
|
||||
* key, or the default integer if the key is missing or invalid.
|
||||
*
|
||||
* @return value corresponding to the given key, or the default value
|
||||
*/
|
||||
public int getOrDefault(String key, int def) {
|
||||
try {
|
||||
return Integer.parseInt(get(key));
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns boolean value from config corresponding to the given
|
||||
* key, or the default boolean if the key is missing.
|
||||
*
|
||||
* @return value corresponding to the given key, or the default value
|
||||
*/
|
||||
public boolean getOrDefault(String key, boolean def) {
|
||||
String val = get(key);
|
||||
if (val != null) {
|
||||
return val.equalsIgnoreCase("true");
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns double value from config corresponding to the given
|
||||
* key, or the default string if the key is missing or invalid.
|
||||
*
|
||||
* @return value corresponding to the given key, or the default value
|
||||
*/
|
||||
public double getOrDefault(String key, double def) {
|
||||
try {
|
||||
return Double.parseDouble(get(key));
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If any error occurred during loading or reading from the config
|
||||
* a 'broken' flag is set, indicating that the config's state
|
||||
* is undefined and should be discarded using `delete()`
|
||||
*
|
||||
* @return the 'broken' flag of the configuration
|
||||
*/
|
||||
public boolean isBroken() {
|
||||
return broken;
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes the config file from the filesystem
|
||||
*
|
||||
* @return true if the operation was successful
|
||||
*/
|
||||
public boolean delete() {
|
||||
VerboseLogger.warn("Config '" + request.filename + "' was removed from existence! Restart the game to regenerate it.");
|
||||
return request.file.delete();
|
||||
}
|
||||
|
||||
}
|
||||
12
src/main/java/me/jonasjones/microcraft/data/BoardData.java
Normal file
12
src/main/java/me/jonasjones/microcraft/data/BoardData.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package me.jonasjones.microcraft.data;
|
||||
|
||||
public class BoardData {
|
||||
public int arduinoNanoPins = 22;
|
||||
|
||||
public enum board {
|
||||
Custom,
|
||||
ArduinoNano,
|
||||
ArduinoUno,
|
||||
ArduinoProMini
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package me.jonasjones.microcraft.gui.screens;
|
||||
|
||||
import me.jonasjones.microcraft.gui.widget.ArduinoNanoWidget;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class BoardScreen extends Screen {
|
||||
private final Screen parent;
|
||||
|
||||
public BoardScreen (Screen parent) {
|
||||
super(Text.of("Microcraft Configuration"));
|
||||
this.parent = parent;
|
||||
}
|
||||
protected void init() {
|
||||
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 12, 150, 20, Text.of("Configure Microcontrollers"), (button) -> {
|
||||
this.client.setScreen(new SelectDevice(this));
|
||||
}));
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 12, 150, 20, Text.of("Configure Microcraft"), (button) -> {
|
||||
this.client.setScreen(new ModSettings(this));
|
||||
}));
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, (button) -> {
|
||||
this.client.setScreen(this.parent);
|
||||
}));
|
||||
this.client.setScreen(new ArduinoNanoWidget(this.parent));
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package me.jonasjones.microcraft.gui.screens;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class GuiHome extends Screen {
|
||||
private final Screen parent;
|
||||
|
||||
public GuiHome (Screen parent) {
|
||||
super(Text.of("Microcraft Configuration"));
|
||||
this.parent = parent;
|
||||
}
|
||||
protected void init() {
|
||||
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 12, 150, 20, Text.of("Configure Microcontrollers"), (button) -> {
|
||||
this.client.setScreen(new SelectDevice(this));
|
||||
}));
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 12, 150, 20, Text.of("Configure Microcraft"), (button) -> {
|
||||
this.client.setScreen(new ModSettings(this));
|
||||
}));
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, (button) -> {
|
||||
this.client.setScreen(this.parent);
|
||||
}));
|
||||
this.addDrawableChild(new net.minecraft.client.gui.widget.CheckboxWidget(50, 50, 100, 20, Text.of("uwu checkbox"), false));
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package me.jonasjones.microcraft.gui.screens;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ModCreditsScreen extends Screen {
|
||||
|
||||
private final Screen parent;
|
||||
|
||||
public ModCreditsScreen(Screen parent) {
|
||||
super(Text.of("About Microcraft"));
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package me.jonasjones.microcraft.gui.screens;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ModSettings extends Screen {
|
||||
private final Screen parent;
|
||||
|
||||
public ModSettings (Screen parent) {
|
||||
super(Text.of("MicrocontrollerMC Controls"));
|
||||
this.parent = parent;
|
||||
}
|
||||
protected void init() {
|
||||
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 12, 150, 20, Text.of("Configure Microcontrollers"), (button) -> {
|
||||
this.client.setScreen(new SelectDevice(this));
|
||||
}));
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, (button) -> {
|
||||
this.client.setScreen(this.parent);
|
||||
}));
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package me.jonasjones.microcraft.gui.screens;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ObjectSelectionList {
|
||||
public static void display(int x, int y, int width, int height, List objects) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
package me.jonasjones.microcraft.gui.screens;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
|
||||
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
|
||||
import net.minecraft.client.gui.screen.world.WorldListWidget;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.OrderedText;
|
||||
import net.minecraft.text.Text;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class SelectDevice extends Screen {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
protected final Screen parent;
|
||||
@Nullable
|
||||
private List<OrderedText> tooltip;
|
||||
private ButtonWidget deleteButton;
|
||||
private ButtonWidget selectButton;
|
||||
private ButtonWidget editButton;
|
||||
private ButtonWidget recreateButton;
|
||||
protected TextFieldWidget searchBox;
|
||||
private WorldListWidget levelList;
|
||||
|
||||
public SelectDevice(Screen parent) {
|
||||
super(Text.translatable("selectWorld.title"));
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
|
||||
return super.mouseScrolled(mouseX, mouseY, amount);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
this.searchBox.tick();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
this.client.keyboard.setRepeatEvents(true);
|
||||
this.searchBox = new TextFieldWidget(this.textRenderer, this.width / 2 - 100, 22, 200, 20, this.searchBox, Text.translatable("selectWorld.search"));
|
||||
this.searchBox.setChangedListener((search) -> {
|
||||
//this.levelList.filter(search);
|
||||
});
|
||||
SelectWorldScreen uwu = new SelectWorldScreen(this);
|
||||
//this.levelList = new WorldListWidget(uwu, this.client, this.width, this.height, 48, this.height - 64, 36, this.getSearchFilter(), this.levelList);
|
||||
this.addSelectableChild(this.searchBox);
|
||||
this.addSelectableChild(this.levelList);
|
||||
this.selectButton = (ButtonWidget)this.addDrawableChild(new ButtonWidget(this.width / 2 - 154, this.height - 52, 150, 20, Text.translatable("selectWorld.select"), (button) -> {
|
||||
this.levelList.getSelectedAsOptional().ifPresent(WorldListWidget.WorldEntry::play);
|
||||
}));
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 + 4, this.height - 52, 150, 20, Text.translatable("selectWorld.create"), (button) -> {
|
||||
CreateWorldScreen.create(this.client, this);
|
||||
}));
|
||||
this.editButton = (ButtonWidget)this.addDrawableChild(new ButtonWidget(this.width / 2 - 154, this.height - 28, 72, 20, Text.translatable("selectWorld.edit"), (button) -> {
|
||||
this.levelList.getSelectedAsOptional().ifPresent(WorldListWidget.WorldEntry::edit);
|
||||
}));
|
||||
this.deleteButton = (ButtonWidget)this.addDrawableChild(new ButtonWidget(this.width / 2 - 76, this.height - 28, 72, 20, Text.translatable("selectWorld.delete"), (button) -> {
|
||||
this.levelList.getSelectedAsOptional().ifPresent(WorldListWidget.WorldEntry::deleteIfConfirmed);
|
||||
}));
|
||||
this.recreateButton = (ButtonWidget)this.addDrawableChild(new ButtonWidget(this.width / 2 + 4, this.height - 28, 72, 20, Text.translatable("selectWorld.recreate"), (button) -> {
|
||||
this.levelList.getSelectedAsOptional().ifPresent(WorldListWidget.WorldEntry::recreate);
|
||||
}));
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 + 82, this.height - 28, 72, 20, ScreenTexts.CANCEL, (button) -> {
|
||||
this.client.setScreen(this.parent);
|
||||
}));
|
||||
this.worldSelected(false);
|
||||
this.setInitialFocus(this.searchBox);
|
||||
}
|
||||
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return super.keyPressed(keyCode, scanCode, modifiers) ? true : this.searchBox.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.client.setScreen(this.parent);
|
||||
}
|
||||
|
||||
public boolean charTyped(char chr, int modifiers) {
|
||||
return this.searchBox.charTyped(chr, modifiers);
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.tooltip = null;
|
||||
//this.levelList.render(matrices, mouseX, mouseY, delta);
|
||||
this.searchBox.render(matrices, mouseX, mouseY, delta);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 8, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
if (this.tooltip != null) {
|
||||
this.renderOrderedTooltip(matrices, this.tooltip, mouseX, mouseY);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setTooltip(List<OrderedText> tooltip) {
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public void worldSelected(boolean active) {
|
||||
this.selectButton.active = active;
|
||||
this.deleteButton.active = active;
|
||||
this.editButton.active = active;
|
||||
this.recreateButton.active = active;
|
||||
}
|
||||
|
||||
public void removed() {
|
||||
if (this.levelList != null) {
|
||||
this.levelList.children().forEach(WorldListWidget.Entry::close);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Supplier<String> getSearchFilter() {
|
||||
return () -> {
|
||||
return this.searchBox.getText();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package me.jonasjones.microcraft.gui.screens.board;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class AdvancedPinMappingScreen extends Screen {
|
||||
|
||||
private final Screen parent;
|
||||
|
||||
public AdvancedPinMappingScreen(Screen parent) {
|
||||
super(Text.of("Advanced Pin Mapping"));
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package me.jonasjones.microcraft.gui.screens.board;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class AdvancedSettingsScreen extends Screen {
|
||||
|
||||
private final Screen parent;
|
||||
|
||||
public AdvancedSettingsScreen(Screen parent) {
|
||||
super(Text.of("Advanced Board Settings"));
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package me.jonasjones.microcraft.gui.screens.board;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ProfileSelectionScreen extends Screen {
|
||||
|
||||
private final Screen parent;
|
||||
|
||||
public ProfileSelectionScreen(Screen parent) {
|
||||
super(Text.of("Profile Selection Screen"));
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package me.jonasjones.microcraft.gui.screens.board;
|
||||
|
||||
import me.jonasjones.microcraft.gui.screens.ModSettings;
|
||||
import me.jonasjones.microcraft.gui.screens.SelectDevice;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class TextureSelectScreen extends Screen {
|
||||
private final Screen parent;
|
||||
|
||||
public TextureSelectScreen(Screen parent) {
|
||||
super(Text.of("Microcraft Configuration"));
|
||||
this.parent = parent;
|
||||
}
|
||||
protected void init() {
|
||||
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 12, 150, 20, Text.of("Configure Microcontrollers"), (button) -> {
|
||||
this.client.setScreen(new SelectDevice(this));
|
||||
}));
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 12, 150, 20, Text.of("Configure Microcraft"), (button) -> {
|
||||
this.client.setScreen(new ModSettings(this));
|
||||
}));
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, (button) -> {
|
||||
this.client.setScreen(this.parent);
|
||||
}));
|
||||
this.addDrawableChild(new net.minecraft.client.gui.widget.CheckboxWidget(50, 50, 100, 20, Text.of("uwu checkbox"), false));
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package me.jonasjones.microcraft.gui.widget;
|
||||
|
||||
import me.jonasjones.microcraft.Microcraft;
|
||||
import me.jonasjones.microcraft.gui.screens.ModSettings;
|
||||
import me.jonasjones.microcraft.gui.screens.board.AdvancedPinMappingScreen;
|
||||
import me.jonasjones.microcraft.gui.screens.board.AdvancedSettingsScreen;
|
||||
import me.jonasjones.microcraft.gui.screens.board.ProfileSelectionScreen;
|
||||
import me.jonasjones.microcraft.gui.screens.ModCreditsScreen;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ScrollableWidget;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ArduinoNanoWidget extends Screen {
|
||||
|
||||
private final Screen parent;
|
||||
|
||||
Identifier BOARD_TEXTURE = new Identifier(Microcraft.MOD_ID, "textures/boards/arduino-nano.png");
|
||||
|
||||
public ArduinoNanoWidget (Screen parent) {
|
||||
super(Text.of("Microcraft Configuration"));
|
||||
this.parent = parent;
|
||||
}
|
||||
protected void init() {
|
||||
//TODO: get current profile
|
||||
addDrawableChild(new ButtonWidget(this.width / 2 - 100, 40, 200, 20, Text.of("[Profile]"), (buttonWidget) -> this.client.setScreen(new ProfileSelectionScreen(this))));
|
||||
|
||||
//TODO: make Board texture clickable to select different texture.
|
||||
this.addDrawableChild(new TexturedButtonWidget(this.width / 2 - 26, this.height / 2 - 65, 52, 130, 0, 0, 130, BOARD_TEXTURE, 52, 130, (buttonWidget) -> this.client.setScreen(this)));
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height - 30, 200, 20, Text.of("About Microcraft"), (buttonWidget) -> this.client.setScreen(new ModCreditsScreen(this))));
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height - 55, 200, 20, Text.of("Advanced Pin Mapping"), (buttonWidget) -> this.client.setScreen(new AdvancedPinMappingScreen(this))));
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height - 80, 200, 20, Text.of("Advanced Board Settings"), (buttonWidget) -> this.client.setScreen(new AdvancedSettingsScreen(this))));
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height - 105, 200, 20, getToggleText(), (buttonWidget) -> Microcraft.toggle()));
|
||||
this.addDrawableChild(new ButtonWidget(this.width - 60, this.height - 30, 50, 20, Text.of("Done"), (buttonWidget) -> this.client.setScreen(this.parent)));
|
||||
this.addDrawableChild(new ButtonWidget(this.width - 210, this.height - 30, 140, 20, Text.of("Write Program to Board"), (buttonWidget) -> this.client.setScreen(this.parent)));
|
||||
this.addDrawableChild(new ButtonWidget(this.width - 210, this.height - 55, 200, 20, Text.of("Microcraft Settings"), (buttonWidget) -> this.client.setScreen(new ModSettings(this))));
|
||||
|
||||
this.addDrawableChild(new )
|
||||
|
||||
}
|
||||
private Text getToggleText() {
|
||||
if (Microcraft.enabled) {
|
||||
return Text.of("Microcraft: enabled");
|
||||
} else {
|
||||
return Text.of("Microcraft: disabled");
|
||||
}
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package me.jonasjones.microcraft.mixin;
|
||||
|
||||
import me.jonasjones.microcraft.gui.screens.GuiHome;
|
||||
import net.minecraft.client.gui.screen.GameMenuScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static me.jonasjones.microcraft.Microcraft.MOD_ID;
|
||||
|
||||
@Mixin(GameMenuScreen.class)
|
||||
public class GameMenuScreenMixin extends Screen {
|
||||
|
||||
protected GameMenuScreenMixin(Text title) {super(title);}
|
||||
|
||||
|
||||
@Inject(at = @At("HEAD"),method = "initWidgets")
|
||||
private void gameMenuScreenButton(CallbackInfo ci) {
|
||||
final Identifier ICON_TEXTURE = new Identifier(MOD_ID, "gui/button_icon.png");
|
||||
|
||||
int buttonX = this.width / 2 + 108;
|
||||
int buttonY = this.height / 4 + 8;
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(buttonX, buttonY, 20, 20, Text.of(""), (button) -> {
|
||||
this.client.setScreen(new GuiHome(this));
|
||||
}));
|
||||
this.addDrawableChild( new TexturedButtonWidget(buttonX, buttonY, 20, 20, 0, 0, 0, ICON_TEXTURE, 20, 20, (buttonWidget) -> this.client.setScreen(new GuiHome(this))));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package me.jonasjones.microcraft.mixin;
|
||||
|
||||
import me.jonasjones.microcraft.gui.screens.BoardScreen;
|
||||
import me.jonasjones.microcraft.gui.screens.GuiHome;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static me.jonasjones.microcraft.Microcraft.MOD_ID;
|
||||
|
||||
@Mixin(TitleScreen.class)
|
||||
public abstract class TitleScreenButtonMixin extends Screen {
|
||||
protected TitleScreenButtonMixin(Text title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "initWidgetsNormal")
|
||||
private void titleScreenButton(int y, int spacingY, CallbackInfo ci) {
|
||||
|
||||
final Identifier ICON_TEXTURE = new Identifier(MOD_ID, "textures/gui/button_icon.png");
|
||||
|
||||
int buttonX = this.width / 2 + 104;
|
||||
int buttonY = y + spacingY * 2;
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(buttonX, buttonY, 20, 20, Text.of(""), (button) -> {
|
||||
this.client.setScreen(new BoardScreen(this));
|
||||
}));
|
||||
this.addDrawableChild( new TexturedButtonWidget(buttonX, buttonY, 20, 20, 0, 0, 0, ICON_TEXTURE, 20, 20, (buttonWidget) -> this.client.setScreen(new BoardScreen(this))));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package me.jonasjones.microcraft.object;
|
||||
|
||||
public class MicroBoard {
|
||||
|
||||
public String name;
|
||||
public int id;
|
||||
public String port;
|
||||
public int baudrate;
|
||||
public String model;
|
||||
public PinMap pins = new PinMap();
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package me.jonasjones.microcraft.object;
|
||||
|
||||
public class PinMap {
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package me.jonasjones.microcraft.util;
|
||||
|
||||
import me.jonasjones.microcraft.Microcraft;
|
||||
import me.jonasjones.microcraft.config.ModConfigs;
|
||||
|
||||
public class VerboseLogger {
|
||||
public static void info(String message) {
|
||||
if (ModConfigs.VERBOSE) {
|
||||
Microcraft.VERBOSELOGGER.info(message);
|
||||
}
|
||||
}
|
||||
public void debug(String message) {
|
||||
if (ModConfigs.VERBOSE) {
|
||||
Microcraft.VERBOSELOGGER.debug(message);
|
||||
}
|
||||
}
|
||||
public static void error(String message) {
|
||||
if (ModConfigs.VERBOSE) {
|
||||
Microcraft.VERBOSELOGGER.error(message);
|
||||
}
|
||||
}
|
||||
public static void trace( String message) {
|
||||
if (ModConfigs.VERBOSE) {
|
||||
Microcraft.VERBOSELOGGER.trace(message);
|
||||
}
|
||||
}
|
||||
public static void warn( String message) {
|
||||
if (ModConfigs.VERBOSE) {
|
||||
Microcraft.VERBOSELOGGER.warn(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package me.jonasjones.microcraft.util.boardmanager;
|
||||
|
||||
|
||||
import com.fazecast.jSerialComm.SerialPort;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SerialNumberScanner {
|
||||
public static List<String> scan() {
|
||||
SerialPort[] ports = SerialPort.getCommPorts();
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (SerialPort port : ports) {
|
||||
System.out.println(port.getSystemPortName());
|
||||
list.add(port.getSystemPortName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue