-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (67 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Component, JSONSchema7, OutputTemplates, useState, ComponentEvent, registerComponent, PlayerPermission, createFeed, dispatchNextComponentEvent, removeFeed, Sender, isPlayerSender, isPlayerController, dispatchCompleted, isPlayerAdmin, subscribeToEvent, unsubscribeFromEvent } from "./library/parkmyst-1";
interface StationState {
waitingFeedId: string,
controlFeedId: string,
}
interface StationEvent extends ComponentEvent {
type: "stationCompleted",
sender: Sender
}
function isStationEvent(event: ComponentEvent): event is StationEvent {
return event.type === "stationCompleted" &&
(!isPlayerSender(event.sender) || isPlayerController(event.sender) || isPlayerAdmin(event.sender));
}
export class StationComponent extends Component<unknown, StationState> {
description = "StationComponent gives you a control point, where a controller player has to manually signal that a team has completed the task."
schema: JSONSchema7 = {
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"additionalProperties": false,
"properties": {}
};
outputTemplates: OutputTemplates = {
stationUserWaiting: {
template: `
<div>
A folytatáshoz teljesítsd az állomás feladatát... Ha ez megtörtént kérd az állomás vezetőt hogy engedjen tovább.
</div>
`,
example: {}
},
stationController: {
template: `
<form>
<label for="stationButton">Nyomd meg ezt a gombot, ha a csapat teljesítette a feladatát!</label>
<input id="stationButton" type="submit" inputtype="stationCompleted"/>
</form>
`,
example: {}
}
};
constructor() {
super();
this.registerSafeEventListeners<StationEvent>("stationCompleted", this.handleStationEvent, isStationEvent);
}
componentStartEvent = () => {
const [, setState] = this.useState();
setState({
waitingFeedId: createFeed("stationUserWaiting", {}),
controlFeedId: createFeed("stationController", {}, PlayerPermission.Controller)
})
subscribeToEvent("stationCompleted");
}
componentCleanUp = () => {
const [state] = useState<StationState>();
removeFeed(state.controlFeedId);
removeFeed(state.waitingFeedId);
unsubscribeFromEvent("stationCompleted");
}
componentCompleted = () => {
const information = this.getInformation();
dispatchNextComponentEvent(information.nextComponents);
}
handleStationEvent = () => {
dispatchCompleted();
}
}
registerComponent(new StationComponent());