woyo-server 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/woyo/server/server.rb +155 -29
  3. data/lib/woyo/server/version.rb +1 -1
  4. data/public/server/css/server.css +6 -6
  5. data/public/server/ember-1.6.1-kit/README.md +36 -0
  6. data/public/server/ember-1.6.1-kit/css/normalize.css +406 -0
  7. data/public/server/ember-1.6.1-kit/css/style.css +4 -0
  8. data/public/server/ember-1.6.1-kit/index.html +31 -0
  9. data/public/server/ember-1.6.1-kit/js/app.js +11 -0
  10. data/public/server/ember-1.6.1-kit/js/libs/ember-1.6.1.js +46762 -0
  11. data/public/server/ember-1.6.1-kit/js/libs/ember-data-1.0.0-beta.8.js +12053 -0
  12. data/public/server/ember-1.6.1-kit/js/libs/handlebars-1.1.2.js +2595 -0
  13. data/public/server/ember-1.6.1-kit/js/libs/jquery-1.10.2.js +9789 -0
  14. data/public/server/ember-1.6.1-kit/tests/runner.css +14 -0
  15. data/public/server/ember-1.6.1-kit/tests/runner.js +13 -0
  16. data/public/server/ember-1.6.1-kit/tests/tests.js +31 -0
  17. data/public/server/ember-1.6.1-kit/tests/vendor/qunit-1.12.0.css +244 -0
  18. data/public/server/ember-1.6.1-kit/tests/vendor/qunit-1.12.0.js +2212 -0
  19. data/public/server/ember-1.7.0/ember.js +48219 -0
  20. data/public/server/ember-animate-0.3.5/README.md +112 -0
  21. data/public/server/ember-animate-0.3.5/bower.json +25 -0
  22. data/public/server/ember-animate-0.3.5/ember-animate.js +256 -0
  23. data/public/server/ember-data-1.0.0-beta.9/ember-data.js +12877 -0
  24. data/public/server/handlebars-1.1.2/handlebars.js +2595 -0
  25. data/public/server/jquery-1.10.2/jquery.js +9789 -0
  26. data/public/server/js/play.js +246 -0
  27. data/public/server/js/server.js +5 -65
  28. data/todo.txt +17 -10
  29. data/views/server/layout.erb +37 -0
  30. data/views/server/play.erb +74 -0
  31. data/views/server/start.erb +22 -0
  32. metadata +29 -10
  33. data/views/server/actions.haml +0 -6
  34. data/views/server/item.haml +0 -7
  35. data/views/server/layout.haml +0 -25
  36. data/views/server/location.haml +0 -8
  37. data/views/server/way.haml +0 -6
  38. data/views/server/world.haml +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfa37213238187a3f86e96fbfc729b52cdf3570d
4
- data.tar.gz: 8103df5e8c3917375468aebacea6e73c58fefb33
3
+ metadata.gz: cfd63e05b76ab53afdae372cc7e3551ff8d71521
4
+ data.tar.gz: 9112b14b7d522244cf950e119d605d1e5f383a99
5
5
  SHA512:
6
- metadata.gz: f92db08cbf485b5422d0d09863cfba099046a006eb336b49ef6ce6ed3154739e4aab9c6599230a83e0b32e96cdc9e0b90b61b20a10b0d1fe5cfc2460f73b205f
7
- data.tar.gz: 6cea759a5e366bd90c5f3b5936695bd35f9a90678e55e671d48fa08c90c1749ceb5c33760d5f3156f204b1a8d21e62318591931fc562d43842d010d292e5ed78
6
+ metadata.gz: 304f8ee49402ddfe3fc72784e63e2157b1234c700d3c8a24a8448cc90ea205c145155be2487071dd4f7c0bc08acf1c685b4e04a215c40d262677ac87e6cae5c1
7
+ data.tar.gz: bed395bc349ec2b81e5f16003147215491247754220a97fa09b3262041f0b3d36b977ebb64019e9a83be313a4e896d34e860cf22d97fbd58c0c72df7c3a8c98d
@@ -1,6 +1,8 @@
1
1
  require 'sinatra/base'
2
2
  require 'sinatra/partial'
3
- require 'haml'
3
+ require 'sinatra/json'
4
+ require 'sinatra/reloader'
5
+ require 'erb'
4
6
  require 'json'
5
7
  require 'woyo/world'
6
8
 
@@ -8,7 +10,9 @@ module Woyo
8
10
 
9
11
  class Server < Sinatra::Application
10
12
 
11
- def self.load_world glob = 'world/*.rb'
13
+ WORLD_FILES = 'world/**/*.rb'
14
+
15
+ def self.load_world glob = WORLD_FILES
12
16
  world = Woyo::World.new
13
17
  Dir[glob].each do |filename|
14
18
  eval_world File.read( filename ), filename, world
@@ -22,57 +26,179 @@ class Server < Sinatra::Application
22
26
  end
23
27
 
24
28
  configure do
29
+ # todo: sessions with server-side store instead of cookie
25
30
  enable :sessions
26
- set :session_secret, SecureRandom.hex(16)
31
+ set session_secret: SecureRandom.hex(16)
27
32
  set root: '.'
28
33
  set views: Proc.new { File.join(root, "views/server") }
29
34
  set public_folder: Proc.new { File.join(root, "public/server") }
30
35
  set world: self.load_world
31
36
  end
32
37
 
38
+ configure :development do
39
+ register Sinatra::Reloader
40
+ require 'pry'
41
+ end
42
+
43
+ def reload_world_changes
44
+ # todo: get and track file adds, deletes, mtimes in WORLD_FILES
45
+ end
46
+
47
+ before do
48
+ if settings.development?
49
+ reload_world_changes
50
+ end
51
+ end
52
+
33
53
  def world
34
- settings.world
54
+ @world = settings.world
55
+ end
56
+
57
+ def location
58
+ @location = world.locations[session[:location_id]]
59
+ end
60
+
61
+ def set_location id
62
+ session[:location_id] = id
63
+ location
35
64
  end
36
65
 
37
66
  get '/' do
38
67
  redirect to 'default.html' if world.description.nil? && world.start.nil? # && world.name.nil?
39
- @world = world
40
- session[:location_id] = world.start
41
- haml :world
68
+ set_location world.start
69
+ erb :start
42
70
  end
43
71
 
44
- get '/location' do
45
- @location = world.locations[session[:location_id]]
46
- haml :location
72
+ get '/play' do
73
+ location
74
+ erb :play
47
75
  end
48
76
 
49
- get '/go/*' do |way_id|
50
- content_type :json
51
- way = world.locations[session[:location_id]].ways[way_id.to_sym]
52
- session[:location_id] = way.to.id if way.open?
53
- way.go.to_json
77
+ get '/locations/?:id?' do |id|
78
+ ids = id ? [ id.to_sym ] : params[:ids]
79
+ ids = [ location.id ] unless false # unless admin? a player can access current location only
80
+ ids = ids.collect { |id| id.to_sym }
81
+ locations = world.locations.select { |_,loc| ids.include? loc.id } # old - id.nil? || ( loc.id == id ) }
82
+ json(
83
+ {
84
+ locations: locations.collect do |_,loc|
85
+ {
86
+ id: loc.id,
87
+ name: loc.name,
88
+ description: loc.description,
89
+ ways: loc.ways.keys,
90
+ items: loc.items.keys
91
+ }
92
+ end
93
+ }
94
+ )
95
+ end
96
+
97
+ get '/items/?:id?' do |id|
98
+ ids = id ? [ id.to_sym ] : params[:ids]
99
+ if ids && ! ids.empty?
100
+ ids = ids.collect { |id| id.to_sym }
101
+ items = location.items.select { |_,item| ids.include? item.id }
102
+ json(
103
+ {
104
+ items: items.collect do |_,item|
105
+ {
106
+ location: location.id,
107
+ id: item.id,
108
+ name: item.name,
109
+ description: item.description,
110
+ actions: item.actions.collect { |_,action| "#{item.id}-#{action.id}" }
111
+ }
112
+ end.compact.uniq,
113
+ actions: items.collect do |_,item|
114
+ item.actions.collect do |_,action|
115
+ {
116
+ item: item.id,
117
+ id: "#{item.id}-#{action.id}",
118
+ name: action.name,
119
+ description: action.description,
120
+ execution: "item/#{item.id}/#{action.id}"
121
+ }
122
+ end
123
+ end.flatten.compact.uniq,
124
+ executions: items.collect do |_,item|
125
+ item.actions.collect do |_,action|
126
+ {
127
+ action: "#{item.id}-#{action.id}",
128
+ id: "item/#{item.id}/#{action.id}"
129
+ }
130
+ end # empty execution so action will not be executed until clicked
131
+ end.flatten.compact.uniq
132
+ }
133
+ )
134
+ end
54
135
  end
55
136
 
56
- get '/do/*/*/*' do |owner_type,owner_id,action_id|
137
+ get '/ways/?:id?' do |id|
138
+ ids = id ? [ id.to_sym ] : params[:ids]
139
+ if ids && ! ids.empty?
140
+ ids = ids.collect { |id| id.to_sym }
141
+ ways = location.ways.select { |_,way| ids.include? way.id }
142
+ json(
143
+ {
144
+ ways: ways.collect do |_,way|
145
+ {
146
+ location: location.id,
147
+ id: way.id,
148
+ name: way.name,
149
+ description: way.description,
150
+ actions: way.actions.collect { |_,action| "#{way.id}-#{action.id}" }
151
+ }
152
+ end.compact.uniq,
153
+ actions: ways.collect do |_,way|
154
+ way.actions.collect do |_,action|
155
+ {
156
+ way: way.id,
157
+ id: "#{way.id}-#{action.id}",
158
+ name: action.name,
159
+ description: action.description,
160
+ execution: "way/#{way.id}/#{action.id}"
161
+ }
162
+ end
163
+ end.flatten.compact.uniq,
164
+ executions: ways.collect do |_,way|
165
+ way.actions.collect do |_,action|
166
+ {
167
+ action: "#{way.id}-#{action.id}",
168
+ id: "way/#{way.id}/#{action.id}"
169
+ }
170
+ end # empty execution so action will not be executed until clicked
171
+ end.flatten.compact.uniq
172
+ }
173
+ )
174
+ end
175
+ end
176
+
177
+ get '/executions/*/*/*' do |owner_type,owner_id,action_id|
57
178
  content_type :json
58
- initial_location_id = session[:location_id]
59
- location = world.locations[initial_location_id]
60
179
  if location.children.include? owner_type.to_sym
61
180
  owner = location.send( owner_type, owner_id.to_sym )
62
- result = owner.action( action_id.to_sym ).execute
63
- # extract client-related info from execution hash
64
- if result[:execution].kind_of?( Hash )
65
- result[:changes] = result[:execution][:changes] ? Array(result[:execution][:changes]) : []
66
- if result[:execution][:location]
67
- session[:location_id] = result[:execution][:location]
68
- result[:changes] << :location
69
- end
181
+ execution = owner.action( action_id.to_sym ).execute
182
+ if execution[:result][:location]
183
+ session[:location_id] = execution[:result][:location]
70
184
  end
71
- result.delete :execution # execution info is for server only, do not pass to client
72
- result.to_json
185
+ execution[:id] = "#{owner_type}/#{owner_id}/#{action_id}"
186
+ execution[:action] = "#{owner_id}-#{action_id}"
187
+ json(
188
+ {
189
+ executions: execution
190
+ }
191
+ )
73
192
  end
74
193
  end
75
-
194
+
195
+ # get '/go/*' do |way_id|
196
+ # content_type :json
197
+ # way = world.locations[session[:location_id]].ways[way_id.to_sym]
198
+ # session[:location_id] = way.to.id if way.open?
199
+ # way.go.to_json
200
+ # end
201
+
76
202
  end
77
203
 
78
204
  end
@@ -1,3 +1,3 @@
1
1
  module Woyo
2
- SERVER_VERSION = "0.0.8"
2
+ SERVER_VERSION = "0.0.9"
3
3
  end
@@ -1,17 +1,17 @@
1
1
 
2
2
  body {
3
- display:none;
3
+ /* display:none; */
4
4
  }
5
5
 
6
- p.describe-actions {
7
- display:none;
8
- opacity:0;
6
+ p.describe-action {
7
+ /* display:none; */
8
+ /* opacity:0; */
9
9
  padding-left:1em;
10
10
  }
11
11
 
12
12
  p.going {
13
- display:none;
14
- opacity:0;
13
+ /* display:none; */
14
+ /* opacity:0; */
15
15
  padding-left:1em;
16
16
  }
17
17
 
@@ -0,0 +1,36 @@
1
+ starter-kit
2
+ ===========
3
+
4
+ A starter kit for Ember
5
+
6
+ Your Ember.js project is almost ready! Here's how to get started:
7
+
8
+ - Start writing your app in `js/app.js`.
9
+
10
+ - Describe your application HTML in `index.html`.
11
+
12
+ - During development, you can link to `js/libs/ember-*.js` to get the
13
+ unminified version of Ember.js.
14
+
15
+ - Add CSS to `css/style.css`.
16
+
17
+ - Open `index.html` in your browser.
18
+
19
+ Tests
20
+ =====
21
+
22
+ This starter kit comes with an integration test sample, written for QUnit runner.
23
+
24
+ You can run the tests by opening the `index.html?test` page in your browser.
25
+
26
+ The test is located in the `tests/tests.js` file. You can see how such an
27
+ integration test should be written, using QUnit assertions and ember-testing helpers.
28
+
29
+ For more information about ember-testing package see [ember-testing](http://emberjs.com/guides/testing/integration/).
30
+
31
+ For more information about the QUnit testing framework, see [QUnit](http://qunitjs.com/).
32
+
33
+ Contact
34
+ ====
35
+
36
+ [www.emberjs.com](http://www.emberjs.com)
@@ -0,0 +1,406 @@
1
+ /*! normalize.css v2.1.3 | MIT License | git.io/normalize */
2
+
3
+ /* ==========================================================================
4
+ HTML5 display definitions
5
+ ========================================================================== */
6
+
7
+ /**
8
+ * Correct `block` display not defined in IE 8/9.
9
+ */
10
+
11
+ article,
12
+ aside,
13
+ details,
14
+ figcaption,
15
+ figure,
16
+ footer,
17
+ header,
18
+ hgroup,
19
+ main,
20
+ nav,
21
+ section,
22
+ summary {
23
+ display: block;
24
+ }
25
+
26
+ /**
27
+ * Correct `inline-block` display not defined in IE 8/9.
28
+ */
29
+
30
+ audio,
31
+ canvas,
32
+ video {
33
+ display: inline-block;
34
+ }
35
+
36
+ /**
37
+ * Prevent modern browsers from displaying `audio` without controls.
38
+ * Remove excess height in iOS 5 devices.
39
+ */
40
+
41
+ audio:not([controls]) {
42
+ display: none;
43
+ height: 0;
44
+ }
45
+
46
+ /**
47
+ * Address `[hidden]` styling not present in IE 8/9.
48
+ * Hide the `template` element in IE, Safari, and Firefox < 22.
49
+ */
50
+
51
+ [hidden],
52
+ template {
53
+ display: none;
54
+ }
55
+
56
+ /* ==========================================================================
57
+ Base
58
+ ========================================================================== */
59
+
60
+ /**
61
+ * 1. Set default font family to sans-serif.
62
+ * 2. Prevent iOS text size adjust after orientation change, without disabling
63
+ * user zoom.
64
+ */
65
+
66
+ html {
67
+ font-family: sans-serif; /* 1 */
68
+ -ms-text-size-adjust: 100%; /* 2 */
69
+ -webkit-text-size-adjust: 100%; /* 2 */
70
+ }
71
+
72
+ /**
73
+ * Remove default margin.
74
+ */
75
+
76
+ body {
77
+ margin: 0;
78
+ }
79
+
80
+ /* ==========================================================================
81
+ Links
82
+ ========================================================================== */
83
+
84
+ /**
85
+ * Remove the gray background color from active links in IE 10.
86
+ */
87
+
88
+ a {
89
+ background: transparent;
90
+ }
91
+
92
+ /**
93
+ * Address `outline` inconsistency between Chrome and other browsers.
94
+ */
95
+
96
+ a:focus {
97
+ outline: thin dotted;
98
+ }
99
+
100
+ /**
101
+ * Improve readability when focused and also mouse hovered in all browsers.
102
+ */
103
+
104
+ a:active,
105
+ a:hover {
106
+ outline: 0;
107
+ }
108
+
109
+ /* ==========================================================================
110
+ Typography
111
+ ========================================================================== */
112
+
113
+ /**
114
+ * Address variable `h1` font-size and margin within `section` and `article`
115
+ * contexts in Firefox 4+, Safari 5, and Chrome.
116
+ */
117
+
118
+ h1 {
119
+ font-size: 2em;
120
+ margin: 0.67em 0;
121
+ }
122
+
123
+ /**
124
+ * Address styling not present in IE 8/9, Safari 5, and Chrome.
125
+ */
126
+
127
+ abbr[title] {
128
+ border-bottom: 1px dotted;
129
+ }
130
+
131
+ /**
132
+ * Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
133
+ */
134
+
135
+ b,
136
+ strong {
137
+ font-weight: bold;
138
+ }
139
+
140
+ /**
141
+ * Address styling not present in Safari 5 and Chrome.
142
+ */
143
+
144
+ dfn {
145
+ font-style: italic;
146
+ }
147
+
148
+ /**
149
+ * Address differences between Firefox and other browsers.
150
+ */
151
+
152
+ hr {
153
+ -moz-box-sizing: content-box;
154
+ box-sizing: content-box;
155
+ height: 0;
156
+ }
157
+
158
+ /**
159
+ * Address styling not present in IE 8/9.
160
+ */
161
+
162
+ mark {
163
+ background: #ff0;
164
+ color: #000;
165
+ }
166
+
167
+ /**
168
+ * Correct font family set oddly in Safari 5 and Chrome.
169
+ */
170
+
171
+ code,
172
+ kbd,
173
+ pre,
174
+ samp {
175
+ font-family: monospace, serif;
176
+ font-size: 1em;
177
+ }
178
+
179
+ /**
180
+ * Improve readability of pre-formatted text in all browsers.
181
+ */
182
+
183
+ pre {
184
+ white-space: pre-wrap;
185
+ }
186
+
187
+ /**
188
+ * Set consistent quote types.
189
+ */
190
+
191
+ q {
192
+ quotes: "\201C" "\201D" "\2018" "\2019";
193
+ }
194
+
195
+ /**
196
+ * Address inconsistent and variable font size in all browsers.
197
+ */
198
+
199
+ small {
200
+ font-size: 80%;
201
+ }
202
+
203
+ /**
204
+ * Prevent `sub` and `sup` affecting `line-height` in all browsers.
205
+ */
206
+
207
+ sub,
208
+ sup {
209
+ font-size: 75%;
210
+ line-height: 0;
211
+ position: relative;
212
+ vertical-align: baseline;
213
+ }
214
+
215
+ sup {
216
+ top: -0.5em;
217
+ }
218
+
219
+ sub {
220
+ bottom: -0.25em;
221
+ }
222
+
223
+ /* ==========================================================================
224
+ Embedded content
225
+ ========================================================================== */
226
+
227
+ /**
228
+ * Remove border when inside `a` element in IE 8/9.
229
+ */
230
+
231
+ img {
232
+ border: 0;
233
+ }
234
+
235
+ /**
236
+ * Correct overflow displayed oddly in IE 9.
237
+ */
238
+
239
+ svg:not(:root) {
240
+ overflow: hidden;
241
+ }
242
+
243
+ /* ==========================================================================
244
+ Figures
245
+ ========================================================================== */
246
+
247
+ /**
248
+ * Address margin not present in IE 8/9 and Safari 5.
249
+ */
250
+
251
+ figure {
252
+ margin: 0;
253
+ }
254
+
255
+ /* ==========================================================================
256
+ Forms
257
+ ========================================================================== */
258
+
259
+ /**
260
+ * Define consistent border, margin, and padding.
261
+ */
262
+
263
+ fieldset {
264
+ border: 1px solid #c0c0c0;
265
+ margin: 0 2px;
266
+ padding: 0.35em 0.625em 0.75em;
267
+ }
268
+
269
+ /**
270
+ * 1. Correct `color` not being inherited in IE 8/9.
271
+ * 2. Remove padding so people aren't caught out if they zero out fieldsets.
272
+ */
273
+
274
+ legend {
275
+ border: 0; /* 1 */
276
+ padding: 0; /* 2 */
277
+ }
278
+
279
+ /**
280
+ * 1. Correct font family not being inherited in all browsers.
281
+ * 2. Correct font size not being inherited in all browsers.
282
+ * 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome.
283
+ */
284
+
285
+ button,
286
+ input,
287
+ select,
288
+ textarea {
289
+ font-family: inherit; /* 1 */
290
+ font-size: 100%; /* 2 */
291
+ margin: 0; /* 3 */
292
+ }
293
+
294
+ /**
295
+ * Address Firefox 4+ setting `line-height` on `input` using `!important` in
296
+ * the UA stylesheet.
297
+ */
298
+
299
+ button,
300
+ input {
301
+ line-height: normal;
302
+ }
303
+
304
+ /**
305
+ * Address inconsistent `text-transform` inheritance for `button` and `select`.
306
+ * All other form control elements do not inherit `text-transform` values.
307
+ * Correct `button` style inheritance in Chrome, Safari 5+, and IE 8+.
308
+ * Correct `select` style inheritance in Firefox 4+ and Opera.
309
+ */
310
+
311
+ button,
312
+ select {
313
+ text-transform: none;
314
+ }
315
+
316
+ /**
317
+ * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
318
+ * and `video` controls.
319
+ * 2. Correct inability to style clickable `input` types in iOS.
320
+ * 3. Improve usability and consistency of cursor style between image-type
321
+ * `input` and others.
322
+ */
323
+
324
+ button,
325
+ html input[type="button"], /* 1 */
326
+ input[type="reset"],
327
+ input[type="submit"] {
328
+ -webkit-appearance: button; /* 2 */
329
+ cursor: pointer; /* 3 */
330
+ }
331
+
332
+ /**
333
+ * Re-set default cursor for disabled elements.
334
+ */
335
+
336
+ button[disabled],
337
+ html input[disabled] {
338
+ cursor: default;
339
+ }
340
+
341
+ /**
342
+ * 1. Address box sizing set to `content-box` in IE 8/9/10.
343
+ * 2. Remove excess padding in IE 8/9/10.
344
+ */
345
+
346
+ input[type="checkbox"],
347
+ input[type="radio"] {
348
+ box-sizing: border-box; /* 1 */
349
+ padding: 0; /* 2 */
350
+ }
351
+
352
+ /**
353
+ * 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome.
354
+ * 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome
355
+ * (include `-moz` to future-proof).
356
+ */
357
+
358
+ input[type="search"] {
359
+ -webkit-appearance: textfield; /* 1 */
360
+ -moz-box-sizing: content-box;
361
+ -webkit-box-sizing: content-box; /* 2 */
362
+ box-sizing: content-box;
363
+ }
364
+
365
+ /**
366
+ * Remove inner padding and search cancel button in Safari 5 and Chrome
367
+ * on OS X.
368
+ */
369
+
370
+ input[type="search"]::-webkit-search-cancel-button,
371
+ input[type="search"]::-webkit-search-decoration {
372
+ -webkit-appearance: none;
373
+ }
374
+
375
+ /**
376
+ * Remove inner padding and border in Firefox 4+.
377
+ */
378
+
379
+ button::-moz-focus-inner,
380
+ input::-moz-focus-inner {
381
+ border: 0;
382
+ padding: 0;
383
+ }
384
+
385
+ /**
386
+ * 1. Remove default vertical scrollbar in IE 8/9.
387
+ * 2. Improve readability and alignment in all browsers.
388
+ */
389
+
390
+ textarea {
391
+ overflow: auto; /* 1 */
392
+ vertical-align: top; /* 2 */
393
+ }
394
+
395
+ /* ==========================================================================
396
+ Tables
397
+ ========================================================================== */
398
+
399
+ /**
400
+ * Remove most spacing between table cells.
401
+ */
402
+
403
+ table {
404
+ border-collapse: collapse;
405
+ border-spacing: 0;
406
+ }