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
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

/**
* @author Jean Porée
*
*
* This module allows you to display or hide elements of the GraphicEntityModule using the viewer's options menu.
*
*
*/
@Singleton
public class ToggleModule implements Module {
Expand Down Expand Up @@ -70,14 +70,20 @@ public void onAfterGameTurn() {
public void onAfterOnEnd() {}

private void sendFrameData() {
Object[] data = { newRegistration };
gameManager.setViewData("toggles", data);
HashMap<String, String> data = new HashMap<>();
for (int d : newRegistration.keySet()) {
String key = newRegistration.get(d).name;
if (!data.containsKey(key)) data.put(key, "");
data.put(key, data.get(key) + d + (newRegistration.get(d).state ? "+" : "-"));
}
if (newRegistration.size() > 0)
gameManager.setViewData("toggles", data);

newRegistration.clear();
}
/**
* Will display the entity only when the toggle state matches the state you set
*
*
* @param entity which will be displayed
* @param toggle the name of the toggle you want to use
* @param state the state of the toggle where the entity will be displayed at
Expand All @@ -90,4 +96,4 @@ public void displayOnToggleState(Entity<?> entity, String toggle, boolean state)
registered.put(id, associatedToggle);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ export class ToggleModule {
}

handleFrameData (frameInfo, data) {
if (!data) {
return
var newRegistration = {}
if (data) {
Object.entries(data).forEach(([key, value]) => {
value.match(/\d+./g).forEach(m => {
var entityId = m.slice(0, -1)
var state = m.slice(-1) === "+"
newRegistration[entityId] = {"name":key, "state":state}
})
})
}
const newRegistration = data[0]
const registered = { ...this.previousFrame.registered, ...newRegistration }
const frame = { registered, number: frameInfo.number }
this.previousFrame = frame
Expand Down