-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaimio_sp_viz.html
252 lines (197 loc) · 8.03 KB
/
daimio_sp_viz.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Screen Perfect Daimio Prototype Visualizer</title>
<script type="text/javascript" src="/daimio_composite.js"></script>
<style>
.selected {
background-color: pink;
}
</style>
</head>
<body style="display:none">
<h1 id="header" data-daimio-template="header">
{$game.name}
</h1>
<ul id="room-list" data-daimio-template="show-all-rooms" style="float:left;position:relative;">
<h2>Rooms</h2>
{begin foo | reduce data $game.rooms | tap}
{__ | }
{end foo}
{((1 2) (2 3 4) (3 4) (4 2)) | reduce block "{__ | is in {_total | list union} | then _total else }"}
reduce(function(acc, item) {
item.slice(1).forEach(function(ref) {
if(acc.indexOf(x[ref])<0)
acc.push(x[ref])});
return acc},
[x[0]])
{begin list | merge data $game.rooms}
<li class="{_key | is like $selected-room-id | then :selected else ""}">
<a href="" class="room-label" data-value="{_key}">
<img src="{_urls.control_thumb}" width="100" height="100">
<strong>
{_name}
</strong>
asdfasdf {_exits} kjfkfj
</a>
<ul>
{begin exists | each data {_exits | list from-json}}
<li class="exit-listing" data-value="{_key}">
foo
<img src="{$game.rooms.{_value.room}.urls.control_thumb}" width="40" height="40">
{$game.rooms.{_value.room}.name}
<a href="" class="remove-exit" data-value="{_key}">Remove</a>
</li>
{end exists}
</ul>
</li>
{end list}
</ul>
<script id="control" type="text/daml" class="spaceseeds">
outer
$game {}
$selected-room-id -1
// NETWORK
@game-data socket-in game-data
@request-data socket-out request-data
@init from-js
@init -> @request-data
changed {__}
@game-data -> {__ | >$game | 0} -> changed
// DISPLAY
show-all-rooms
header
@set-room-list dom-set-html room-list
@set-header dom-set-html header
changed -> show-all-rooms -> @set-room-list
changed -> header -> @set-header
// SAVE A ROOM
@save-game socket-out save-game
@room-form dom-on-submit
save-game {__}
save-game -> changed
save-game -> @save-game
eat-room-form
{ __ | >raw-info
| * (:name _raw-info.name
:exits {_raw-info.exits | list from-json}
:urls {_raw-info | list remove by_key (:name :exits)} )
| list poke data $game path (:rooms {_raw-info.index | else {$game.rooms | count}}) | >$game}
@room-form -> eat-room-form -> save-game
// SELECT A ROOM
show-room-div
room-changer
{ __ | >$selected-room-id}
selected-room-only
{$selected-room-id | eq -1 | else "{1 | >@good}" | run}
@change-room dom-on-click .room-label
@set-room-div dom-set-html room-div
@init -> {"<p>Select a room from the list</p>"} -> @set-room-div
@change-room -> room-changer -> changed
changed -> selected-room-only
selected-room-only.good -> {$game.rooms.{$selected-room-id}} -> show-room-div -> @set-room-div
// ADD A ROOM
@add-room-form dom-on-submit
@add-room-form -> eat-room-form
@add-room-form -> {$game.rooms | count} -> room-changer
// LIST EXISTS
highlight-exit {__}
@tweak-style
@over-exit dom-on-mouseover .exit-listing
@out-exit dom-on-mouseout .exit-listing
@over-exit -> {* (:id {("exit-" __in) | join} :attr "background-color" :value :yellow)} -> @tweak-style
@out-exit -> {* (:id {("exit-" __in) | join} :attr "background-color" :value :green)} -> @tweak-style
// ADD AN EXIT
add-an-exit
{ $game.rooms.{$selected-room-id}.exits
| poke {* (:room __in.exit-id
:width 100 :height 100
:top 0 :left 0)}
| >$game.rooms.{$selected-room-id}.exits}
@add-exit-form dom-on-submit
@add-exit-form -> add-an-exit -> save-game
// REMOVE AN EXIT
remove-an-exit
{ $game.rooms.{$selected-room-id}.exits
| list remove by_key __in
| >$game.rooms.{$selected-room-id}.exits}
@remove-exit dom-on-click .remove-exit
@remove-exit -> remove-an-exit -> save-game
// MOVE AN EXIT
move-hot-spot
{ __ | >e | $game.rooms.{$selected-room-id}.exits.{_e.value} | >exit
| * (:room _exit.room :width _exit.width :height _exit.height
:top {_exit.top | add _e.offsetY | subtract _exit.height | max 0}
:left {_exit.left | add _e.offsetX | max 0})
| >$game.rooms.{$selected-room-id}.exits.{_e.value}}
@hotspot dom-on-dragend .hotspot
@hotspot -> move-hot-spot -> save-game
// SIZE AN EXIT
size-hot-spot
{ __ | >e | $game.rooms.{$selected-room-id}.exits.{_e.value} | >exit
| * (:room _exit.room :top _exit.top :left _exit.left
:width {_exit.width | add _e.offsetX | max 30}
:height {_exit.height | add _e.offsetY | minus 30 | max 30})
| >$game.rooms.{$selected-room-id}.exits.{_e.value}}
@sizer dom-on-dragend .sizer
@sizer -> size-hot-spot -> save-game
// TODO: exits GUI
// TODO: add 'parent' to history
// TODO: munge html and daimio code in html templates separately (like {3 | >$x} -> {3 | >x})
// TODO: make run default to all local named scoped params (ORLY?) [could work for injected but not pipeline]
// TODO: only run with not if with but maybe merge with stupid state stupid alias stupid pipes
// TODO: shift to show greens in control
// YAGNI: local machine refs
// YAGNI: whitespace chomping
</script>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
D.import_port_flavour('dom-on-dragend', {
dir: 'in',
outside_add: function() {
var self = this
var fun = function(value, event) {
event.dataTransfer.effectAllowed = "move"
event.dataTransfer.dropEffect = 'move'
event.value = value
self.enter(D.scrub_var(event))
}
D.track_event('dragend', this.settings.thing, fun)
}
})
D.import_port_flavour('tweak-style', {
dir: 'out',
outside_exit: function(ship) {
try {
var el = document.getElementById(ship.id)
if(!el) return false
el.style[ship.attr] = ship.value
} catch(e) {}
}
})
document.addEventListener('DOMContentLoaded', function() {
D.Etc.socket = io.connect('/')
var template_els = [].slice.call(document.querySelectorAll('[data-daimio-template]'))
, templates = template_els.reduce(function(acc, template) {
var name = template.attributes.getNamedItem('data-daimio-template').value
acc[name] = template.innerHTML
template.innerHTML = ""
return acc
}, {})
document.getElementsByTagName('body')[0].style.display = ''
var seedlikes = Array.prototype.slice.call(
document.getElementsByClassName('spaceseeds')
).map(function(node) {
return node.text
}).join("\n")
var outerseed = D.make_some_space(seedlikes, templates)
OuterSpace = new D.Space(outerseed) // published for debug
// activate init port
var game_id = window.location.pathname.replace(/\/$/, '').split('/')[1]
var data = {game: game_id} // {game: '5275ec64388d57ccb2f87d0e'}
D.send_value_to_js_port(outerseed, 'init', data)
})
</script>
</body>
</html>