-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExternalData.html
96 lines (65 loc) · 3.22 KB
/
ExternalData.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<tw-storydata name="ExternalData" startnode="4" creator="Twine" creator-version="2.1.3" ifid="68021349-4F3D-4BF3-821F-9998B445CBA5" format="Harlowe" format-version="2.0.1" options="" hidden><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css">
</style><script role="script" id="twine-user-script" type="text/twine-javascript">// via https://furkleindustries.com/fictions/twine/twine2_resources/twine2_macros/
var _state = State;
window._state = _state;
function getHarloweVariable(prop) {
if (typeof(prop) === typeof(undefined) ||
prop === '') {
return;
}
return prop[0] === '$' ?
_state.variables[prop.slice(1, prop.length)] : _state.variables[prop];
}
window.getHarloweVariable = getHarloweVariable;
function setHarloweVariable(prop, val) {
if (typeof(prop) === typeof(undefined) ||
prop === '' ||
typeof(val) === typeof(undefined)) {
return;
}
if (prop[0] === '$') {
prop = prop.slice(1, prop.length);
}
_state.variables[prop] = val;
}
window.setHarloweVariable = setHarloweVariable;
var socket = new WebSocket("ws://"+window.location.hostname+":"+window.location.port+"/ws/game");
window.sendHarloweVariable = function(variableToSend) {
var payload = {};
payload[''+variableToSend]=getHarloweVariable(variableToSend);
window.send(payload);
}
socket.onopen = function() {
window.socket = socket;
var send = function(dataToSend) {
console.log("sending",dataToSend);
socket.send(JSON.stringify(dataToSend));
}
window.send = send;
var payload = { init: "init"};
send(payload);
}
socket.onmessage = function (event) {
console.log(event);
var msg = JSON.parse(event.data);
for (var key in msg) {
window.setHarloweVariable( key, msg[key] );
}
}
</script><tw-passagedata pid="1" name="Start" tags="" position="418,197">The temperature is $temperature.
It is (if: $temperature>10)[ [[Hot->Hot]] ](if: $temperature<=10)[ [[Cold->Cold]] ]
[[Check temperature again!->Start]]
[Push this temperature to Node-red]<sendTemperature|(click:?sendTemperature)[
(set: $emptyExpression to window.sendHarloweVariable('temperature'))[Sent '$temperature' back up the socket!]
]
Alternately: Do you prefer [soy milk]<sendSoy|(click:?sendSoy)[
(set: $milk to "soy")(set: $emptyExpression to window.sendHarloweVariable('milk'))] or [almond milk]<sendAlmond|(click:?sendAlmond)[
(set: $milk to "almond")(set: $emptyExpression to window.sendHarloweVariable('milk'))]?
(if: $milk is not "")[Apparently, you like $milk milk.]</tw-passagedata><tw-passagedata pid="2" name="Hot" tags="" position="601,313">Weather is hot.
[[start->Start]]</tw-passagedata><tw-passagedata pid="3" name="Cold" tags="" position="139,296">Weather is cold.
[[start->Start]]</tw-passagedata><tw-passagedata pid="4" name="Title" tags="" position="416,30">This is the title page.
It is needed so data can be initialised before the player starts.
[[Start the game!->Start]]
(set:$milk to "")</tw-passagedata><tw-passagedata pid="5" name="Soy Milk" tags="" position="418,347">You chose badly, my friend.
Soy milk tastes odd. Enjoy almond milk, while we still enjoy the company of bees.
[[start->Start]]</tw-passagedata></tw-storydata>