Skip to content

Commit 5cc4636

Browse files
NaejDoreeJean Poree
authored andcommitted
feat(techio): adding toggle module doc
1 parent ed634cc commit 5cc4636

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# ToggleModule
2+
3+
This modules allows you to show elements only when a toggle of the cg-player is in a certain state.
4+
This can help to create debug modes.
5+
6+
## Setup
7+
⚠ This module requires the [GraphicEntityModule](https://github.com/CodinGame/codingame-game-engine/tree/master/engine/modules/entities) to work.
8+
9+
Add the dependency in the `pom.xml` of your project.
10+
```xml
11+
<dependency>
12+
<groupId>com.codingame.gameengine</groupId>
13+
<artifactId>module-toggle</artifactId>
14+
<version>3.2.0</version>
15+
</dependency>
16+
```
17+
18+
And setup the module and the toggles in your `config.js`.
19+
20+
```javascript
21+
import { GraphicEntityModule } from './entity-module/GraphicEntityModule.js'
22+
import { ToggleModule } from './toggle-module/ToggleModule.js'
23+
24+
// List of viewer modules that you want to use in your game
25+
export const modules = [
26+
GraphicEntityModule,
27+
ToggleModule
28+
]
29+
30+
// The list of toggles displayed in the cg-player
31+
export const options = [
32+
{
33+
// The name displayed over the toggle
34+
title: 'MY TOGGLE',
35+
// Getters and setters for the on/off state of your toggle
36+
get: function () {
37+
return toggles.myToggle // replace "myToggle" by the name of the toggle you want to use
38+
},
39+
set: function (value) {
40+
toggles.myToggle = value // replace "myToggle" by the name of the toggle you want to use
41+
ToggleModule.refreshContent()
42+
},
43+
// What will be displayed depending of the state of your toggle
44+
values: {
45+
'TOGGLED ON': true,
46+
'TOGGLED OFF': false
47+
}
48+
},
49+
{
50+
title: 'MY OTHER TOGGLE',
51+
...
52+
}
53+
]
54+
55+
// The list of the toggles used by the ToggleModule
56+
// replace "myToggle" by the name of the toggle you want to use
57+
export const toggles = {
58+
myToggle: true, // default value of your toggle
59+
myOtherToggle: false
60+
}
61+
62+
```
63+
64+
## Usage
65+
66+
`Referee.java`
67+
```java
68+
// Associating `myEntity` to the true state of `myToggle`
69+
toggleModule.displayOnToggleState(myEntity, "myToggle", true);
70+
// My entity will only be displayed when `myToggle` is true
71+
// (on the `TOGGLED ON` position according to our previous setup)
72+
```
73+

0 commit comments

Comments
 (0)