gamefic-sdk 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61acd296a500629ea97c6e31db00b4c966aa975d
4
+ data.tar.gz: cbe43ae8d137c1708f7a65c008230f534bf1a3d6
5
+ SHA512:
6
+ metadata.gz: 1ed83278eacd87d0582a3f0bf9cd8097b9b9425a1f2f4b6ace6514bd9c6873cfeff95d33987307fd8944c3b46f5a05df9481d57ee876107b11064674398e29f1
7
+ data.tar.gz: 250a6098b55a035e05141758ee2115a72afacb1ae6342b7f91fbfbecd1d2ffec5611ed6e2480caa1fab43a642bb8c77a3b0f245a10d0b5b6e1acda0e12f3f582
data/bin/gfk ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gamefic'
4
+ require 'gamefic-sdk'
5
+
6
+ shell = Gamefic::Sdk::Gfk.new
7
+ shell.execute
@@ -0,0 +1,10 @@
1
+ javascripts.push "core/opal.js"
2
+ javascripts.push "core/gamefic.js"
3
+ javascripts.push "core/static.js"
4
+ javascripts.push "core/scripts.js"
5
+ javascripts.push "core/engine.js"
6
+ javascripts.push "core/jquery.js"
7
+
8
+ javascripts.push "play.js"
9
+
10
+ stylesheets.push "style.css"
@@ -0,0 +1,28 @@
1
+ require 'gamefic'
2
+ require 'gamefic-sdk/gfk'
3
+ require 'gamefic-sdk/platform'
4
+ require 'gamefic-sdk/plot_config'
5
+
6
+ module Gamefic::Sdk
7
+ HTML_TEMPLATE_PATH = File.dirname(__FILE__) + "/../html/"
8
+ GLOBAL_SCRIPT_PATH = File.dirname(__FILE__) + "/../scripts/"
9
+ # @deprecated
10
+ GLOBAL_IMPORT_PATH = GLOBAL_SCRIPT_PATH
11
+ LIB_PATH = File.dirname(__FILE__)
12
+ end
13
+
14
+ class Class
15
+ def descendants
16
+ result = []
17
+ ObjectSpace.each_object(::Class) {|klass| result << klass if klass < self }
18
+ result
19
+ end
20
+ end
21
+
22
+ class Entity
23
+ def self.names
24
+ result = []
25
+ Entity.descendants.each { |e| result << e.to_s.split('::').last }
26
+ result
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ require 'yaml'
2
+
3
+ module Gamefic::Sdk
4
+
5
+ module Build
6
+ def self.release directory
7
+ config = YAML.load(File.read("#{directory}/config.yaml"))
8
+ if File.file?("#{directory}/.uuid")
9
+ config['uuid'] = File.read("#{directory}/.uuid").strip
10
+ end
11
+ platforms = YAML.load(File.read("#{directory}/build.yaml"))
12
+ platforms.each_pair { |k, v|
13
+ v['name'] = k
14
+ cls = Gamefic::Sdk::Platform.const_get(v['platform'])
15
+ plat = cls.new(directory, v)
16
+ puts "Building #{k}..." #unless quiet
17
+ plat.build
18
+ }
19
+ puts "Build#{platforms.length > 1 ? 's' : ''} complete." #unless quiet
20
+ end
21
+ def self.clean directory, config
22
+ config.each_pair { |k, v|
23
+ v['name'] = k
24
+ puts "Cleaning #{k}..."
25
+ build_dir = "#{directory}/build/#{k}"
26
+ platform_dir = "#{directory}/release/#{k}"
27
+ cls = Gamefic::Sdk::Platform.const_get(v['platform'])
28
+ plat = cls.new(directory, v)
29
+ plat.clean
30
+ }
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,5 @@
1
+ module Gamefic::Sdk::Debug
2
+ autoload :Plot, 'gamefic-sdk/debug/plot'
3
+ autoload :Action, 'gamefic-sdk/debug/action'
4
+ autoload :Meta, 'gamefic-sdk/debug/meta'
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'gamefic'
2
+
3
+ module Gamefic::Sdk
4
+ module Debug
5
+ class Action < Gamefic::Action
6
+ attr_reader :source_location
7
+ def initialize(story, command, *queries, &proc)
8
+ super
9
+ @executed = false
10
+ caller.each { |c|
11
+ if c.end_with?(":in `stage'")
12
+ @source_location = c[0..-12]
13
+ break
14
+ end
15
+ }
16
+ end
17
+ def execute *args
18
+ super
19
+ @executed = true
20
+ end
21
+ def executed?
22
+ @executed
23
+ end
24
+ def standard?
25
+ return false if source_location.nil?
26
+ source_location.start_with?(Gamefic::Sdk::GLOBAL_IMPORT_PATH)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ require 'gamefic'
2
+
3
+ module Gamefic::Sdk::Debug
4
+ class Plot < Gamefic::Plot
5
+ attr_reader :main_dir
6
+ def post_initialize
7
+ meta :debug, Query::Text.new("unused") do |actor, text|
8
+ unused = []
9
+ actions.each { |a|
10
+ if !a.standard? and !a.executed?
11
+ unused.push "#{a.verb}:#{a.source_location}"
12
+ end
13
+ }
14
+ actor.tell "#{unused.join("\r\n")}"
15
+ end
16
+ end
17
+ def action(command, *queries, &proc)
18
+ Gamefic::Sdk::Debug::Action.new(self, command, *queries, &proc)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,244 @@
1
+ require 'tmpdir'
2
+ require 'zip'
3
+ require 'getoptlong'
4
+ require 'gamefic/engine/tty'
5
+ require 'gamefic-sdk'
6
+ require 'gamefic-sdk/build'
7
+ require 'securerandom'
8
+ require 'gamefic-sdk/debug'
9
+
10
+ include Gamefic
11
+
12
+ module Gamefic::Sdk
13
+ class Gfk
14
+ attr_accessor :argv
15
+ def initialize
16
+
17
+ end
18
+ def execute
19
+ if ARGV.length == 0
20
+ ARGV.push 'help'
21
+ end
22
+ cmd = ARGV.shift
23
+ case cmd
24
+ when 'test'
25
+ test ARGV.shift
26
+ when 'init'
27
+ init ARGV.shift
28
+ when 'build'
29
+ build ARGV.shift
30
+ when 'clean'
31
+ clean ARGV.shift
32
+ when 'fetch'
33
+ fetch ARGV.shift
34
+ when 'help'
35
+ help ARGV.shift
36
+ else
37
+ help nil
38
+ end
39
+ end
40
+ private
41
+ def test path
42
+ puts "Loading..."
43
+ STDOUT.flush
44
+ if !File.exist?(path)
45
+ raise "Invalid path: #{path}"
46
+ end
47
+ build_file = nil
48
+ main_file = path
49
+ test_file = nil
50
+ if File.directory?(path)
51
+ config = PlotConfig.new "#{path}/config.yaml"
52
+ else
53
+ config = PlotConfig.new
54
+ end
55
+ paths = config.script_paths + [Gamefic::Sdk::GLOBAL_SCRIPT_PATH]
56
+ plot = Gamefic::Sdk::Debug::Plot.new Source::File.new(*paths)
57
+ plot.script 'main'
58
+ plot.script 'debug'
59
+ engine = Tty::Engine.new plot
60
+ puts "\n"
61
+ engine.run
62
+ end
63
+ def init directory
64
+ quiet = false
65
+ html = nil
66
+ imports = []
67
+ opts = GetoptLong.new(
68
+ [ '-q', '--quiet', GetoptLong::NO_ARGUMENT ],
69
+ [ '--with-html', GetoptLong::REQUIRED_ARGUMENT ],
70
+ [ '-i', '--import', GetoptLong::REQUIRED_ARGUMENT ]
71
+ )
72
+ begin
73
+ opts.each { |opt, arg|
74
+ case opt
75
+ when '-q'
76
+ quiet = true
77
+ when '--with-html'
78
+ html = arg
79
+ when '-i'
80
+ imports = arg.split(';')
81
+ end
82
+ }
83
+ rescue Exception => e
84
+ puts "#{e}"
85
+ exit 1
86
+ end
87
+ if directory.to_s == ''
88
+ puts "No directory specified."
89
+ exit 1
90
+ elsif File.exist?(directory)
91
+ if File.directory?(directory)
92
+ files = Dir[directory + '/*']
93
+ if files.length > 0
94
+ dotfiles = Dir[directory + '/\.*']
95
+ if dotfiles.length < files.length
96
+ puts "'#{directory}' is not an empty directory."
97
+ exit 1
98
+ end
99
+ end
100
+ else
101
+ puts "'#{directory}' is a file."
102
+ exit 1
103
+ end
104
+ else
105
+ Dir.mkdir(directory)
106
+ end
107
+ Dir.mkdir(directory + '/scripts')
108
+ main_rb = File.new(directory + '/scripts/main.plot.rb', 'w')
109
+ main_rb.write <<EOS
110
+ script 'standard'
111
+ EOS
112
+ imports.each { |i|
113
+ main_rb.write "require '#{i}'\n"
114
+ }
115
+ main_rb.close
116
+ test_rb = File.new(directory + '/scripts/test.plot.rb', 'w')
117
+ test_rb.write <<EOS
118
+ script 'standard/test'
119
+ EOS
120
+ test_rb.close
121
+ build_rb = File.new(directory + '/build.yaml', 'w')
122
+ build_rb.write <<EOS
123
+ web:
124
+ platform: Web
125
+ gfic:
126
+ platform: Gfic
127
+ EOS
128
+ build_rb.close
129
+ config_rb = File.new(directory + '/config.yaml', 'w')
130
+ config_rb.write <<EOS
131
+ title: Untitled
132
+ author: Anonymous
133
+
134
+ script_paths:
135
+ - ./scripts
136
+ asset_paths:
137
+ - ./assets
138
+ EOS
139
+ config_rb.close
140
+ Dir.mkdir(directory + '/html')
141
+ if !html.nil?
142
+ FileUtils.cp_r(Dir[Gamefic::Sdk::HTML_TEMPLATE_PATH + "/core/*"], directory + "/html")
143
+ FileUtils.cp_r(Dir[Gamefic::Sdk::HTML_TEMPLATE_PATH + "/skins/" + html + "/*"], directory + "/html")
144
+ end
145
+ uuid = SecureRandom.uuid
146
+ File.open("#{directory}/.uuid", "w") { |f| f.write uuid }
147
+ puts "Game directory '#{directory}' initialized." unless quiet
148
+ end
149
+ def fetch directory
150
+ if directory.to_s == ''
151
+ puts "No source directory was specified."
152
+ exit 1
153
+ end
154
+ if !File.directory?(directory)
155
+ puts "#{directory} is not a directory."
156
+ exit 1
157
+ end
158
+ puts "Loading game data..."
159
+ story = Plot.new(Source.new(GLOBAL_SCRIPT_PATH))
160
+ begin
161
+ story.load directory + '/main', true
162
+ rescue Exception => e
163
+ puts "'#{directory}' has errors or is not a valid source directory."
164
+ puts "#{e}"
165
+ exit 1
166
+ end
167
+ puts "Checking for external script references..."
168
+ fetched = 0
169
+ story.imported_scripts.each { |script|
170
+ if !script.filename.start_with?(directory)
171
+ base = script.filename[(script.filename.rindex('scripts/') + 7)..-1]
172
+ puts "Fetching #{base}"
173
+ FileUtils.mkdir_p directory + '/scripts/' + File.dirname(base)
174
+ FileUtils.copy script.filename, directory + '/scripts/' + base
175
+ fetched += 1
176
+ end
177
+ }
178
+ if fetched == 0
179
+ puts "Nothing to fetch."
180
+ else
181
+ puts "Done."
182
+ end
183
+ end
184
+ def build directory
185
+ Build.release directory
186
+ end
187
+ def clean directory
188
+ config = YAML.load(File.read(directory + '/build.yaml'))
189
+ Build.clean directory, config
190
+ end
191
+ def help command
192
+ shell_script = File.basename($0)
193
+ case command
194
+ when "test"
195
+ puts <<EOS
196
+ #{shell_script} test [path]
197
+ Test a Gamefic source directory or script.
198
+ EOS
199
+ when "init"
200
+ puts <<EOS
201
+ #{shell_script} init [directory]
202
+ Initialize a Gamefic source directory. The resulting directory will contain
203
+ source files ready to build into a Gamefic file.
204
+ EOS
205
+ when "fetch"
206
+ puts <<EOS
207
+ #{shell_script} fetch [directory]
208
+ Copy shared scripts to the source directory.
209
+ If the specified game directory imports external scripts, such as the ones
210
+ that are distributed with the Gamefic gem, this command will copy them into
211
+ the game's script directory. Fetching can be useful if you want to customize
212
+ common features.
213
+ EOS
214
+ when "build"
215
+ puts <<EOS
216
+ #{shell_script} build [directory] [-o | --output filename]
217
+ Build a distributable Gamefic file from the source directory. The default
218
+ filename is [directory].gfic. You can change the filename with the -o option.
219
+ EOS
220
+ when "clean"
221
+ puts <<EOS
222
+ #{shell_script} clean [directory]
223
+ Clean Gamefic source directories. This command will delete any intermediate
224
+ files that are used during the build process. The next build will rebuild
225
+ everything from source.
226
+ EOS
227
+ when nil, "help"
228
+ puts <<EOS
229
+ #{shell_script} init [directory] - initialize a Gamefic source directory
230
+ #{shell_script} test [path] - test a Gamefic source directory or script
231
+ #{shell_script} fetch [directory] - copy shared scripts into directory
232
+ #{shell_script} build [directory] - build games
233
+ #{shell_script} build [directory] - clean game directories
234
+ #{shell_script} help - display this message
235
+ #{shell_script} help [command] - display info about command
236
+ EOS
237
+ else
238
+ puts "Unrecognized command '#{command}'"
239
+ exit 1
240
+ end
241
+ end
242
+ end
243
+
244
+ end
@@ -0,0 +1,9 @@
1
+ module Gamefic::Sdk
2
+
3
+ module Platform
4
+ autoload :Base, 'gamefic-sdk/platform/base'
5
+ autoload :Gfic, 'gamefic-sdk/platform/gfic'
6
+ autoload :Web, 'gamefic-sdk/platform/web'
7
+ end
8
+
9
+ end
@@ -0,0 +1,48 @@
1
+ require 'gamefic-sdk'
2
+ require 'gamefic-sdk/debug/plot'
3
+
4
+ module Gamefic::Sdk
5
+ class Platform::Base
6
+ # @return [Gamefic::Sdk::Debug::Plot]
7
+ attr_reader :source_dir
8
+
9
+ # @return [Hash]
10
+ attr_reader :config
11
+
12
+ def initialize source_dir, config = {}
13
+ @source_dir = source_dir
14
+ @config = defaults.merge(config)
15
+ @config['target_dir'] ||= "release/#{config['name'] || self.class.to_s.split("::").last}"
16
+ @config['build_dir'] ||= "build/#{config['name'] || self.class.to_s.split("::").last}"
17
+ # Convert config directories into absolute paths
18
+ @config['target_dir'] = File.absolute_path(@config['target_dir'], source_dir)
19
+ @config['build_dir'] = File.absolute_path(@config['build_dir'], source_dir)
20
+ end
21
+
22
+ def plot
23
+ if @plot.nil?
24
+ config = PlotConfig.new "#{source_dir}/config.yaml"
25
+ paths = config.script_paths + [Gamefic::Sdk::GLOBAL_SCRIPT_PATH]
26
+ @plot = Gamefic::Sdk::Debug::Plot.new(Gamefic::Source::File.new(*paths))
27
+ @plot.script 'main'
28
+ end
29
+ @plot
30
+ end
31
+
32
+ # Get a hash of default configuration values.
33
+ # Platforms can overload this method to define their own defaults.
34
+ # @return [Hash]
35
+ def defaults
36
+ @defaults ||= Hash.new
37
+ end
38
+
39
+ def build
40
+ # Platforms need to build/compile the deployment here.
41
+ raise "The base Platform class does not have a build method"
42
+ end
43
+
44
+ def clean
45
+ puts "Nothing to do for this platform."
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,33 @@
1
+ require 'zip'
2
+
3
+ module Gamefic::Sdk
4
+
5
+ class Platform::Gfic < Platform::Base
6
+ def defaults
7
+ @defaults ||= {
8
+ :filename => nil,
9
+ :with_html => true,
10
+ :with_media => true
11
+ }
12
+ end
13
+ def build
14
+ target_dir = config['target_dir']
15
+ if config['filename'].to_s == ''
16
+ filename = target_dir + '/' + source_dir.split('/').delete_if{|i| i.to_s == ''}.last + '.gfic'
17
+ else
18
+ filename = "#{target_dir}/#{config['filename']}"
19
+ end
20
+ stream = StringIO.new("")
21
+ FileUtils.rm filename if File.file?(filename)
22
+ FileUtils.mkdir_p target_dir
23
+ Zip::File.open(filename, Zip::File::CREATE) do |zipfile|
24
+ if plot.imported_scripts.length > 0
25
+ plot.imported_scripts.each { |script|
26
+ zipfile.add "scripts/#{script.path}", script.absolute_path
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,130 @@
1
+ require 'gamefic'
2
+ require 'gamefic-sdk'
3
+ require 'opal'
4
+
5
+ module Gamefic::Sdk
6
+
7
+ class Platform::Web < Platform::Base
8
+ autoload :AppConfig, 'gamefic-sdk/platform/web/app_config'
9
+
10
+ def defaults
11
+ @defaults ||= {
12
+ :html_skin => 'multimedia',
13
+ :with_media => true
14
+ }
15
+ end
16
+
17
+ def build
18
+ target_dir = config['target_dir']
19
+ # TODO Configurable build folder?
20
+ build_dir = config['build_dir']
21
+ html_dir = resolve_html_dir
22
+ app_config = AppConfig.new html_dir
23
+
24
+ FileUtils.mkdir_p target_dir
25
+
26
+ # Copy everything in source except config and template
27
+ Dir.entries(html_dir).each { |entry|
28
+ if entry != 'config.rb' and entry != 'index.html.erb' and entry != '.' and entry != '..'
29
+ FileUtils.mkdir_p target_dir + File.dirname(entry)
30
+ FileUtils.cp_r "#{html_dir}/#{entry}", "#{target_dir}/#{entry}"
31
+ end
32
+ }
33
+
34
+ # Make sure core exists in build directory
35
+ FileUtils.mkdir_p build_dir + "/core"
36
+
37
+ # Opal core
38
+ if !File.exist?(build_dir + "/core/opal.js")
39
+ File.open(build_dir + "/core/opal.js", "w") do |file|
40
+ file << Opal::Builder.build('opal')
41
+ file << Opal::Builder.build('json')
42
+ file << Opal::Builder.build('native')
43
+ end
44
+ end
45
+
46
+ # Gamefic core
47
+ Opal.append_path Gamefic::Sdk::LIB_PATH
48
+ if !File.exist?(build_dir + "/core/gamefic.js")
49
+ File.open(build_dir + "/core/gamefic.js", "w") do |file|
50
+ file << Opal::Builder.build('gamefic').to_s
51
+ end
52
+ end
53
+
54
+ # GameficOpal
55
+ if !File.exist?(build_dir + "/core/static.js")
56
+ File.open(build_dir + "/core/static.js", "w") do |file|
57
+ file << Opal::Builder.build('gamefic-sdk/platform/web/gamefic_opal')
58
+ end
59
+ end
60
+
61
+ # Plot scripts
62
+ File.open("#{build_dir}/scripts.rb", 'w') do |file|
63
+ file << "def GameficOpal.load_scripts\n"
64
+ plot.imported_scripts.each { |script|
65
+ file << "GameficOpal.static_plot.stage do\n"
66
+ file << script.read
67
+ file << "\nend\n"
68
+ }
69
+ file << "end\n"
70
+ end
71
+ Opal.append_path build_dir
72
+ File.open(build_dir + "/core/scripts.js", 'w') do |file|
73
+ file << Opal::Builder.build('scripts')
74
+ end
75
+
76
+ # Render index
77
+ File.open(target_dir + "/index.html", "w") do |file|
78
+ file << app_config.render
79
+ end
80
+
81
+ # Copy requisite assets
82
+ app_config.resource_paths.push build_dir
83
+ app_config.javascripts.each { |js|
84
+ absolute = resolve(js, app_config.resource_paths)
85
+ FileUtils.mkdir_p target_dir + "/" + File.dirname(js)
86
+ FileUtils.cp_r absolute, target_dir + "/" + js
87
+ }
88
+ app_config.stylesheets.each { |css|
89
+ absolute = resolve(css, app_config.resource_paths)
90
+ FileUtils.mkdir_p target_dir + "/" + File.dirname(css)
91
+ FileUtils.cp_r absolute, target_dir + "/" + css
92
+ }
93
+ end
94
+
95
+ def clean
96
+ FileUtils.remove_entry_secure config['build_dir'] if File.exist?(config['build_dir'])
97
+ FileUtils.mkdir_p config['build_dir']
98
+ puts "#{config['build_dir']} cleaned."
99
+ end
100
+
101
+ private
102
+
103
+ def resolve filename, paths
104
+ absolute = nil
105
+ paths.each { |path|
106
+ if File.file?("#{path}/#{filename}")
107
+ absolute = "#{path}/#{filename}"
108
+ break
109
+ end
110
+ }
111
+ raise "#{filename} not found" if absolute.nil?
112
+ absolute
113
+ end
114
+
115
+ def resolve_html_dir
116
+ html_dir = "#{source_dir}/html"
117
+ if !File.directory?(html_dir) and config['html_skin'].to_s != ''
118
+ html_dir = "#{Gamefic::Sdk::HTML_TEMPLATE_PATH}/skins/#{config['html_skin']}"
119
+ end
120
+ if !File.directory?(html_dir)
121
+ html_dir = "#{Gamefic::Sdk::HTML_TEMPLATE_PATH}/skins/minimal"
122
+ end
123
+ if !File.directory?(html_dir)
124
+ raise "Could not resolve HTML directory"
125
+ end
126
+ html_dir
127
+ end
128
+ end
129
+
130
+ end
@@ -0,0 +1,56 @@
1
+ require 'erb'
2
+ require 'gamefic/stage'
3
+
4
+ class Gamefic::Sdk::Platform::Web::AppConfig
5
+ include Stage
6
+ attr_reader :javascripts, :stylesheets, :resource_paths
7
+ expose :javascripts, :stylesheets, :resource_paths
8
+
9
+ # @param main_dir [String] The directory containing the resources (config file, HTML template, etc.) for this build
10
+ def initialize source_dir
11
+ @javascripts = []
12
+ @stylesheets = []
13
+ @source_dir = source_dir
14
+ @resource_paths = ["#{source_dir}", Gamefic::Sdk::HTML_TEMPLATE_PATH]
15
+ config_file = "#{source_dir}/config.rb"
16
+ stage File.read(config_file), config_file
17
+ end
18
+
19
+ # @return [BuildConfig::Data]
20
+ def data
21
+ Data.new @javascripts, @stylesheets
22
+ end
23
+
24
+ # Render HTML using the build config data
25
+ #
26
+ # @return [String] The resulting HTML
27
+ def render
28
+ erb = ERB.new(File.read(@source_dir + "/index.html.erb"))
29
+ erb.result data.get_binding
30
+ end
31
+ end
32
+
33
+ class Gamefic::Sdk::Platform::Web::AppConfig::Data
34
+ attr_reader :javascripts, :stylesheets
35
+ def initialize javascripts, stylesheets
36
+ @javascripts = javascripts
37
+ @stylesheets = stylesheets
38
+ end
39
+ def javascript_tags
40
+ result = ""
41
+ javascripts.each { |js|
42
+ result += "<script type=\"text/javascript\" src=\"#{js}\"></script>"
43
+ }
44
+ result
45
+ end
46
+ def stylesheet_tags
47
+ result = ""
48
+ stylesheets.each { |css|
49
+ result += "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{css}\" />"
50
+ }
51
+ result
52
+ end
53
+ def get_binding
54
+ binding()
55
+ end
56
+ end
@@ -0,0 +1,36 @@
1
+ # HACK Explicit requires to fix Opal's failure to resolve autoloads
2
+ require 'gamefic/query/expression'
3
+ require 'gamefic/query/matches'
4
+ require 'gamefic/grammar/verb_set'
5
+
6
+ # HACK Opal doesn't recognizes classes and modules declared from scripts
7
+ def Object.const_missing sym
8
+ Gamefic.const_get sym
9
+ end
10
+
11
+ module GameficOpal
12
+ def self.static_plot
13
+ @@static_plot ||= WebPlot.new(Gamefic::Source::Text.new)
14
+ end
15
+ def self.static_player
16
+ @@static_player ||= WebUser.new(GameficOpal.static_plot)
17
+ end
18
+
19
+ class WebPlot < Gamefic::Plot
20
+ def script path
21
+ # Stub
22
+ end
23
+ end
24
+
25
+ class WebUser < Gamefic::User
26
+ def save filename, data
27
+ `Gamefic.Engine.save(filename, data);`
28
+ end
29
+ def restore filename
30
+ data = `Gamefic.Engine.restore(filename);`
31
+ return data
32
+ end
33
+ end
34
+ end
35
+
36
+ GameficOpal.static_plot.script 'main'
@@ -0,0 +1,25 @@
1
+ require 'yaml'
2
+
3
+ module Gamefic
4
+
5
+ class PlotConfig
6
+ attr_reader :author, :title, :script_paths, :asset_paths
7
+ def initialize filename = nil
8
+ @script_paths = []
9
+ @asset_paths = []
10
+ if !filename.nil?
11
+ config = YAML.load_file filename
12
+ base_dir = File.dirname(filename)
13
+ @author = config['author']
14
+ @title = config['title']
15
+ config['script_paths'].each { |p|
16
+ @script_paths.push File.absolute_path(p, base_dir)
17
+ } if !config['script_paths'].nil?
18
+ config['asset_paths'].map! { |p|
19
+ @asset_paths.push File.absolute_path(p, base_dir)
20
+ } if !config['asset_paths'].nil?
21
+ end
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,5 @@
1
+ module Gamefic
2
+ module Sdk
3
+ VERSION = '0.3.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gamefic-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Fred Snyder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gamefic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: opal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Development tools for Gamefic
56
+ email: fsnyder@gamefic.com
57
+ executables:
58
+ - gfk
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/gamefic-sdk.rb
63
+ - lib/gamefic-sdk/platform/base.rb
64
+ - lib/gamefic-sdk/platform/gfic.rb
65
+ - lib/gamefic-sdk/platform/web.rb
66
+ - lib/gamefic-sdk/platform/web/app_config.rb
67
+ - lib/gamefic-sdk/platform/web/gamefic_opal.rb
68
+ - lib/gamefic-sdk/plot_config.rb
69
+ - lib/gamefic-sdk/version.rb
70
+ - lib/gamefic-sdk/debug.rb
71
+ - lib/gamefic-sdk/debug/action.rb
72
+ - lib/gamefic-sdk/debug/plot.rb
73
+ - lib/gamefic-sdk/build.rb
74
+ - lib/gamefic-sdk/gfk.rb
75
+ - lib/gamefic-sdk/platform.rb
76
+ - html/skins/minimal/config.rb
77
+ - bin/gfk
78
+ homepage: http://gamefic.com
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: 1.9.3
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.14
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Gamefic SDK
102
+ test_files: []
103
+ has_rdoc: