From 126ac736ae26b2c901fccdbb3fa345d75a9083bf Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 6 Jun 2023 22:36:58 +0200 Subject: [PATCH 1/7] Add Lua Support --- build.gradle | 1 + gradle.properties | 2 +- .../advancedscripts/lexer/Command.java | 13 - .../advancedscripts/lexer/Commands.java | 13 - .../lexer/ExpressionColorizer.java | 134 ------- .../advancedscripts/lexer/Headers.java | 13 - .../advancedscripts/lexer/Operators.java | 13 - .../lexer/ScriptColorizer.java | 330 +++++------------- .../lexer/ScriptSyntaxPacketParser.java | 78 ----- .../advancedscripts/lexer/Token.java | 8 + .../advancedscripts/lexer/TokenType.java | 13 - .../lexer/TokenTypeColors.java | 7 +- .../lexer/VariablePrefixes.java | 13 - .../lexer/VariableSuffixes.java | 13 - .../mixin/ClientPlayNetworkHandlerMixin.java | 31 -- .../screen/ScriptEditScreen.java | 63 ++-- .../resources/advancedscripts.mixins.json | 3 +- src/main/resources/fabric.mod.json | 3 +- 18 files changed, 140 insertions(+), 611 deletions(-) delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/Command.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/Commands.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/ExpressionColorizer.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/Headers.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/Operators.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptSyntaxPacketParser.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/TokenType.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/VariablePrefixes.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/VariableSuffixes.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/mixin/ClientPlayNetworkHandlerMixin.java diff --git a/build.gradle b/build.gradle index 61ed747..d3a6128 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,7 @@ version = project.mod_version group = project.maven_group repositories { + mavenCentral() } dependencies { diff --git a/gradle.properties b/gradle.properties index 50caf5c..47f4927 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,6 @@ org.gradle.parallel=true loader_version=0.14.11 # Mod Properties - mod_version = 1.0.0 + mod_version = 2.0.0 maven_group = de.zonlykroks archives_base_name = AdvancedScripts \ No newline at end of file diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/Command.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/Command.java deleted file mode 100644 index 5930bc9..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/Command.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -import java.util.List; - -public class Command { - public final boolean repeatable; - public final List> arguments; - - public Command(boolean repeatable, List> arguments) { - this.repeatable = repeatable; - this.arguments = arguments; - } -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/Commands.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/Commands.java deleted file mode 100644 index 3c2debc..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/Commands.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -import java.util.HashMap; -import java.util.Map; - -public class Commands { - - private Commands() { - throw new IllegalStateException("Utility class"); - } - - public static Map COMMANDS = new HashMap<>(); -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/ExpressionColorizer.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/ExpressionColorizer.java deleted file mode 100644 index feaea4a..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/ExpressionColorizer.java +++ /dev/null @@ -1,134 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class ExpressionColorizer { - - private ExpressionColorizer() { - throw new IllegalStateException("Utility class"); - } - - public static List colorize(String expression) { - List parts = tokenize(expression); - List tokens = new ArrayList<>(); - for (int i = 0; i < parts.size(); i++) { - String part = parts.get(i); - if ("{".equals(part) || "}".equals(part)) { - tokens.add(new Token(part, TokenTypeColors.OTHER)); - continue; - } - if ("true".equalsIgnoreCase(part) || "false".equalsIgnoreCase(part)) { - tokens.add(new Token(part, TokenTypeColors.BOOLEAN)); - continue; - } - try { - Double.parseDouble(part); - tokens.add(new Token(part, TokenTypeColors.NUMBER)); - continue; - } catch (NumberFormatException ignored) { - } - try { - Long.parseLong(part); - tokens.add(new Token(part, TokenTypeColors.NUMBER)); - continue; - } catch (NumberFormatException ignored) { - } - if (part.contains(".")) { - String[] split = part.split("\\."); - if (split.length == 1) { - tokens.add(new Token(part, TokenTypeColors.VARIABLE)); - continue; - } - if (VariablePrefixes.RPEFIXES.contains(split[0])) { - tokens.add(new Token(split[0], TokenTypeColors.OTHER)); - tokens.add(new Token(".", TokenTypeColors.OTHER)); - split = Arrays.copyOfRange(split, 1, split.length); - } - tokens.add(new Token(split[0], TokenTypeColors.VARIABLE)); - for (int j = 1; j < split.length; j++) { - String s = split[j]; - tokens.add(new Token(".", TokenTypeColors.OTHER)); - if (VariableSuffixes.SUFFIXES.contains(s)) { - tokens.add(new Token(s, TokenTypeColors.OTHER)); - } else { - tokens.add(new Token(s, TokenTypeColors.ERROR)); - } - } - continue; - } - if (Operators.OPERATORS.contains(part)) { - String previous = get(parts, i, -1); - String next = get(parts, i, 1); - if (previous == null || next == null) { - tokens.add(new Token(part, TokenTypeColors.ERROR)); - continue; - } - if (Operators.OPERATORS.contains(previous) || Operators.OPERATORS.contains(next)) { - tokens.add(new Token(part, TokenTypeColors.ERROR)); - continue; - } - if ("{".equals(previous) || "}".equals(next)) { - tokens.add(new Token(part, TokenTypeColors.ERROR)); - continue; - } - tokens.add(new Token(part, TokenTypeColors.OTHER)); - continue; - } - if (part.matches("[+\\-*/%^&|<>=!]+")) { - tokens.add(new Token(part, TokenTypeColors.ERROR)); - continue; - } - tokens.add(new Token(part, TokenTypeColors.VARIABLE)); - } - return tokens; - } - - private static String get(List parts, int index, int direction) { - for (int i = index + direction; i >= 0 && i < parts.size(); i += direction) { - String part = parts.get(i); - if (!part.isBlank()) return part; - } - return null; - } - - private static List tokenize(String s) { - List tokens = new ArrayList<>(); - StringBuilder token = new StringBuilder(); - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c == '{' || c == '}' || c == ' ') { - if (token.length() > 0) { - tokens.add(token.toString()); - token = new StringBuilder(); - } - tokens.add(c + ""); - continue; - } - StringBuilder op = new StringBuilder(); - for (int j = i; j < s.length(); j++) { - char k = s.charAt(j); - if (k == '+' || k == '-' || k == '*' || k == '/' || k == '%' || k == '^' || k == '&' || k == '|' || k == '>' || k == '<' || k == '=' || k == '!') { - op.append(k); - } else { - break; - } - } - if (op.length() > 0) { - if (token.length() > 0) { - tokens.add(token.toString()); - token = new StringBuilder(); - } - tokens.add(op.toString()); - i += op.length() - 1; - continue; - } - token.append(c); - } - if (token.length() > 0) { - tokens.add(token.toString()); - } - return tokens; - } -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/Headers.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/Headers.java deleted file mode 100644 index 2e3c4e7..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/Headers.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -import java.util.HashSet; -import java.util.Set; - -public class Headers { - - private Headers() { - throw new IllegalStateException("Utility class"); - } - - public static final Set HEADERS = new HashSet<>(); -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/Operators.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/Operators.java deleted file mode 100644 index 70586f4..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/Operators.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -import java.util.HashSet; -import java.util.Set; - -public class Operators { - - private Operators() { - throw new IllegalStateException("Utility class"); - } - - public static final Set OPERATORS = new HashSet<>(); -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java index 6086486..77e57d9 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java +++ b/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java @@ -2,277 +2,115 @@ package de.zonlykroks.advancedscripts.lexer; import java.util.ArrayList; import java.util.List; +import java.util.Set; public class ScriptColorizer { + private static final Set KEYWORDS = Set.of( + "and", "break", "do", "else", "elseif", "end", "for", "function", "goto", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "until", "while" + ); + private ScriptColorizer() { throw new IllegalStateException("Utility class"); } - public static List colorize(int lineNumber, String line) { - if (lineNumber == 0) { - List tokens = colorizeHeader(line); - if (tokens != null) return tokens; - } - - List tokens; - tokens = colorizeComment(line); - if (tokens != null) return tokens; - tokens = colorizeJumpPoint(line); + public static List colorize(String line) { + List tokens = colorizeComment(line); if (tokens != null) return tokens; return colorizeLine(line); } - private static List colorizeHeader(String line) { - if (!line.startsWith("#!")) return null; - List tokens = new ArrayList<>(); - tokens.add(new Token("#!", TokenTypeColors.COMMENT)); - String s = line.substring(2); - - for (String pattern : Headers.HEADERS) { - if (s.matches(pattern)) { - tokens.add(new Token(s, TokenTypeColors.OTHER)); - return tokens; - } - } - tokens.add(new Token(s, TokenTypeColors.ERROR)); - return tokens; - } - private static List colorizeComment(String line) { - if (!line.startsWith("#")) return null; + if (!line.startsWith("--")) return null; return List.of(new Token(line, TokenTypeColors.COMMENT)); } - private static List colorizeJumpPoint(String line) { - if (!line.startsWith(".")) return null; - return List.of(new Token(line, TokenTypeColors.JUMP_POINT)); - } - private static List colorizeLine(String line) { List tokens = new ArrayList<>(); - String command = line; - if (line.indexOf(' ') != -1) { - command = line.substring(0, line.indexOf(' ')); - } - boolean repeatable = false; - List> argumentTypes = null; - if (Commands.COMMANDS.containsKey(command)) { - Command c = Commands.COMMANDS.get(command); - repeatable = c.repeatable; - argumentTypes = c.arguments; - tokens.add(new Token(command, TokenTypeColors.LITERAL)); - } else { - repeatable = true; - argumentTypes = new ArrayList<>(); - argumentTypes.add(List.of(TokenType.any)); - tokens.add(new Token(command, TokenTypeColors.OTHER)); - } - if (command.equals(line)) return tokens; - tokens.add(Token.SPACE); + StringBuilder currentToken = new StringBuilder(); + + boolean inString = false; + boolean doubleQuoteString = false; + + System.out.println('"' + line + '"'); + + for (char c : line.toCharArray()) { + switch (c) { + case '"' -> { + if (inString) { + currentToken.append(c); + if (doubleQuoteString) { + tokens.add(new Token(currentToken.toString(), TokenTypeColors.STRING)); + currentToken = new StringBuilder(); + inString = false; + doubleQuoteString = false; + } + } else { + inString = true; + doubleQuoteString = true; + if (currentToken.length() > 0) { + tokens.add(toToken(currentToken.toString())); + currentToken = new StringBuilder(); + } + currentToken.append(c); + } + } + case '\'' -> { + if (inString) { + currentToken.append(c); + if (!doubleQuoteString) { + tokens.add(new Token(currentToken.toString(), TokenTypeColors.STRING)); + currentToken = new StringBuilder(); + inString = false; + } + } else { + inString = true; + doubleQuoteString = false; + if (currentToken.length() > 0) { + tokens.add(toToken(currentToken.toString())); + currentToken = new StringBuilder(); + } + currentToken.append(c); + } + } + case '-', ';', '(', ')', ',', ' ', '{', '\t' -> { + if (inString) { + currentToken.append(c); + } else { + if(currentToken.length() > 0) { + tokens.add(toToken(currentToken.toString())); + } + tokens.add(new Token(String.valueOf(c), TokenTypeColors.OTHER)); + currentToken = new StringBuilder(); + } + } + default -> currentToken.append(c); + } + } + + if (currentToken.length() > 0) { + tokens.add(toToken(currentToken.toString())); + } + + System.out.println(tokens); - String args = line.substring(command.length() + 1); - tokens.addAll(colorizeArgs(args, repeatable, argumentTypes)); return tokens; } - private static List colorizeArgs(String args, boolean repeatable, List> argumentTypes) { - List tokens = new ArrayList<>(); - - for (List tokenTypes : argumentTypes) { - List temp = new ArrayList<>(); - int index = 0; - int argIndex = 0; - try { - while (argIndex < args.length()) { - if (args.charAt(argIndex) == ' ') { - argIndex++; - temp.add(Token.SPACE); - continue; - } - List current = parse(tokenTypes.get(index), args.substring(argIndex)); - if (current.isEmpty()) { - break; - } - temp.addAll(current); - argIndex += current.stream().mapToInt(t -> t.text.length()).sum(); - index++; - if (repeatable && index == tokenTypes.size()) { - index--; - } - if (index == tokenTypes.size()) { - break; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - if (argIndex != args.length()) { - continue; - } - if (index != tokenTypes.size() - (repeatable ? 1 : 0)) { - continue; - } - - if (!temp.isEmpty()) { - tokens.addAll(temp); - break; - } - } - - if (tokens.isEmpty()) { - tokens.add(new Token(args, TokenTypeColors.OTHER)); - } - return tokens; - } - - private static List parse(TokenType type, String current) { - return switch (type) { - case any -> parseAny(current); - case expression -> parseExpression(current); - case jump_point -> parseJumpPoint(current); - case variable -> parseVariable(current); - case text_type -> parseText(current); - case number_type -> parseNumber(current); - case floating_number_type -> parseFloatingNumber(current); - case boolean_type -> parseBoolean(current); - }; - } - - private static List parseAny(String current) { - List tokens = parseExpression(current); - if (!tokens.isEmpty()) return tokens; - tokens = parseFloatingNumber(current); - if (!tokens.isEmpty()) return tokens; - tokens = parseNumber(current); - if (!tokens.isEmpty()) return tokens; - tokens = parseBoolean(current); - if (!tokens.isEmpty()) return tokens; - return parseText(current); - } - - private static List parseExpression(String current) { - if (!current.startsWith("{")) return new ArrayList<>(); - int depth = 0; - int index = 0; - do { - if (current.charAt(index) == '{') { - depth++; - } else if (current.charAt(index) == '}') { - depth--; - } - index++; - } while (depth != 0 && index < current.length()); - if (depth != 0) return List.of(new Token(current, TokenTypeColors.ERROR)); - return ExpressionColorizer.colorize(current.substring(0, index)); - } - - private static List parseJumpPoint(String current) { - int index = current.indexOf(' '); - if (index == -1) { - return List.of(new Token(current, TokenTypeColors.JUMP_POINT)); - } else { - return List.of(new Token(current.substring(0, index), TokenTypeColors.JUMP_POINT)); - } - } - - private static List parseVariable(String current) { - int index = current.indexOf(' '); - if (index == -1) { - return List.of(new Token(current, TokenTypeColors.VARIABLE)); - } else { - return List.of(new Token(current.substring(0, index), TokenTypeColors.VARIABLE)); - } - } - - private static List parseText(String current) { - int index = current.indexOf(' '); - if (index != -1) { - current = current.substring(0, index); - } - List tokens = new ArrayList<>(); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < current.length(); i++) { - char c = current.charAt(i); - if (c == '&' && i + 1 < current.length()) { - char color = current.charAt(i + 1); - if (color >= '0' && color <= '9' || color >= 'a' && color <= 'f' || color >= 'A' && color <= 'F') { - if (sb.length() > 0) { - tokens.add(new Token(sb.toString(), TokenTypeColors.TEXT)); - sb = new StringBuilder(); - } - i++; - switch (color) { - case '0' -> tokens.add(new Token("&0", 0xFF000000)); - case '1' -> tokens.add(new Token("&1", 0xFF0000AA)); - case '2' -> tokens.add(new Token("&2", 0xFF00AA00)); - case '3' -> tokens.add(new Token("&3", 0xFF00AAAA)); - case '4' -> tokens.add(new Token("&4", 0xFFAA0000)); - case '5' -> tokens.add(new Token("&5", 0xFFAA00AA)); - case '6' -> tokens.add(new Token("&6", 0xFFFFAA00)); - case '7' -> tokens.add(new Token("&7", 0xFFAAAAAA)); - case '8' -> tokens.add(new Token("&8", 0xFF555555)); - case '9' -> tokens.add(new Token("&9", 0xFF5555FF)); - case 'a', 'A' -> tokens.add(new Token("&a", 0xFF55FF55)); - case 'b', 'B' -> tokens.add(new Token("&b", 0xFF55FFFF)); - case 'c', 'C' -> tokens.add(new Token("&c", 0xFFFF5555)); - case 'd', 'D' -> tokens.add(new Token("&d", 0xFFFF55FF)); - case 'e', 'E' -> tokens.add(new Token("&e", 0xFFFFFF55)); - case 'f', 'F' -> tokens.add(new Token("&f", 0xFFFFFFFF)); - default -> tokens.add(new Token("&" + color, TokenTypeColors.TEXT)); - } - } else { - sb.append(c); - } + private static Token toToken(String text) { + if (text.length() > 0) { + if (KEYWORDS.contains(text)) { + return new Token(text, TokenTypeColors.CONSTANT); + } else if ("true".contentEquals(text) || "false".contentEquals(text)) { + return new Token(text, TokenTypeColors.BOOLEAN); + } else if (text.matches("[0-9]+")) { + return new Token(text, TokenTypeColors.NUMBER); } else { - sb.append(c); + return new Token(text, TokenTypeColors.OTHER); } - } - if (sb.length() > 0) { - tokens.add(new Token(sb.toString(), TokenTypeColors.TEXT)); - } - return tokens; - } - - private static List parseNumber(String current) { - int index = current.indexOf(' '); - String number = current; - if (index != -1) { - number = current.substring(0, index); - } - try { - Long.parseLong(number); - return List.of(new Token(number, TokenTypeColors.NUMBER)); - } catch (NumberFormatException e) { - return new ArrayList<>(); - } - } - - private static List parseFloatingNumber(String current) { - int index = current.indexOf(' '); - String number = current; - if (index != -1) { - number = current.substring(0, index); - } - try { - Double.parseDouble(number); - return List.of(new Token(number, TokenTypeColors.NUMBER)); - } catch (NumberFormatException e) { - return new ArrayList<>(); - } - } - - private static List parseBoolean(String current) { - int index = current.indexOf(' '); - String bool = current; - if (index != -1) { - bool = current.substring(0, index); - } - if ("true".equalsIgnoreCase(bool) || "false".equalsIgnoreCase(bool)) { - return List.of(new Token(bool, TokenTypeColors.BOOLEAN)); } else { - return new ArrayList<>(); + return Token.SPACE; } } } diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptSyntaxPacketParser.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptSyntaxPacketParser.java deleted file mode 100644 index abf09f6..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptSyntaxPacketParser.java +++ /dev/null @@ -1,78 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -public class ScriptSyntaxPacketParser { - - private ScriptSyntaxPacketParser() { - throw new IllegalStateException("Utility class"); - } - - private static final TokenType[] TOKEN_TYPES = TokenType.values(); - - private static void reset() { - Operators.OPERATORS.clear(); - Headers.HEADERS.clear(); - VariablePrefixes.RPEFIXES.clear(); - VariableSuffixes.SUFFIXES.clear(); - Commands.COMMANDS.clear(); - } - - public static synchronized void parse(String scriptSyntax) { - reset(); - - JsonObject jsonObject = JsonParser.parseString(scriptSyntax).getAsJsonObject(); - for (String key : jsonObject.keySet()) { - JsonArray jsonElements = jsonObject.get(key).getAsJsonArray(); - if (key.startsWith("@")) { - parseSpecial(key, jsonElements); - } else { - parseCommand(key, jsonElements); - } - } - } - - private static void parseCommand(String key, JsonArray value) { - boolean repeating = value.get(0).getAsBoolean(); - List> validArgumentTypes = new ArrayList<>(); - for (int i = 1; i < value.size(); i++) { - JsonArray parameters = value.get(i).getAsJsonArray(); - List parameterTypes = new ArrayList<>(); - for (JsonElement parameter : parameters) { - parameterTypes.add(TOKEN_TYPES[parameter.getAsInt()]); - } - validArgumentTypes.add(parameterTypes); - } - Commands.COMMANDS.put(key, new Command(repeating, validArgumentTypes)); - } - - private static void parseSpecial(String key, JsonArray value) { - Set set; - switch (key) { - case "@operators": - set = Operators.OPERATORS; - break; - case "@headers": - set = Headers.HEADERS; - break; - case "@prefixes": - set = VariablePrefixes.RPEFIXES; - break; - case "@suffixes": - set = VariableSuffixes.SUFFIXES; - break; - default: - return; - } - for (JsonElement element : value) { - set.add(element.getAsString()); - } - } -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/Token.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/Token.java index 6e7d022..98c8f95 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/Token.java +++ b/src/main/java/de/zonlykroks/advancedscripts/lexer/Token.java @@ -10,4 +10,12 @@ public class Token { this.text = text; this.color = color; } + + @Override + public String toString() { + return "Token{" + + "text='" + text + '\'' + + ", color=" + color + + '}'; + } } diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenType.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenType.java deleted file mode 100644 index 075646c..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenType.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -public enum TokenType { // This is copied from the BauSystem2.0 sources. - any, // This does not include jump_point and variable - expression, - jump_point, - variable, - - text_type, - number_type, - floating_number_type, - boolean_type, -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java index 71a5643..44dda6e 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java +++ b/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java @@ -1,5 +1,7 @@ package de.zonlykroks.advancedscripts.lexer; +import java.awt.*; + public class TokenTypeColors { private TokenTypeColors() { @@ -13,11 +15,10 @@ public class TokenTypeColors { public static final int ERROR = 0xFFAA0000; public static final int VARIABLE = 0xFFFFFFFF; - public static final int LITERAL = 0xFF925F35; public static final int COMMENT = 0xFF656565; - public static final int JUMP_POINT = 0xFFFFa500; + public static final int CONSTANT = Color.HSBtoRGB(219, 0.54f, 0.51f); public static final int NUMBER = 0xFF61839F; public static final int BOOLEAN = 0xFF925F35; - public static final int TEXT = 0xFF6F855D; + public static final int STRING = Color.HSBtoRGB(150, 0.63f, 0.3f); } diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/VariablePrefixes.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/VariablePrefixes.java deleted file mode 100644 index 631fd15..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/VariablePrefixes.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -import java.util.HashSet; -import java.util.Set; - -public class VariablePrefixes { - - private VariablePrefixes() { - throw new IllegalStateException("Utility class"); - } - - public static final Set RPEFIXES = new HashSet<>(); -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/VariableSuffixes.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/VariableSuffixes.java deleted file mode 100644 index d4d67f1..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/VariableSuffixes.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -import java.util.HashSet; -import java.util.Set; - -public class VariableSuffixes { - - private VariableSuffixes() { - throw new IllegalStateException("Utility class"); - } - - public static final Set SUFFIXES = new HashSet<>(); -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/de/zonlykroks/advancedscripts/mixin/ClientPlayNetworkHandlerMixin.java deleted file mode 100644 index 3b9c457..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/mixin/ClientPlayNetworkHandlerMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package de.zonlykroks.advancedscripts.mixin; - -import de.zonlykroks.advancedscripts.lexer.ScriptSyntaxPacketParser; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; -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; - -@Mixin(ClientPlayNetworkHandler.class) -public class ClientPlayNetworkHandlerMixin { - - private static final Identifier CHANNEL = new Identifier("sw:script_syntax"); - - @Inject(method = "onCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/CustomPayloadS2CPacket;getData()Lnet/minecraft/network/PacketByteBuf;"), cancellable = true) - public void onCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) { - if (CHANNEL.equals(packet.getChannel())) { - PacketByteBuf buf = packet.getData(); - int readableBytes = buf.readableBytes(); - StringBuilder st = new StringBuilder(); - for (int i = 0; i < readableBytes; i++) { - st.append((char) buf.readByte()); - } - ScriptSyntaxPacketParser.parse(st.toString()); - ci.cancel(); - } - } -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java index b4daf11..a91d1d9 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java +++ b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java @@ -6,6 +6,8 @@ import de.zonlykroks.advancedscripts.lexer.Token; import de.zonlykroks.advancedscripts.lexer.TokenTypeColors; import net.minecraft.client.font.TextHandler; import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.BookEditScreen; import net.minecraft.client.gui.screen.ingame.BookScreen; @@ -25,7 +27,12 @@ import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.Hand; import org.apache.commons.lang3.mutable.MutableInt; +import org.jetbrains.annotations.Nullable; +import org.luaj.vm2.ast.Chunk; +import org.luaj.vm2.parser.LuaParser; +import org.luaj.vm2.parser.ParseException; +import java.io.StringReader; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -137,6 +144,7 @@ public class ScriptEditScreen extends Screen { @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + setFocused(null); this.renderBackground(matrices); RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); @@ -169,11 +177,11 @@ public class ScriptEditScreen extends Screen { if (lineTooLong(s)) { fill(matrices, 25 + lineNumberLength + 2, 25 + lineNumber.getValue() * 9, 25 + lineNumberLength + 3, 25 + lineNumber.getValue() * 9 + height, TokenTypeColors.ERROR); } - this.textRenderer.draw(matrices, lineNumberText + "", 25 + lineNumberLength - textRenderer.getWidth(lineNumberText + ""), 25 + lineNumber.getValue() * 9, 0xFFFFFF); + this.textRenderer.draw(matrices, String.valueOf(lineNumberText), 25f + lineNumberLength - textRenderer.getWidth(String.valueOf(lineNumberText)), 25f + lineNumber.getValue() * 9f, 0xFFFFFF); lineNumberText++; // Line text - List tokens = ScriptColorizer.colorize(lineNumber.getValue(), s); + List tokens = ScriptColorizer.colorize(s); AtomicInteger x = new AtomicInteger(25 + lineNumberLength + 5); AtomicInteger currentXIndex = new AtomicInteger(0); for (Token token : tokens) { @@ -252,6 +260,7 @@ public class ScriptEditScreen extends Screen { } private void key(int keyCode) { + setFocused(null); if (Screen.isSelectAll(keyCode)) { this.cursorX = 0; this.cursorY = 0; @@ -282,46 +291,49 @@ public class ScriptEditScreen extends Screen { int previousCursorX = cursorX; int previousCursorY = cursorY; switch (keyCode) { - case 257: - case 335: + case 258 -> { + insert(" "); + return; + } + case 257, 335 -> { selection(true); newLine(); valid = false; - break; - case 259: + } + case 259 -> { if (selection(true) == null) backspace(selectionType); valid = false; - break; - case 261: + } + case 261 -> { if (selection(true) == null) delete(selectionType); valid = false; - break; - case 262: + } + case 262 -> { moveCursor(1, selectionType); valid = Screen.hasShiftDown(); - break; - case 263: + } + case 263 -> { moveCursor(-1, selectionType); valid = Screen.hasShiftDown(); - break; - case 264: + } + case 264 -> { moveDown(); valid = Screen.hasShiftDown(); - break; - case 265: + } + case 265 -> { moveUp(); valid = Screen.hasShiftDown(); - break; - case 268: + } + case 268 -> { cursorX = 0; valid = Screen.hasShiftDown(); - break; - case 269: + } + case 269 -> { cursorX = lines.get(cursorY).length(); valid = Screen.hasShiftDown(); - break; - default: - break; + } + default -> { + } } if (valid) { if (Screen.hasShiftDown() && savedCursorX == -1 && savedCursorY == -1) { @@ -337,6 +349,7 @@ public class ScriptEditScreen extends Screen { @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + setFocused(null); if (super.keyPressed(keyCode, scanCode, modifiers)) { return true; } @@ -348,17 +361,19 @@ public class ScriptEditScreen extends Screen { @Override public boolean keyReleased(int keyCode, int scanCode, int modifiers) { + setFocused(null); this.keyCode = -1; return super.keyReleased(keyCode, scanCode, modifiers); } @Override public boolean charTyped(char chr, int modifiers) { + setFocused(null); if (super.charTyped(chr, modifiers)) { return true; } selection(true); - boolean valid = insert(chr + ""); + boolean valid = insert(String.valueOf(chr)); savedCursorY = -1; savedCursorX = -1; autoScroll(); diff --git a/src/main/resources/advancedscripts.mixins.json b/src/main/resources/advancedscripts.mixins.json index 4f89400..b1b182d 100644 --- a/src/main/resources/advancedscripts.mixins.json +++ b/src/main/resources/advancedscripts.mixins.json @@ -7,8 +7,7 @@ ], "client": [ "KeyboardMixin", - "ClientPlayerEntityMixin", - "ClientPlayNetworkHandlerMixin" + "ClientPlayerEntityMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 025699f..a06c0ee 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -6,7 +6,8 @@ "name": "Advanced Scripts", "description": "An addition to the Steamwar script system!", "authors": [ - "zOnlyKroks" + "zOnlyKroks", + "Chaoscaot" ], "license": "AGPL-3.0", "environment": "client", -- 2.39.5 From 28856d8bd5e2fbc563305d9df83899d834fbc7bf Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 6 Jun 2023 22:46:45 +0200 Subject: [PATCH 2/7] Remove Debug --- .../de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java index 77e57d9..d9e57c7 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java +++ b/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java @@ -33,8 +33,6 @@ public class ScriptColorizer { boolean inString = false; boolean doubleQuoteString = false; - System.out.println('"' + line + '"'); - for (char c : line.toCharArray()) { switch (c) { case '"' -> { @@ -93,8 +91,6 @@ public class ScriptColorizer { tokens.add(toToken(currentToken.toString())); } - System.out.println(tokens); - return tokens; } -- 2.39.5 From e5df33c19adb7c62331847376bcc8eb12df795f6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 6 Jun 2023 23:02:58 +0200 Subject: [PATCH 3/7] Adjust Color --- .../de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java | 2 +- .../de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java | 2 +- .../zonlykroks/advancedscripts/screen/ScriptEditScreen.java | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java index d9e57c7..a224f8b 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java +++ b/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java @@ -11,7 +11,7 @@ public class ScriptColorizer { ); private ScriptColorizer() { - throw new IllegalStateException("Utility class"); + throw new IllegalStateException("Utility class██"); } public static List colorize(String line) { diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java index 44dda6e..6cede38 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java +++ b/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java @@ -20,5 +20,5 @@ public class TokenTypeColors { public static final int NUMBER = 0xFF61839F; public static final int BOOLEAN = 0xFF925F35; - public static final int STRING = Color.HSBtoRGB(150, 0.63f, 0.3f); + public static final int STRING = 0x6a8759; } diff --git a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java index a91d1d9..98bb5e0 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java +++ b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java @@ -27,12 +27,7 @@ import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.Hand; import org.apache.commons.lang3.mutable.MutableInt; -import org.jetbrains.annotations.Nullable; -import org.luaj.vm2.ast.Chunk; -import org.luaj.vm2.parser.LuaParser; -import org.luaj.vm2.parser.ParseException; -import java.io.StringReader; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -- 2.39.5 From 743ec5d565913096957f25568df00206f0e9c014 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 6 Jun 2023 23:12:21 +0200 Subject: [PATCH 4/7] Fixes --- .../zonlykroks/advancedscripts/screen/ScriptEditScreen.java | 6 +++++- steamwarci.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java index 98bb5e0..044b8ff 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java +++ b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java @@ -77,7 +77,10 @@ public class ScriptEditScreen extends Screen { @Override protected void init() { this.addDrawableChild( - new Button(DONE, this.width / 2 - 98 / 2, height - 55, () -> { + new Button(CANCEL, this.width / 2 - 100, height - 55, () -> this.client.setScreen(null)) + ); + this.addDrawableChild( + new Button(DONE, this.width / 2 + 2, height - 55, () -> { this.client.setScreen(null); finalizeBook(); }) @@ -91,6 +94,7 @@ public class ScriptEditScreen extends Screen { } public static final Text DONE = Text.translatable("gui.done"); + public static final Text CANCEL = Text.translatable("gui.cancel"); public static final Text BOOK = Text.translatable("item.minecraft.book"); private static class Button extends PressableWidget { diff --git a/steamwarci.yml b/steamwarci.yml index ddd1f90..2498190 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -2,4 +2,4 @@ build: - "./gradlew remapJar" artifacts: - "/binarys/AdvancedScripts.jar": "build/libs/AdvancedScripts-1.0.0.jar" \ No newline at end of file + "/binarys/AdvancedScripts.jar": "build/libs/AdvancedScripts-2.0.0.jar" \ No newline at end of file -- 2.39.5 From a9d3fa0bbb4517a62252f7367f6b5fdd8dfe9eed Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 6 Jun 2023 23:24:38 +0200 Subject: [PATCH 5/7] Add Icon --- src/main/resources/advanced-scripts-icon.png | Bin 0 -> 4779 bytes src/main/resources/fabric.mod.json | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/advanced-scripts-icon.png diff --git a/src/main/resources/advanced-scripts-icon.png b/src/main/resources/advanced-scripts-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ca9bdfd543d4fb7918939605de4d769a65c51bf0 GIT binary patch literal 4779 zcmeHKdsGuw8V_=oCoYZ^#S;Q4&McNDM59MP-sq!W8l#8A!l_$G70F z@=&RY;#$$Ffa0S-t0IR`>T9X4h_6ZuzE(ur`oIM#dnX{`*`D3wIotn8GRd9qe&6qY z-|zd~dosE51rk?hFJ}sc;wp_2DZsCuyhb~L?{7Yy-V1)}vtkz!3e*A_O$H5~ia|uC z5rZ%*uAxw@H+Aw`t_`fwueEubk{r{LXjk?tLLRIi0mB=5k9$E7c_MvGX@+lumU7hSJhV|sL< zc>J6_;R~C+{rCBcCW~Ya#}mbv@W|0iuG2pn`<1G8Q{S_teOa3u`={A<1$cIgXpZub zQJm<-R+?|~<(-#gF&D@E@^pd6PYyY!6IL8reda!e;;NE^aPi+|>Os&upl&>bv^6)Z=>(x<`9RVr2(Doz`*eeCEdEag|lqg#U6` z4QFH9J5S8XKTF>R&04d{Yp&ntd464p|0D%5wfm=Wp*gvU&b4!s?kgO|E#+^^KS za9y2XZyz{{!_Q2%;92A;Zj3NflpG>l$siS z%K53rTF0@%KOXZBEiB!Z-|YBQ`&^a)5iZXwYO_;zbv$>7iaAmka<+aNYw4cH>6q-f{`BiQI)tl*^mx9EB{N21$#_(j35&^E5Ua{cQNe2Z%y8#0D*^y?7=c1oU8>%U zScP;uE&|4+nMsH2E<}ouzDOpAA`K=C;sx=7SPZch&*0F*ouM$3T7xJ=a|R*6osgbP z5JrT_v{)=b7H*Kiq-C;U7-q6KOb&+uJQ(IoJ%L&odb1A+F@Pb$%qkOZByfWsA~8{= zA)OG?>0lmulb_BglMTV^&4VleKA2Y2$Yckxm^vMEc!Ze{X8@4Fgnl!^91AunQ-PTc z=_VB>&cO79&u|E}YAD{AZc4S6qgFAoR7?k4&0tmbJ4;HWGWk#hNr4vE8SPPk>~}l~ zT=SN!cXA_V?Bxtk1cVRazT^F-cDpn1lF1N}L6uIXClv|lHaA3o zGPoK6i@`%xe1-t#Y8a@J!{)2mJSA6v4TF;E%>=4fVI&j)55fTshljzKnj6gEhiEtq zo&aStPyt`SV6ov47B2+mvo+jd5YZ+as1i*bo)rnD22ea$qf~2H0){}q5iocv4a|Tw zA#4Vpqk-8xwK4?eY3xvH6*9+Q(xIT8xDM4~Oru_FpCAcGX33>OIwy$r)*??u2@MDk z(&yv)bnDxRSX_t25GcteJ6I6R5(M)EK%X2ApZ(S;4l|j75=l%pD~QXp&ya0FKrw(= zl+-Bzu-ic`NTdlv34Q12Y@p>)xEZXUX*Uh*s2D75;BMeH6}N9C2(oVq1XT@`U`8`A zwLMROH87=0M)g_@oF0R6ePhReLkd_h8p2lcV1_C<7-R4>V23MVpbVf8K99pybJ&6b zDGZ^T4I09Nny^_~z$4%a$kWahi^~gJ#0}WM;RVh@=Fnj{$Qj7@_k0cZ;`dwvf<_j3FMdbp8lmgG7?SzkQs-^x$8R1w1STHa)2a4_Z#jc@hz&pM38*eV_&>p)mt_sCi4m8-JWqpG z+D8AWe(Km3;a4Kb7gsAsE!#T#Xi-gCz%96YvyEM8*xhEHd%f<|nZC#J52-N`v<;4F zwv~eM5^?}-5{##|lLI%KJGDK6Mh;dAz`)Dh^7Yb;>dv+P?!YrLU`dMi!`Cp+Wx|!EHcy4?wnSmvlr;IDCs5muZq2^k+WnxkG`i{dhQlE4@cf%`pO-(PNf!I| z)*QT-=Eu1fe(ebnMm^%+=Y$_RL@T0&7H1{egnqu0#;9Nxp)W@&rj-U)Z+4MAzj}9E zb8EgNq(3`xej$z8{@u|UIsbaQN3q6~xMF6og*l_$naNvR6xR~&mgfO#G{tW{_;jc2 zWSdt*-HpGTE-prvt(Q>8hpu~YF}fJZN7b(Gcz;<1d&Ux}W#Pv1bRUbq#NzVcOR_?Xp&v}_}ZakZFpsQ_r9YszMp1n3>LXRNC~PmW>mLC?bQGz0fv9qJ(yD(0x_tE} literal 0 HcmV?d00001 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a06c0ee..e1004dd 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -9,6 +9,7 @@ "zOnlyKroks", "Chaoscaot" ], + "icon": "advanced-scripts-icon.png", "license": "AGPL-3.0", "environment": "client", "entrypoints": { @@ -21,7 +22,7 @@ ], "depends": { "fabricloader": ">=0.14.11", - "minecraft": ">=1.19.2", + "minecraft": ">=1.19.3", "java": ">=17" }, "accessWidener" : "advancedscripts.accesswidener" -- 2.39.5 From 2d1c320792e91f159feeb27132778d8e02c73607 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 10 Jun 2023 16:37:14 +0200 Subject: [PATCH 6/7] Remove AWT --- .../de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java index 6cede38..00738fe 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java +++ b/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java @@ -1,7 +1,5 @@ package de.zonlykroks.advancedscripts.lexer; -import java.awt.*; - public class TokenTypeColors { private TokenTypeColors() { @@ -16,7 +14,7 @@ public class TokenTypeColors { public static final int VARIABLE = 0xFFFFFFFF; public static final int COMMENT = 0xFF656565; - public static final int CONSTANT = Color.HSBtoRGB(219, 0.54f, 0.51f); + public static final int CONSTANT = 0x3F6EC6; public static final int NUMBER = 0xFF61839F; public static final int BOOLEAN = 0xFF925F35; -- 2.39.5 From 279042b987ad265f98a468d9de958d989a210c9f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 17 Jul 2023 15:55:06 +0200 Subject: [PATCH 7/7] Add Copyright & Rename Package --- .../advancedscripts/AdvancedScripts.java | 29 +++++++++++++ .../lexer/ScriptColorizer.java | 21 +++++++++- .../steamwar/advancedscripts/lexer/Token.java | 40 ++++++++++++++++++ .../lexer/TokenTypeColors.java | 41 +++++++++++++++++++ .../mixin/ClientPlayerEntityMixin.java | 23 ++++++++++- .../advancedscripts/mixin/KeyboardMixin.java | 33 ++++++++------- .../screen/ScriptEditScreen.java | 29 ++++++++++--- .../advancedscripts/AdvancedScripts.java | 26 ------------ .../advancedscripts/lexer/Token.java | 21 ---------- .../lexer/TokenTypeColors.java | 22 ---------- .../resources/advancedscripts.mixins.json | 2 +- src/main/resources/fabric.mod.json | 2 +- 12 files changed, 194 insertions(+), 95 deletions(-) create mode 100644 src/main/java/de/steamwar/advancedscripts/AdvancedScripts.java rename src/main/java/de/{zonlykroks => steamwar}/advancedscripts/lexer/ScriptColorizer.java (83%) create mode 100644 src/main/java/de/steamwar/advancedscripts/lexer/Token.java create mode 100644 src/main/java/de/steamwar/advancedscripts/lexer/TokenTypeColors.java rename src/main/java/de/{zonlykroks => steamwar}/advancedscripts/mixin/ClientPlayerEntityMixin.java (51%) rename src/main/java/de/{zonlykroks => steamwar}/advancedscripts/mixin/KeyboardMixin.java (61%) rename src/main/java/de/{zonlykroks => steamwar}/advancedscripts/screen/ScriptEditScreen.java (95%) delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/AdvancedScripts.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/Token.java delete mode 100644 src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java diff --git a/src/main/java/de/steamwar/advancedscripts/AdvancedScripts.java b/src/main/java/de/steamwar/advancedscripts/AdvancedScripts.java new file mode 100644 index 0000000..240e73d --- /dev/null +++ b/src/main/java/de/steamwar/advancedscripts/AdvancedScripts.java @@ -0,0 +1,29 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.advancedscripts; + +import net.fabricmc.api.ClientModInitializer; + +public class AdvancedScripts implements ClientModInitializer { + + @Override + public void onInitializeClient() { + } +} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java b/src/main/java/de/steamwar/advancedscripts/lexer/ScriptColorizer.java similarity index 83% rename from src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java rename to src/main/java/de/steamwar/advancedscripts/lexer/ScriptColorizer.java index a224f8b..dc78d4d 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/ScriptColorizer.java +++ b/src/main/java/de/steamwar/advancedscripts/lexer/ScriptColorizer.java @@ -1,4 +1,23 @@ -package de.zonlykroks.advancedscripts.lexer; +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.advancedscripts.lexer; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/de/steamwar/advancedscripts/lexer/Token.java b/src/main/java/de/steamwar/advancedscripts/lexer/Token.java new file mode 100644 index 0000000..58f764c --- /dev/null +++ b/src/main/java/de/steamwar/advancedscripts/lexer/Token.java @@ -0,0 +1,40 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.advancedscripts.lexer; + +public class Token { + public static final Token SPACE = new Token(" ", 0xFFFFFFFF); + + public final String text; + public final int color; + + public Token(String text, int color) { + this.text = text; + this.color = color; + } + + @Override + public String toString() { + return "Token{" + + "text='" + text + '\'' + + ", color=" + color + + '}'; + } +} diff --git a/src/main/java/de/steamwar/advancedscripts/lexer/TokenTypeColors.java b/src/main/java/de/steamwar/advancedscripts/lexer/TokenTypeColors.java new file mode 100644 index 0000000..6510fb0 --- /dev/null +++ b/src/main/java/de/steamwar/advancedscripts/lexer/TokenTypeColors.java @@ -0,0 +1,41 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.advancedscripts.lexer; + +public class TokenTypeColors { + + private TokenTypeColors() { + throw new IllegalStateException("Utility class"); + } + + public static final int BACKGROUND = 0xFF1E1F22; + public static final int SELECTION = 0xFF23437F; + public static final int OTHER = 0xFFFFFFFF; + + public static final int ERROR = 0xFFAA0000; + + public static final int VARIABLE = 0xFFFFFFFF; + public static final int COMMENT = 0xFF656565; + public static final int CONSTANT = 0x3F6EC6; + + public static final int NUMBER = 0xFF61839F; + public static final int BOOLEAN = 0xFF925F35; + public static final int STRING = 0x6a8759; +} diff --git a/src/main/java/de/zonlykroks/advancedscripts/mixin/ClientPlayerEntityMixin.java b/src/main/java/de/steamwar/advancedscripts/mixin/ClientPlayerEntityMixin.java similarity index 51% rename from src/main/java/de/zonlykroks/advancedscripts/mixin/ClientPlayerEntityMixin.java rename to src/main/java/de/steamwar/advancedscripts/mixin/ClientPlayerEntityMixin.java index 4c00782..11b0a25 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/mixin/ClientPlayerEntityMixin.java +++ b/src/main/java/de/steamwar/advancedscripts/mixin/ClientPlayerEntityMixin.java @@ -1,6 +1,25 @@ -package de.zonlykroks.advancedscripts.mixin; +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ -import de.zonlykroks.advancedscripts.screen.ScriptEditScreen; +package de.steamwar.advancedscripts.mixin; + +import de.steamwar.advancedscripts.screen.ScriptEditScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.item.ItemStack; diff --git a/src/main/java/de/zonlykroks/advancedscripts/mixin/KeyboardMixin.java b/src/main/java/de/steamwar/advancedscripts/mixin/KeyboardMixin.java similarity index 61% rename from src/main/java/de/zonlykroks/advancedscripts/mixin/KeyboardMixin.java rename to src/main/java/de/steamwar/advancedscripts/mixin/KeyboardMixin.java index acdec70..5d0d666 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/mixin/KeyboardMixin.java +++ b/src/main/java/de/steamwar/advancedscripts/mixin/KeyboardMixin.java @@ -1,20 +1,23 @@ /* - This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ - Copyright (C) 2020 SteamWar.de-Serverteam - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.zonlykroks.advancedscripts.mixin; +package de.steamwar.advancedscripts.mixin; import io.netty.buffer.Unpooled; import net.minecraft.client.Keyboard; diff --git a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java b/src/main/java/de/steamwar/advancedscripts/screen/ScriptEditScreen.java similarity index 95% rename from src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java rename to src/main/java/de/steamwar/advancedscripts/screen/ScriptEditScreen.java index 044b8ff..07afe06 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java +++ b/src/main/java/de/steamwar/advancedscripts/screen/ScriptEditScreen.java @@ -1,13 +1,30 @@ -package de.zonlykroks.advancedscripts.screen; +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.advancedscripts.screen; import com.mojang.blaze3d.systems.RenderSystem; -import de.zonlykroks.advancedscripts.lexer.ScriptColorizer; -import de.zonlykroks.advancedscripts.lexer.Token; -import de.zonlykroks.advancedscripts.lexer.TokenTypeColors; +import de.steamwar.advancedscripts.lexer.TokenTypeColors; +import de.steamwar.advancedscripts.lexer.ScriptColorizer; +import de.steamwar.advancedscripts.lexer.Token; import net.minecraft.client.font.TextHandler; import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.Selectable; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.BookEditScreen; import net.minecraft.client.gui.screen.ingame.BookScreen; diff --git a/src/main/java/de/zonlykroks/advancedscripts/AdvancedScripts.java b/src/main/java/de/zonlykroks/advancedscripts/AdvancedScripts.java deleted file mode 100644 index 6882751..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/AdvancedScripts.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.zonlykroks.advancedscripts; - -import net.fabricmc.api.ClientModInitializer; - -public class AdvancedScripts implements ClientModInitializer { - - @Override - public void onInitializeClient() { - } -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/Token.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/Token.java deleted file mode 100644 index 98c8f95..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/Token.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -public class Token { - public static final Token SPACE = new Token(" ", 0xFFFFFFFF); - - public final String text; - public final int color; - - public Token(String text, int color) { - this.text = text; - this.color = color; - } - - @Override - public String toString() { - return "Token{" + - "text='" + text + '\'' + - ", color=" + color + - '}'; - } -} diff --git a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java b/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java deleted file mode 100644 index 00738fe..0000000 --- a/src/main/java/de/zonlykroks/advancedscripts/lexer/TokenTypeColors.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.zonlykroks.advancedscripts.lexer; - -public class TokenTypeColors { - - private TokenTypeColors() { - throw new IllegalStateException("Utility class"); - } - - public static final int BACKGROUND = 0xFF1E1F22; - public static final int SELECTION = 0xFF23437F; - public static final int OTHER = 0xFFFFFFFF; - - public static final int ERROR = 0xFFAA0000; - - public static final int VARIABLE = 0xFFFFFFFF; - public static final int COMMENT = 0xFF656565; - public static final int CONSTANT = 0x3F6EC6; - - public static final int NUMBER = 0xFF61839F; - public static final int BOOLEAN = 0xFF925F35; - public static final int STRING = 0x6a8759; -} diff --git a/src/main/resources/advancedscripts.mixins.json b/src/main/resources/advancedscripts.mixins.json index b1b182d..a455d4c 100644 --- a/src/main/resources/advancedscripts.mixins.json +++ b/src/main/resources/advancedscripts.mixins.json @@ -1,7 +1,7 @@ { "required": true, "minVersion": "0.8", - "package": "de.zonlykroks.advancedscripts.mixin", + "package": "de.steamwar.advancedscripts.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ ], diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e1004dd..097be61 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -14,7 +14,7 @@ "environment": "client", "entrypoints": { "client": [ - "de.zonlykroks.advancedscripts.AdvancedScripts" + "de.steamwar.advancedscripts.AdvancedScripts" ] }, "mixins": [ -- 2.39.5