gamefic-sdk 1.7.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +5 -5
  2. data/bin/gamefic +16 -0
  3. data/lib/gamefic-sdk.rb +4 -24
  4. data/lib/gamefic-sdk/diagram.rb +205 -0
  5. data/lib/gamefic-sdk/scaffold.rb +54 -0
  6. data/lib/gamefic-sdk/server.rb +81 -65
  7. data/lib/gamefic-sdk/shell.rb +22 -129
  8. data/lib/gamefic-sdk/tasks.rb +40 -0
  9. data/lib/gamefic-sdk/tasks/common.rb +21 -0
  10. data/lib/gamefic-sdk/tasks/ruby.rb +99 -0
  11. data/lib/gamefic-sdk/tasks/web.rb +82 -0
  12. data/lib/gamefic-sdk/version.rb +5 -5
  13. metadata +123 -139
  14. data/bin/gfk +0 -6
  15. data/html/core/engine.js +0 -114
  16. data/html/core/jquery.js +0 -5
  17. data/html/core/jquery.modal.css +0 -44
  18. data/html/core/jquery.modal.js +0 -225
  19. data/html/core/js.cookie.js +0 -137
  20. data/html/sinatra/engine.js +0 -65
  21. data/html/skins/hypertext/compass.png +0 -0
  22. data/html/skins/hypertext/index.html +0 -149
  23. data/html/skins/hypertext/style.css +0 -74
  24. data/html/skins/minimal/index.html.erb +0 -22
  25. data/html/skins/minimal/index.rb +0 -4
  26. data/html/skins/minimal/play.js +0 -36
  27. data/html/skins/minimal/style.css +0 -8
  28. data/html/skins/multimedia/close.png +0 -0
  29. data/html/skins/multimedia/index.html +0 -179
  30. data/html/skins/multimedia/mobile.css +0 -10
  31. data/html/skins/multimedia/spinner.gif +0 -0
  32. data/html/skins/multimedia/style.css +0 -186
  33. data/html/skins/standard/index.html.erb +0 -22
  34. data/html/skins/standard/index.rb +0 -4
  35. data/html/skins/standard/play.js +0 -18
  36. data/html/skins/standard/style.css +0 -73
  37. data/lib/gamefic-sdk/build.rb +0 -30
  38. data/lib/gamefic-sdk/config.rb +0 -126
  39. data/lib/gamefic-sdk/debug.rb +0 -4
  40. data/lib/gamefic-sdk/debug/action.rb +0 -30
  41. data/lib/gamefic-sdk/debug/plot.rb +0 -23
  42. data/lib/gamefic-sdk/platform.rb +0 -22
  43. data/lib/gamefic-sdk/platform/base.rb +0 -68
  44. data/lib/gamefic-sdk/platform/gfic.rb +0 -27
  45. data/lib/gamefic-sdk/platform/sinatra.rb +0 -98
  46. data/lib/gamefic-sdk/platform/web.rb +0 -176
  47. data/lib/gamefic-sdk/platform/web/app_config.rb +0 -81
  48. data/lib/gamefic-sdk/platform/web/engine.rb +0 -44
  49. data/lib/gamefic-sdk/platform/web/user.rb +0 -19
  50. data/lib/gamefic-sdk/shell/init.rb +0 -83
  51. data/lib/gamefic-sdk/shell/test.rb +0 -32
  52. data/scripts/save-restore-undo.plot.rb +0 -25
  53. data/scripts/snapshots.plot.rb +0 -16
  54. data/scripts/standard.plot.rb +0 -10
  55. data/scripts/standard/actions.plot.rb +0 -13
  56. data/scripts/standard/actions/drop.plot.rb +0 -19
  57. data/scripts/standard/actions/enter.plot.rb +0 -19
  58. data/scripts/standard/actions/go.plot.rb +0 -48
  59. data/scripts/standard/actions/insert.plot.rb +0 -37
  60. data/scripts/standard/actions/inventory.plot.rb +0 -9
  61. data/scripts/standard/actions/leave.plot.rb +0 -30
  62. data/scripts/standard/actions/look.plot.rb +0 -108
  63. data/scripts/standard/actions/nil.plot.rb +0 -36
  64. data/scripts/standard/actions/place.plot.rb +0 -41
  65. data/scripts/standard/actions/quit.plot.rb +0 -11
  66. data/scripts/standard/actions/take.plot.rb +0 -31
  67. data/scripts/standard/actions/talk.plot.rb +0 -27
  68. data/scripts/standard/actions/wait.plot.rb +0 -3
  69. data/scripts/standard/clothing.plot.rb +0 -4
  70. data/scripts/standard/clothing/actions.plot.rb +0 -4
  71. data/scripts/standard/clothing/actions/doff.plot.rb +0 -12
  72. data/scripts/standard/clothing/actions/drop.plot.rb +0 -8
  73. data/scripts/standard/clothing/actions/inventory.plot.rb +0 -14
  74. data/scripts/standard/clothing/actions/wear.plot.rb +0 -20
  75. data/scripts/standard/clothing/entities.plot.rb +0 -7
  76. data/scripts/standard/clothing/entities/clothing.plot.rb +0 -5
  77. data/scripts/standard/clothing/entities/coat.plot.rb +0 -3
  78. data/scripts/standard/clothing/entities/gloves.plot.rb +0 -3
  79. data/scripts/standard/clothing/entities/hat.plot.rb +0 -3
  80. data/scripts/standard/clothing/entities/pants.plot.rb +0 -3
  81. data/scripts/standard/clothing/entities/shirt.plot.rb +0 -3
  82. data/scripts/standard/clothing/entities/shoes.plot.rb +0 -3
  83. data/scripts/standard/container.plot.rb +0 -28
  84. data/scripts/standard/container/actions.plot.rb +0 -0
  85. data/scripts/standard/container/entities.plot.rb +0 -5
  86. data/scripts/standard/direction.plot.rb +0 -55
  87. data/scripts/standard/edible.plot.rb +0 -21
  88. data/scripts/standard/entities.plot.rb +0 -12
  89. data/scripts/standard/entities/character.plot.rb +0 -10
  90. data/scripts/standard/entities/fixture.plot.rb +0 -3
  91. data/scripts/standard/entities/item.plot.rb +0 -3
  92. data/scripts/standard/entities/portal.plot.rb +0 -44
  93. data/scripts/standard/entities/receptacle.plot.rb +0 -3
  94. data/scripts/standard/entities/room.plot.rb +0 -57
  95. data/scripts/standard/entities/rubble.plot.rb +0 -11
  96. data/scripts/standard/entities/scenery.plot.rb +0 -3
  97. data/scripts/standard/entities/supporter.plot.rb +0 -7
  98. data/scripts/standard/entities/thing.plot.rb +0 -7
  99. data/scripts/standard/give.plot.rb +0 -27
  100. data/scripts/standard/lockable.plot.rb +0 -79
  101. data/scripts/standard/modules.plot.rb +0 -9
  102. data/scripts/standard/modules/attachable.plot.rb +0 -12
  103. data/scripts/standard/modules/auto_takes.plot.rb +0 -50
  104. data/scripts/standard/modules/enterable.plot.rb +0 -15
  105. data/scripts/standard/modules/explicit_exits.plot.rb +0 -15
  106. data/scripts/standard/modules/itemizable.plot.rb +0 -18
  107. data/scripts/standard/modules/locale_description.plot.rb +0 -20
  108. data/scripts/standard/modules/parent-room.plot.rb +0 -9
  109. data/scripts/standard/modules/portable.plot.rb +0 -11
  110. data/scripts/standard/modules/use.plot.rb +0 -51
  111. data/scripts/standard/openable.plot.rb +0 -43
  112. data/scripts/standard/pathfinder.plot.rb +0 -65
  113. data/scripts/standard/queries.plot.rb +0 -21
  114. data/scripts/standard/test.plot.rb +0 -10
  115. data/scripts/undo.plot.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7395294d50944bd37c3f1876c55c6a946bbcf9ee
4
- data.tar.gz: fdf9b3cbb95019b3279687b987522edc0ff3794f
2
+ SHA256:
3
+ metadata.gz: ce08abec9929267cbcd41b95da9a7bd313e3449ce3160277b26160aadd8437bf
4
+ data.tar.gz: 1e7c8e9827b24816addfec88ff81f1c9d9e8112f9e5422f045a2ef07471375b1
5
5
  SHA512:
6
- metadata.gz: b760a05656461913ac13ce5623c21c30ab8918e8afe822d3365811cb10d0e011064f4e4b7c6055d20c79586dfd395c2b9cfc3b771553d558dcd84cec17091f20
7
- data.tar.gz: 86b311a43a5658c4fad44f8180c56ab5b1b32b5312aa3172d652a890d2c86f07c116010ee0272ddee200a1285df089ee69decabd7d5d21919ea26685a7d108c4
6
+ metadata.gz: 1dc60435ac2e35ed97f76de2d2ba8494c5dad6a54b6aeb943b4767159c866cdd799e21763f29ed1b9360e117a8b2912934ad607b6b343d986cac9c4769d004bd
7
+ data.tar.gz: 76c10bcf57491365f4b61b78f2f076d3bdd9bab43b0d46a6ed838b612c2a7c82026cb6d2ef5d94bc7f0fa817fe364ff3325b1550e8de7bfc49b5e95e47a4d910
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gamefic-sdk'
4
+ require 'gamefic-sdk/shell'
5
+
6
+ Gamefic::Sdk::Shell.start(ARGV)
7
+
8
+ #!/usr/bin/env ruby
9
+
10
+ #require 'gamefic'
11
+ #require 'gamefic-tty'
12
+
13
+ # Make play the default command if the first argument is an existing file
14
+ #args = %w(play help).include?(ARGV[0]) || ARGV.count.zero? || !File.exist?(ARGV[0]) ? ARGV : ARGV.dup.unshift('play')
15
+
16
+ #Gamefic::Tty::Shell.start(args)
@@ -1,30 +1,10 @@
1
1
  require 'gamefic'
2
- require 'gamefic-sdk/platform'
3
- #require 'gamefic-sdk/plot_config'
4
- require 'gamefic-sdk/debug'
5
2
  require 'gamefic-sdk/version'
6
3
 
7
4
  module Gamefic::Sdk
8
5
  autoload :Server, 'gamefic-sdk/server'
9
- autoload :Config, 'gamefic-sdk/config'
10
-
11
- HTML_TEMPLATE_PATH = File.realpath(File.dirname(__FILE__) + "/../html/")
12
- GLOBAL_SCRIPT_PATH = File.realpath(File.dirname(__FILE__) + "/../scripts/")
13
- LIB_PATH = File.dirname(__FILE__)
14
- end
15
-
16
- class Class
17
- def descendants
18
- result = []
19
- ObjectSpace.each_object(::Class) {|klass| result << klass if klass < self }
20
- result
21
- end
22
- end
23
-
24
- class Gamefic::Entity
25
- def self.names
26
- result = []
27
- Entity.descendants.each { |e| result << e.to_s.split('::').last }
28
- result
29
- end
6
+ autoload :Diagram, 'gamefic-sdk/diagram'
7
+ autoload :Scaffold, 'gamefic-sdk/scaffold'
8
+ autoload :Tasks, 'gamefic-sdk/tasks'
9
+ SCAFFOLDS_PATH = File.realpath(File.join(File.dirname(__FILE__), '..', 'scaffolds'))
30
10
  end
@@ -0,0 +1,205 @@
1
+ require 'json'
2
+
3
+ module Gamefic
4
+ module Sdk
5
+ class Diagram
6
+ class Position
7
+ attr_accessor :x, :y
8
+
9
+ def initialize x = 0, y = 0
10
+ @x = x
11
+ @y = y
12
+ freeze
13
+ end
14
+
15
+ def move x, y
16
+ Position.new(self.x + x, self.y + y)
17
+ end
18
+ end
19
+
20
+ # @return [Gamefic::Plot]
21
+ attr_reader :plot
22
+
23
+ def initialize plot
24
+ @plot = plot
25
+ end
26
+
27
+ def get type
28
+ if valid?(type)
29
+ send(type)
30
+ else
31
+ raise ArgumentError, "Unknown diagram type '#{type}'"
32
+ end
33
+ end
34
+
35
+ def verbs
36
+ plot.verbs
37
+ end
38
+
39
+ def rooms
40
+ clear
41
+ position = Position.new
42
+ plot.entities.that_are(Room).each do |room|
43
+ proceed_from room, position
44
+ next_x = right
45
+ next_y = bottom
46
+ if next_x > next_y
47
+ position = Position.new(0, next_y + distance)
48
+ else
49
+ position = Position.new(next_x + distance, 0)
50
+ end
51
+ end
52
+ elements.values
53
+ end
54
+
55
+ def entities
56
+ plot.initial_state[:entities].map do |e|
57
+ e.transform_keys do |k|
58
+ str = k.to_s
59
+ if str.start_with?('@')
60
+ str[1..-1]
61
+ else
62
+ str
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ def actions
69
+ plot.actions.map do |act|
70
+ {
71
+ verb: act.verb,
72
+ meta: act.meta?,
73
+ signature: act.signature
74
+ }
75
+ end
76
+ end
77
+
78
+ def commands
79
+ {
80
+ actions: actions,
81
+ verbs: verbs,
82
+ syntaxes: syntaxes
83
+ }
84
+ end
85
+
86
+ def verbs
87
+ plot.verbs
88
+ end
89
+
90
+ def syntaxes
91
+ plot.syntaxes.map do |syn|
92
+ {
93
+ template: syn.template,
94
+ command: syn.command,
95
+ first_word: syn.first_word,
96
+ verb: syn.verb
97
+ }
98
+ end
99
+ end
100
+
101
+ def valid? type
102
+ %w[rooms entities actions verbs syntaxes commands].include?(type)
103
+ end
104
+
105
+ private
106
+
107
+ def distance
108
+ 150
109
+ end
110
+
111
+ def elements
112
+ @elements ||= {}
113
+ end
114
+
115
+ def entity_uid entity
116
+ raise "Invalid entity" if plot.entities.index(entity).nil?
117
+ "EIN_#{plot.entities.index(entity)}"
118
+ end
119
+
120
+ def proceed_from room, position
121
+ return if elements.has_key?(room)
122
+ directions = ['north', 'south', 'west', 'east', 'northwest', 'northeast', 'southwest', 'southeast']
123
+ rel = { data: {} }
124
+ rel[:data][:id] = entity_uid(room)
125
+ rel[:data][:label] = room.definitely
126
+ rel[:position] = { x: position.x, y: position.y }
127
+ elements[room] = rel
128
+ room.children.that_are(Portal).each do |portal|
129
+ next if portal.destination.nil?
130
+ # For lack of a better way to lay them out, 'up' and 'down' are not
131
+ # treated as specific directions
132
+ if portal.direction.nil? or portal.direction.to_s == 'up' or portal.direction.to_s == 'down'
133
+ direction = directions.shift
134
+ new_pos = move_from(position, direction)
135
+ while position_taken?(new_pos)
136
+ direction = directions.shift
137
+ return if direction.nil?
138
+ new_pos = move_from(position, direction)
139
+ end
140
+ else
141
+ directions.delete portal.direction.to_s
142
+ new_pos = move_from(position, portal.direction.to_s)
143
+ end
144
+ proceed_from portal.destination, new_pos
145
+ pel = { data: {} }
146
+ pel[:data][:id] = entity_uid(portal)
147
+ pel[:data][:source] = entity_uid(room)
148
+ pel[:data][:target] = entity_uid(portal.destination)
149
+ elements[portal] = pel
150
+ end
151
+ end
152
+
153
+ def clear
154
+ elements.clear
155
+ end
156
+
157
+ def bottom
158
+ max_y = 0
159
+ elements.values.each do |el|
160
+ next if el[:position].nil?
161
+ max_y = [max_y, el[:position][:y]].max
162
+ end
163
+ max_y
164
+ end
165
+
166
+ def right
167
+ max_x = 0
168
+ elements.values.each do |el|
169
+ next if el[:position].nil?
170
+ max_x = [max_x, el[:position][:x]].max
171
+ end
172
+ max_x
173
+ end
174
+
175
+ def position_taken?(position)
176
+ elements.values.each do |el|
177
+ next if el[:position].nil?
178
+ return true if el[:position][:x] == position.x and el[:position][:y] == position.y
179
+ end
180
+ false
181
+ end
182
+
183
+ def move_from position, direction
184
+ case direction
185
+ when 'north'
186
+ position.move 0, -distance
187
+ when 'south'
188
+ position.move 0, distance
189
+ when 'west'
190
+ position.move -distance, 0
191
+ when 'east'
192
+ position.move distance, 0
193
+ when 'northwest'
194
+ position.move -distance * 0.5, -distance * 0.5
195
+ when 'northeast'
196
+ position.move distance * 0.5, -distance * 0.5
197
+ when 'southwest'
198
+ position.move -distance * 0.5, distance * 0.5
199
+ when 'southeast'
200
+ position.move distance * 0.5, distance * 0.5
201
+ end
202
+ end
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,54 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+ require 'pathname'
4
+ require 'securerandom'
5
+ require 'shellwords'
6
+
7
+ module Gamefic
8
+ module Sdk
9
+ module Scaffold
10
+ class Binder < OpenStruct
11
+ def get_binding
12
+ binding()
13
+ end
14
+ end
15
+
16
+ module_function
17
+
18
+ def render(file, data)
19
+ template = File.read(file)
20
+ erb = ERB.new(template)
21
+ erb.result(data.get_binding)
22
+ end
23
+
24
+ def custom_copy origin, destination, data
25
+ FileUtils.mkdir_p File.dirname(destination)
26
+ if destination.end_with?('.gf.erb')
27
+ File.write destination[0..-8], render(origin, data)
28
+ else
29
+ FileUtils.cp_r origin, destination
30
+ end
31
+ end
32
+
33
+ def build name, destination
34
+ dir = File.join(SCAFFOLDS_PATH, name)
35
+ raise LoadError, "Scaffold `#{name}` does not exist" unless File.directory?(dir)
36
+ path = Pathname.new('.').join(destination).realdirpath
37
+ data = Binder.new(name: File.basename(path))
38
+ files = Dir.glob(File.join(dir, '**', '*'), File::FNM_DOTMATCH).select { |entry| File.file?(entry) }
39
+ map = {}
40
+ files.each do |file|
41
+ rename = File.join(File.dirname(file), File.basename(file).gsub('__name__', data.name))
42
+ dst = File.join(destination, rename[dir.length..-1])
43
+ if File.file?(dst)
44
+ raise "Gamefic generation would overwrite existing file #{rename}"
45
+ else
46
+ map[file] = dst
47
+ end
48
+ end
49
+ map.each_pair { |src, dst| custom_copy src, dst, data }
50
+ system "bundle install --gemfile=#{Shellwords.escape(File.join(destination, 'Gemfile'))}"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,65 +1,81 @@
1
- require 'sinatra/base'
2
- require 'yaml'
3
-
4
- module Gamefic
5
- module Sdk
6
-
7
- class Server < Sinatra::Base
8
- set :port, 4342
9
-
10
- get '/' do
11
- config = Gamefic::Sdk::Config.load(settings.source_dir)
12
- paths = [config.script_path, config.import_path, Gamefic::Sdk::GLOBAL_SCRIPT_PATH]
13
- @@plot = Gamefic::Sdk::Debug::Plot.new Source::File.new(*paths)
14
- @@plot.script 'main'
15
- #@@plot.script 'debug'
16
- sinatra = Gamefic::Sdk::Platform::Sinatra.new(config: config)
17
- sinatra.build
18
- File.read File.join(sinatra.release_target, 'index.html')
19
- end
20
-
21
- post '/start' do
22
- content_type :json
23
- @@character = @@plot.player_class.new(name: 'player', synonyms: 'me myself self you yourself', description: 'As good-looking as ever.')
24
- @@plot.introduce @@character
25
- @@plot.ready
26
- @@character.state.to_json
27
- end
28
-
29
- post '/update' do
30
- content_type :json
31
- @@character.queue.push params['command']
32
- @@plot.update
33
- @@plot.ready
34
- @@character.state.merge(input: params['command']).to_json
35
- end
36
-
37
- post '/restore' do
38
- content_type :json
39
- snapshot = JSON.parse(params['snapshot'], symbolize_names: true)
40
- @@plot.restore snapshot
41
- @@character.cue @@plot.default_scene
42
- @@plot.update
43
- @@plot.ready
44
- @@character.state.to_json
45
- end
46
-
47
- class << self
48
-
49
- def run!
50
- start_browser if settings.browser
51
- super
52
- end
53
-
54
- def start_browser
55
- Thread.new {
56
- sleep 1 until Server.running?
57
- `start http://localhost:#{settings.port}`
58
- }
59
- end
60
-
61
- end
62
- end
63
-
64
- end
65
- end
1
+ require 'sinatra/base'
2
+ require 'yaml'
3
+
4
+ module Gamefic
5
+ module Sdk
6
+ class Server < Sinatra::Base
7
+ set :port, 4342
8
+ set :server, :webrick
9
+
10
+ get '/' do
11
+ File.read File.join(settings.public_folder, 'index.html')
12
+ end
13
+
14
+ post '/start' do
15
+ content_type :json
16
+ reset_features
17
+ load File.join(settings.source_dir, 'main.rb')
18
+ @@plot = Gamefic::Plot.new
19
+ @@character = @@plot.get_player_character
20
+ @@plot.introduce @@character
21
+ @@plot.ready
22
+ @@character.output.to_json
23
+ end
24
+
25
+ post '/receive' do
26
+ content_type :json
27
+ @@character.queue.push params['command']
28
+ {}.to_json
29
+ end
30
+
31
+ post '/update' do
32
+ content_type :json
33
+ @@plot.update
34
+ @@plot.ready
35
+ # @@character.state.merge(input: params['command'], continued: @@character.queue.any?).to_json
36
+ @@character.output.to_json
37
+ end
38
+
39
+ get '/snapshot' do
40
+ content_type :json
41
+ @@plot.save.to_json
42
+ end
43
+
44
+ post '/restore' do
45
+ content_type :json
46
+ # The snapshot needs to be received as a JSON string because of issues
47
+ # with IndifferentHash malforming arrays.
48
+ snapshot = JSON.parse(params['snapshot'], symbolize_names: true)
49
+ @@plot.restore snapshot
50
+ @@character.cue @@plot.default_scene
51
+ @@plot.update
52
+ @@plot.ready
53
+ @@character.output.to_json
54
+ end
55
+
56
+ def reset_features
57
+ @@old_features ||= $LOADED_FEATURES.clone
58
+ @@old_constants ||= Object.constants(false)
59
+ $LOADED_FEATURES.keep_if { |e| @@old_features.include?(e) }
60
+ Object.constants(false).each do |const|
61
+ Object.send(:remove_const, const) unless @@old_constants.include?(const)
62
+ end
63
+ Gamefic::Plot.blocks.clear
64
+ end
65
+
66
+ class << self
67
+ # def run!
68
+ # start_browser if settings.browser
69
+ # super
70
+ # end
71
+
72
+ # def start_browser
73
+ # Thread.new {
74
+ # sleep 1 until Server.running?
75
+ # `start http://localhost:#{settings.port}`
76
+ # }
77
+ # end
78
+ end
79
+ end
80
+ end
81
+ end