Skip to content

Commit 9ee769d

Browse files
committed
reduce replay size when using the ToggleModule
1 parent 3934d0c commit 9ee769d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

engine/modules/toggle/src/main/java/com/codingame/gameengine/module/toggle/ToggleModule.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
/**
1515
* @author Jean Porée
16-
*
16+
*
1717
* This module allows you to display or hide elements of the GraphicEntityModule using the viewer's options menu.
18-
*
18+
*
1919
*/
2020
@Singleton
2121
public class ToggleModule implements Module {
@@ -70,14 +70,19 @@ public void onAfterGameTurn() {
7070
public void onAfterOnEnd() {}
7171

7272
private void sendFrameData() {
73-
Object[] data = { newRegistration };
73+
HashMap<String, String> data = new HashMap<>();
74+
for (int d : newRegistration.keySet()) {
75+
String key = newRegistration.get(d).name;
76+
if (!data.containsKey(key)) data.put(key, "");
77+
data.put(key, data.get(key) + d + (newRegistration.get(d).state ? "+" : "-"));
78+
}
7479
gameManager.setViewData("toggles", data);
7580

7681
newRegistration.clear();
7782
}
7883
/**
7984
* Will display the entity only when the toggle state matches the state you set
80-
*
85+
*
8186
* @param entity which will be displayed
8287
* @param toggle the name of the toggle you want to use
8388
* @param state the state of the toggle where the entity will be displayed at
@@ -90,4 +95,4 @@ public void displayOnToggleState(Entity<?> entity, String toggle, boolean state)
9095
registered.put(id, associatedToggle);
9196
}
9297
}
93-
}
98+
}

engine/modules/toggle/src/main/resources/view/toggle-module/ToggleModule.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ export class ToggleModule {
5858
if (!data) {
5959
return
6060
}
61-
const newRegistration = data[0]
61+
var newRegistration = {}
62+
Object.entries(data).forEach(([key, value]) => {
63+
value.match(/\d+./g).forEach(m => {
64+
var entityId = m.slice(0, -1)
65+
var state = m.slice(-1) === "+"
66+
newRegistration[entityId] = {"name":key, "state":state}
67+
})
68+
})
6269
const registered = { ...this.previousFrame.registered, ...newRegistration }
6370
const frame = { registered, number: frameInfo.number }
6471
this.previousFrame = frame

0 commit comments

Comments
 (0)