Skip to content

Commit 2b70fb5

Browse files
authored
Update trace following and resource bar touches other resource bars. (Metta-AI#248)
### TL;DR Enhanced the trace visualization in the player with improved zoom, layout, and selection behavior. ### What changed? - Changed default zoom level from 1 to 1/2 for better visibility - Added inventory padding (16px) and defined trace constants - Implemented separate follow flags for map and trace selections - Added visualization for inactive actions in the trace with low opacity - Improved reward icon positioning in the trace view - Changed trace step indicator color from white to gray for better contrast - Fixed inventory item spacing calculation to account for padding - Improved selection behavior between map and trace panels - Updated the trace visualization image ### How to test? 1. Run the player and load a replay 2. Select an agent in the trace view and verify it's properly highlighted in the map 3. Check that the inventory items have proper padding and spacing 4. Verify that inactive actions appear with low opacity in the trace 5. Test that the follow behavior works correctly when selecting agents 6. Confirm that the reward icons are properly centered in the trace view ### Why make this change? These improvements enhance the usability and visual clarity of the trace visualization, making it easier to track agent actions and rewards over time. The separate follow flags provide better control when navigating between the map and trace views, while the adjusted zoom level and improved spacing make the interface more readable.
1 parent b8999a7 commit 2b70fb5

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed
-108 Bytes
Loading

deps/mettagrid/player/src/main.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class PanelInfo {
4141
-x,
4242
-y
4343
);
44-
this.zoomLevel = 1;
44+
this.zoomLevel = 1/2;
4545
}
4646

4747
// Update the pan and zoom level based on the mouse position and scroll delta.
@@ -93,6 +93,11 @@ const TILE_SIZE = 200;
9393
// Agent defaults.
9494
const DEFAULT_VISION_SIZE = 11;
9595

96+
// Trace constants.
97+
const INVENTORY_PADDING = 16;
98+
const TRACE_HEIGHT = 256
99+
const TRACE_WIDTH = 32
100+
96101
let drawer: Drawer;
97102

98103
// Flag to prevent multiple calls to requestAnimationFrame
@@ -137,6 +142,7 @@ let lastMousePos = new Vec2f(0, 0);
137142
let scrollDelta = 0;
138143
let lastClickTime = 0; // For double-click detection
139144
let followSelection = false; // Flag to follow selected entity
145+
let followTraceSelection = false; // Flag to follow trace selection
140146

141147
let traceSplit = DEFAULT_TRACE_SPLIT;
142148
let traceDragging = false;
@@ -221,6 +227,7 @@ function onMouseDown() {
221227
if (followSelection) {
222228
// Set the zoom level to 1 as requested when following
223229
mapPanel.zoomLevel = 1/2;
230+
followTraceSelection = true;
224231
}
225232
}
226233
}
@@ -478,6 +485,7 @@ function onKeyDown(event: KeyboardEvent) {
478485
if (event.key == "Escape") {
479486
selectedGridObject = null;
480487
followSelection = false; // Also stop following when selection is cleared
488+
followTraceSelection = false;
481489
}
482490
// '[' and ']' to scrub forward and backward.
483491
if (event.key == "[") {
@@ -837,14 +845,14 @@ function drawInventory(replay: any) {
837845
const y = getAttr(gridObject, "r")
838846

839847
// Sum up the objects inventory, in case we need to condense it.
840-
let inventoryX = 0;
848+
let inventoryX = INVENTORY_PADDING;
841849
let numItems = 0;
842850
for (const [key, [icon, color]] of replay.resource_inventory) {
843851
const num = getAttr(gridObject, key);
844852
numItems += num;
845853
}
846854
// Draw the actual inventory icons.
847-
let advanceX = Math.min(32, TILE_SIZE / numItems);
855+
let advanceX = Math.min(32, (TILE_SIZE - INVENTORY_PADDING*2) / numItems);
848856
for (const [key, [icon, color]] of replay.resource_inventory) {
849857
const num = getAttr(gridObject, key);
850858
for (let i = 0; i < num; i++) {
@@ -1004,12 +1012,9 @@ function drawTrace(panel: PanelInfo) {
10041012
return;
10051013
}
10061014

1007-
const TRACE_HEIGHT = 256
1008-
const TRACE_WIDTH = 32
1009-
10101015
const localMousePos = panel.transformPoint(mousePos);
10111016

1012-
if (followSelection && selectedGridObject !== null) {
1017+
if (followTraceSelection && selectedGridObject !== null) {
10131018
panel.focusPos(
10141019
step * TRACE_WIDTH + TRACE_WIDTH/2,
10151020
getAttr(selectedGridObject, "agent_id") * TRACE_HEIGHT + TRACE_HEIGHT/2
@@ -1026,7 +1031,7 @@ function drawTrace(panel: PanelInfo) {
10261031
followSelection = true;
10271032
selectedGridObject = replay.agents[agentId];
10281033
console.log("selectedGridObject on a trace: ", selectedGridObject);
1029-
panel.focusPos(
1034+
mapPanel.focusPos(
10301035
getAttr(selectedGridObject, "c") * TILE_SIZE,
10311036
getAttr(selectedGridObject, "r") * TILE_SIZE
10321037
);
@@ -1067,7 +1072,7 @@ function drawTrace(panel: PanelInfo) {
10671072
drawer.drawSolidRect(
10681073
step * TRACE_WIDTH, 0,
10691074
TRACE_WIDTH, fullSize.y(),
1070-
[1.0, 1.0, 1.0, 0.5] // White with 50% opacity
1075+
[0.5, 0.5, 0.5, 0.5] // White with 50% opacity
10711076
);
10721077

10731078
// Draw agent traces
@@ -1082,6 +1087,12 @@ function drawTrace(panel: PanelInfo) {
10821087
replay.action_images[action[0]],
10831088
j * TRACE_WIDTH + TRACE_WIDTH/2, i * TRACE_HEIGHT + TRACE_HEIGHT/2,
10841089
);
1090+
} else if (action != null) {
1091+
drawer.drawSprite(
1092+
replay.action_images[action[0]],
1093+
j * TRACE_WIDTH + TRACE_WIDTH/2, i * TRACE_HEIGHT + TRACE_HEIGHT/2,
1094+
[0.01, 0.01, 0.01, 0.01],
1095+
);
10851096
}
10861097

10871098
if (getAttr(agent, "agent:frozen", j) > 0) {
@@ -1096,7 +1107,7 @@ function drawTrace(panel: PanelInfo) {
10961107
if (reward > 0) {
10971108
drawer.drawSprite(
10981109
"resources/reward.png",
1099-
j * TRACE_WIDTH - 16,
1110+
j * TRACE_WIDTH + TRACE_WIDTH/2,
11001111
i * TRACE_HEIGHT + 256 - 32,
11011112
[1.0, 1.0, 1.0, 1.0],
11021113
1/8

0 commit comments

Comments
 (0)