Skip to content

Commit b5ab459

Browse files
committed
cleanup(sdk): ToggleModule: adhere to CodinGame's coding convetion
1 parent e79c16b commit b5ab459

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5+
import java.util.Map.Entry;
56

67
import com.codingame.gameengine.core.AbstractPlayer;
78
import com.codingame.gameengine.core.GameManager;
@@ -67,26 +68,32 @@ public void onAfterGameTurn() {
6768
}
6869

6970
@Override
70-
public void onAfterOnEnd() {}
71+
public void onAfterOnEnd() {
72+
}
7173

7274
private void sendFrameData() {
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 ? "+" : "-"));
75+
Map<String, String> data = new HashMap<>();
76+
for (Entry<Integer, Toggle> e : newRegistration.entrySet()) {
77+
String key = e.getValue().name;
78+
int id = e.getKey();
79+
data.put(key, data.getOrDefault(key, "") + id + (newRegistration.get(id).state ? "+" : "-"));
7880
}
79-
if (newRegistration.size() > 0)
81+
if (newRegistration.size() > 0) {
8082
gameManager.setViewData("toggles", data);
83+
}
8184

8285
newRegistration.clear();
8386
}
87+
8488
/**
8589
* Will display the entity only when the toggle state matches the state you set
8690
*
87-
* @param entity which will be displayed
88-
* @param toggle the name of the toggle you want to use
89-
* @param state the state of the toggle where the entity will be displayed at
91+
* @param entity
92+
* which will be displayed
93+
* @param toggle
94+
* the name of the toggle you want to use
95+
* @param state
96+
* the state of the toggle where the entity will be displayed at
9097
*/
9198
public void displayOnToggleState(Entity<?> entity, String toggle, boolean state) {
9299
int id = entity.getId();

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ export class ToggleModule {
5555
}
5656

5757
handleFrameData (frameInfo, data) {
58-
var newRegistration = {}
58+
const newRegistration = {}
5959
if (data) {
60-
Object.entries(data).forEach(([key, value]) => {
61-
value.match(/\d+./g).forEach(m => {
62-
var entityId = m.slice(0, -1)
63-
var state = m.slice(-1) === "+"
64-
newRegistration[entityId] = {"name":key, "state":state}
65-
})
60+
Object.entries(data).forEach(([key, value]) => {
61+
value.match(/\d+./g).forEach(m => {
62+
const entityId = m.slice(0, -1)
63+
const state = m.slice(-1) === '+'
64+
newRegistration[entityId] = {
65+
name: key,
66+
state: state
67+
}
6668
})
69+
})
6770
}
6871
const registered = { ...this.previousFrame.registered, ...newRegistration }
6972
const frame = { registered, number: frameInfo.number }
@@ -87,7 +90,7 @@ function checkDuplicates (option) {
8790
let matchedPair = ToggleModule.optionValues[option.toggle].find(elem => elem.value === value)
8891

8992
if (!matchedPair) {
90-
matchedPair = { keys: [ ], value }
93+
matchedPair = { keys: [], value }
9194
ToggleModule.optionValues[option.toggle].push(matchedPair)
9295
}
9396

0 commit comments

Comments
 (0)