-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
258 lines (229 loc) · 7.98 KB
/
index.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Inkwell</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="codemirror.css">
<script type="text/javascript" src="loadSample.js"></script>
<link rel="stylesheet" href="editor.css">
<script type="text/javascript" src="codemirror.js"> </script>
<style>
html,
body,
#super-container {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body {
color: #E6E1DC;
background-color: #202020;
height:100vh;
}
#super-container {
box-sizing: border-box;
padding: 15px;
display:flex;
flex-direction:column;
}
#container {
display:flex;
height:calc(100vh - 60px);
}
#editor, #player {
width:50%;
}
#editor {
height:100%;
}
#inner-editor {
height:80%;
}
.inner-player .hide {
opacity: 0.0;
}
.inner-player * {
opacity: 1.0;
transition: opacity 1.0s;
}
a {
font-weight: 700;
color: #b97c2c;
font-family: sans-serif;
transition: color 0.6s;
text-decoration: none;
}
a:hover {
color: white;
transition: color 0.3s;
}
#player {
box-shadow: inset 0 0 10px black;
height:80%;
overflow:auto;
}
#inner-player {
box-sizing: border-box;
padding: 15px;
padding-top: 0;
}
#inner-player .hide {
opacity: 0.0;
}
#inner-player * {
opacity: 1.0;
transition: opacity 1.0s;
}
</style>
</head>
<body>
<div id="super-container">
<div style="display:flex; justify-content: space-between">
<h3>Inkwell <img id="load-icon" src="830_1.gif" alt=""></h3>
<button id="sample" style="margin: 10px">Load Sample</button>
</div>
<div id="container">
<div id="editor">
<div id="inner-editor">
<textarea name="" id="gameText" placeholder="text goes here"></textarea>
</div>
<div id="editor-panel">
<button id="submitme">Submit</button>
<h3>Errors</h3>
<pre id="error-display"></pre>
<h3>Warnings</h3>
<pre id="warning-display"></pre>
</div>
</div>
<div id="player">
<div id="inner-player"></div>
</div>
</div>
</div>
<script type="text/javascript" src="https://unpkg.com/inkjs"></script>
<script>
var story;
class Compiler {
ready = false;
worker = null;
init = (onComplete = () => { }) => {
return new Promise((resolve, reject) => {
this.worker = new Worker("worker.js");
this.ready = false;
this.worker.onmessage = (e) => {
if (e.data === "ready") {
this.ready = true;
resolve();
} else if (this.ready) {
onComplete(e.data);
$("#load-icon").fadeTo("fast", 0);
}
}
})
}
submit = (text) => {
$("#load-icon").fadeTo("fast", 1);
this.worker.postMessage(text);
}
}
const a = new Compiler();
a.init(response => {
console.log(response)
console.log(response.story.globalTags);
if (response.errors.length > 0 || response.warnings.length > 0) {
console.log("Errors", response.errors);
$("#error-display").text(response.errors.join('\n'))
console.log("Warnings", response.warnings);
$("#warning-display").text(response.warnings.join('\n'))
} else {
// should call a refresh story function here
console.log(response.story);
// story = new inkjs.Story(response.story)
processStoryContent(response.story);
$("#error-display").text("");
console.log("Warnings", response.warnings);
$("#warning-display").text("");
}
})
const textArea = document.getElementById("gameText");
textArea.value = localStorage.getItem("text") || "";
const editor = CodeMirror.fromTextArea(textArea, { viewportMargin: Infinity, lineWrapping: true, lineNumbers: true, theme: "ambiance" })
$("#submitme").click(() => {
console.log("CLICK");
if (a.ready) {
console.log("Submit");
editor.save();
var text = $("#gameText").val()
localStorage.setItem("text", text);
console.log(text);
a.submit(text);
}
})
$("#sample").click(function(){
const text = getSample();
editor.setValue(text);
a.submit(text)
})
function contentBottomEdgeY() {
return 0;
}
function showAfter(delay, element) {
$(element).addClass("hide");
setTimeout(() => $(element).removeClass("hide"), delay);
}
function processStoryContent(storyContent) {
$("#inner-player").empty();
var story = new inkjs.Story(storyContent);
// process global tags will go here
var outerStoryContainer = $("#inner-player");
var storyContainer = $("#inner-player");
continueStory(true);
function continueStory(firstTime) {
var paragraphIndex = 0;
var delay = 0.0;
var previousBottomEdge = firstTime ? 0 : contentBottomEdgeY();
while (story.canContinue) {
var paragraphText = story.Continue();
var tags = story.currentTags;
// add any special tags with this line
const paragraph = $(`<p>${paragraphText}</p>`)
storyContainer.append(
paragraph
);
showAfter(delay, paragraph);
delay += 200.0;
}
story.currentChoices.forEach(function (choice) {
const element = $(`<p class="choice"><a href="">${choice.text}</a></p>`);
storyContainer.append(
element
);
showAfter(delay, element);
delay += 200;
// include delays
element.find("a").click(event => {
event.preventDefault();
$("p.choice").remove();
story.ChooseChoiceIndex(choice.index);
continueStory();
});
$("#player").animate({ scrollTop: $("#inner-player").height() }, "slow");
return false;
});
}
}
const startup = setInterval(() => {
if(a.ready){
clearInterval(startup)
var text = $("#gameText").val()
a.submit(text);
}
}, 500)
</script>
</body>
</html>