mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 05:27:37 +00:00
Made TokenType priority internal
This commit is contained in:
1 parent
547989a6d4
commit
eae5a08932
3 files changed
+17
-46
No files matched your search
+9
-9
@@ -13,9 +13,12 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Manages reloadable style overrides (color, priority, bold, italic) for {@link TokenType},
|
||||
* Manages reloadable style overrides (color, bold, italic) for {@link TokenType},
|
||||
* plus editor background/gutter/scrollbar colors via {@link BackgroundStyleEntry}.
|
||||
* <p>
|
||||
* Priority is always determined internally by {@link TokenType#getPriority()} ()}
|
||||
* and is never exposed to or loaded from user-facing JSON files.
|
||||
* <p>
|
||||
* Loaded from {@code assets/customnpcs/colorscheme/script_editor_scheme.json} on resource reload.
|
||||
* Styles are cached in a flat array indexed by {@link TokenType#ordinal()} for zero-cost lookups.
|
||||
*/
|
||||
@@ -67,7 +70,7 @@ public final class ScriptColorScheme {
|
||||
for (TokenType tt : samples) {
|
||||
StyleEntry e = current[tt.ordinal()];
|
||||
LogWriter.info("[ColorScheme] " + tt.name() + " -> color=#" + String.format("%08X", e.hexColor)
|
||||
+ ", priority=" + e.priority + ", bold=" + e.bold + ", italic=" + e.italic);
|
||||
+ ", bold=" + e.bold + ", italic=" + e.italic);
|
||||
}
|
||||
|
||||
BackgroundStyleEntry bg = background;
|
||||
@@ -77,7 +80,7 @@ public final class ScriptColorScheme {
|
||||
|
||||
/**
|
||||
* Parse a color scheme JSON and install it as the active scheme.
|
||||
* Expected format: {@code { "TOKEN_NAME": { "color": "#RRGGBB", "priority": int, "bold": bool, "italic": bool }, ... }}
|
||||
* Expected format: {@code { "TOKEN_NAME": { "color": "#RRGGBB", "bold": bool, "italic": bool }, ... }}
|
||||
* Missing properties per token fall back to the enum default. Parse errors are logged per-token.
|
||||
*/
|
||||
public static void loadFromJson(Reader reader) {
|
||||
@@ -129,11 +132,10 @@ public final class ScriptColorScheme {
|
||||
int color = entry.has("color")
|
||||
? parseColor(entry.get("color"), defaultColor, tt.name())
|
||||
: defaultColor;
|
||||
int priority = entry.has("priority") ? entry.get("priority").getAsInt() : tt.getDefaultPriority();
|
||||
boolean bold = entry.has("bold") ? entry.get("bold").getAsBoolean() : tt.getDefaultBold();
|
||||
boolean italic = entry.has("italic") ? entry.get("italic").getAsBoolean() : tt.getDefaultItalic();
|
||||
|
||||
return new StyleEntry(color, priority, bold, italic);
|
||||
return new StyleEntry(color, bold, italic);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("[ColorScheme] Error parsing token " + tt.name() + ", using defaults: " + e.getMessage());
|
||||
return defaultEntry(tt);
|
||||
@@ -145,7 +147,7 @@ public final class ScriptColorScheme {
|
||||
if ((color & 0xFF000000) == 0) {
|
||||
color |= 0xFF000000;
|
||||
}
|
||||
return new StyleEntry(color, tt.getDefaultPriority(), tt.getDefaultBold(), tt.getDefaultItalic());
|
||||
return new StyleEntry(color, tt.getDefaultBold(), tt.getDefaultItalic());
|
||||
}
|
||||
|
||||
private static BackgroundStyleEntry parseBackground(JsonObject root) {
|
||||
@@ -212,13 +214,11 @@ public final class ScriptColorScheme {
|
||||
|
||||
static final class StyleEntry {
|
||||
final int hexColor;
|
||||
final int priority;
|
||||
final boolean bold;
|
||||
final boolean italic;
|
||||
|
||||
StyleEntry(int hexColor, int priority, boolean bold, boolean italic) {
|
||||
StyleEntry(int hexColor, boolean bold, boolean italic) {
|
||||
this.hexColor = hexColor;
|
||||
this.priority = priority;
|
||||
this.bold = bold;
|
||||
this.italic = italic;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ import noppes.npcs.client.gui.util.script.interpreter.type.TypeInfo;
|
||||
* Defines all token types for syntax highlighting with hex colors and priorities.
|
||||
* Priority determines which token type wins when marks overlap.
|
||||
* Higher priority = wins conflicts.
|
||||
*
|
||||
* Style properties (color, priority, bold, italic) can be overridden at runtime
|
||||
* <p>
|
||||
* Priority is defined exclusively by the enum and never stored elsewhere.
|
||||
* Visual style properties (color, bold, italic) can be overridden at runtime
|
||||
* via {@link ScriptColorScheme}. The enum constructor values serve as compile-time defaults.
|
||||
*/
|
||||
public enum TokenType {
|
||||
@@ -16,7 +17,7 @@ public enum TokenType {
|
||||
STRING(0xFFCC8855, 130),
|
||||
|
||||
// JSDoc elements - lower priority but will fill gaps left by fragmented comment marking
|
||||
JSDOC_TAG(0xFFCC9933, 125), // @param, @type, @return etc. (gold/orange)
|
||||
JSDOC_TAG(0xFFCC9933, 125,true, true), // @param, @type, @return etc. (gold/orange)
|
||||
JSDOC_TYPE(0xFF00AAAA, 124), // {TypeName} in JSDoc (aqua like types)
|
||||
|
||||
UNUSED_IMPORT(0xFF666666, 119), // unused import statements (gray)
|
||||
@@ -52,7 +53,7 @@ public enum TokenType {
|
||||
DEFAULT(0xFFFFFFFF, 0); // default text color (white)
|
||||
|
||||
private final int defaultHexColor;
|
||||
private final int defaultPriority;
|
||||
private final int priority;
|
||||
private final boolean defaultBold;
|
||||
private final boolean defaultItalic;
|
||||
|
||||
@@ -62,7 +63,7 @@ public enum TokenType {
|
||||
|
||||
TokenType(int hexColor, int priority, boolean bold, boolean italic) {
|
||||
this.defaultHexColor = hexColor;
|
||||
this.defaultPriority = priority;
|
||||
this.priority = priority;
|
||||
this.defaultBold = bold;
|
||||
this.defaultItalic = italic;
|
||||
}
|
||||
@@ -72,7 +73,7 @@ public enum TokenType {
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return ScriptColorScheme.styles[ordinal()].priority;
|
||||
return priority;
|
||||
}
|
||||
|
||||
public boolean isBold() {
|
||||
@@ -86,11 +87,7 @@ public enum TokenType {
|
||||
int getDefaultHexColor() {
|
||||
return defaultHexColor;
|
||||
}
|
||||
|
||||
int getDefaultPriority() {
|
||||
return defaultPriority;
|
||||
}
|
||||
|
||||
|
||||
boolean getDefaultBold() {
|
||||
return defaultBold;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user