Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ build/
/run/
/lib
/logs
TODO.md
169 changes: 111 additions & 58 deletions src/main/java/com/riprod/hexcode/builtin/glyphs/debug/DebugGlyph.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package com.riprod.hexcode.builtin.glyphs.debug;

import java.util.List;
import java.util.Map;

import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.modules.entitystats.EntityStatMap;
import com.hypixel.hytale.server.core.modules.entitystats.EntityStatValue;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.riprod.hexcode.api.execution.HexExecuter;
import com.riprod.hexcode.core.common.execution.component.HexContext;
import com.riprod.hexcode.core.common.execution.component.VolatilityTracker;
import com.riprod.hexcode.core.common.glyphs.component.Glyph;
import com.riprod.hexcode.core.common.glyphs.component.GlyphHandler;
import com.riprod.hexcode.core.common.glyphs.component.Slot;
import com.riprod.hexcode.core.common.glyphs.registry.GlyphRegistry;
import com.riprod.hexcode.core.common.glyphs.variables.HexVar;
import com.riprod.hexcode.core.common.stats.HexcodeEntityStatTypes;

public class DebugGlyph implements GlyphHandler {
private static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
public static final String ID = "Debug";

@Override
public String getId() {
return ID;
Expand Down Expand Up @@ -49,65 +48,119 @@ private void dump(Glyph glyph, HexContext hexContext) {
if (pr == null)
return;

StringBuilder sb = new StringBuilder();

float mana = hexContext.getHexRoot().getCurrentMana(hexContext.getAccessor());
float maxVol = hexContext.getVolatilityTracker().getStartingBudget();
float curVol = hexContext.getVolatilityTracker().getRemainingBudget();
sb.append(String.format("Mana: %.1f\n", mana));
sb.append(String.format("Volatility: %.1f / %.1f\n", curVol, maxVol));

var nextLinks = glyph.getNextLinks();
if (!nextLinks.isEmpty()) {
sb.append("Next:\n");
for (String nextId : nextLinks) {
Glyph next = hexContext.getGlyph(nextId);
if (next == null) {
sb.append(" - [missing ").append(shortId(nextId)).append("]\n");
continue;
}
sb.append(String.format(" - %s (vol %.2f, eff %.2f)\n",
next.getGlyphId(), next.getVolatility(), next.getEfficiency()));
}
}
String volatility = volatilityText(hexContext.getVolatilityTracker());
// complexity axis not yet wired; placeholder until the accrual seam lands
String complexity = "0";

Slot slot = glyph.getSlot(DebugGlyphSlots.SLOT);
boolean wired = slot != null && slot.getFirstLink() != null;

Message msg = wired
? markup(Message.translation("hexcode.debugGlyph.slots")
.param("volatility", volatility)
.param("complexity", complexity)
.param("slots", buildSlotLines(slot, hexContext)))
: markup(Message.translation("hexcode.debugGlyph.gis")
.param("volatility", volatility)
.param("complexity", complexity)
.param("gis", buildGisLines(hexContext)));

pr.sendMessage(msg);
LOGGER.atInfo().log(msg.getAnsiMessage());
}

private Message buildSlotLines(Slot slot, HexContext hexContext) {
Message composite = Message.raw("");
int index = 0;
for (String linkId : slot.getLinks()) {
Glyph linked = hexContext.getGlyph(linkId);
if (linked == null)
continue;

// multi-read: dump every wired slot input
List<HexVar> slotValues = glyph.readSlotAll(DebugGlyphSlots.SLOT, hexContext);
if (!slotValues.isEmpty()) {
if (slotValues.size() == 1) {
sb.append("Slot: ").append(slotValues.get(0).describe()).append("\n");
} else {
sb.append("Slot:\n");
for (int i = 0; i < slotValues.size(); i++) {
HexVar sv = slotValues.get(i);
sb.append(" [").append(i).append("] ").append(sv.describe()).append("\n");
}
}
HexVar value = resolveLink(linked, hexContext);

Message line = markup(Message.translation("hexcode.debugGlyph.slots.line")
.param("index", index)
.param("value", valueText(value))
.param("glyph", linked.getGlyphId())
.param("accuracy", String.format("%.2f", linked.getVolatility()))
.param("speed", String.format("%.2f", linked.getEfficiency()))
.param("metadata", typeLabel(value)));

if (index > 0)
composite.insert("\n");
composite.insert(line);
index++;
}
return composite;
}

private Message buildGisLines(HexContext hexContext) {
Message composite = Message.raw("");
HexVar defaultVar = hexContext.getDefaultVariable();
sb.append("Default: ").append(defaultVar != null ? defaultVar.describe() : "[none]").append("\n");

Map<String, HexVar> vars = hexContext.getVariables();
if (vars.isEmpty()) {
sb.append("Vars: [empty]");
} else {
sb.append("Vars:\n");
for (Map.Entry<String, HexVar> entry : vars.entrySet()) {
HexVar v = entry.getValue();
if (v == null)
continue;
sb.append(" ")
.append(entry.getKey())
.append(": ")
.append(v.describe())
.append("\n");
}
int index = 0;
for (Map.Entry<String, HexVar> entry : hexContext.getVariables().entrySet()) {
HexVar value = entry.getValue();
if (value == null)
continue;

Glyph source = hexContext.getGlyph(entry.getKey());
String glyph = source != null ? source.getGlyphId() : shortId(entry.getKey());

Message line = markup(Message.translation("hexcode.debugGlyph.slots.gis")
.param("index", entry.getKey())
.param("value", valueText(value))
.param("glyph", glyph)
.param("metadata", gisMetadata(value, defaultVar)));

if (index > 0)
composite.insert("\n");
composite.insert(line);
index++;
}
return composite;
}

private static HexVar resolveLink(Glyph linked, HexContext hexContext) {
GlyphHandler handler = GlyphRegistry.get(linked.getGlyphId());
if (handler == null || hexContext.isResolving(linked.getId()))
return null;
hexContext.pushResolving(linked.getId());
try {
return handler.readValue(linked, hexContext);
} finally {
hexContext.popResolving();
}
}

private static Message markup(Message message) {
message.getFormattedMessage().markupEnabled = true;
return message;
}

private static String volatilityText(VolatilityTracker tracker) {
if (tracker == null)
return "-";
return String.format("%.1f / %.1f", tracker.getRemainingBudget(), tracker.getStartingBudget());
}

private static String valueText(HexVar value) {
if (value == null)
return "[none]";
String described = value.describe();
int split = described.indexOf(": ");
return split >= 0 ? described.substring(split + 2) : described;
}

private static String typeLabel(HexVar value) {
if (value == null)
return "[none]";
return value.getClass().getSimpleName().replace("Var", "");
}

String msg = sb.toString();
pr.sendMessage(Message.raw(msg));
LOGGER.atInfo().log(msg);
private static String gisMetadata(HexVar value, HexVar defaultVar) {
String label = typeLabel(value);
return value == defaultVar ? label + " *" : label;
}

private static String shortId(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Vector3d forward() {
public String describe() {
if (rotation == null)
return "RotationVar: [null]";
return String.format("RotationVar: pitch=%.3f rad, yaw=%.3f rad, roll=%.3f rad",
return String.format("RotationVar: ( p=%.3f, y=%.3f, r=%.3f )",
rotation.x, rotation.y, rotation.z);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
slots.line=<color is="#cfcfcf">[{index}]:</color> <color is="#95eefa">{glyph}</color>=<b><color is="#e5c07b">{value}</color></b> - <i><color is="#c678dd">Acc: {accuracy} - Speed: {speed}</color> - <color is="#cfcfcf">{metadata}</color></i>
slots.gis=<color is="#cfcfcf">[{index}]:</color> <color is="#95eefa">{glyph}</color> <b><color is="#e5c07b">{value}</color></b> - <i><color is="#cfcfcf">{metadata}</color></i>
gis=Volatility: <color is="#f54150">{volatility}</color>\nComplexity: <color is="#95eefa">{complexity}</color>\n{gis}
slots=Volatility: <color is="#f54150">{volatility}</color>\nComplexity: <color is="#95eefa">{complexity}</color>\n{slots}
3 changes: 2 additions & 1 deletion src/main/resources/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"Description": "Magic By Design.",
"Authors": [
{
"Name": "Riprod"
"Name": "Riprod",
"Email": "Some Email"
}
],
"Website": "https://modtale.net/mod/hexcode",
Expand Down
Loading