gamefic-sdk 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/html/core/engine.js +89 -20
  3. data/html/sinatra/engine.js +27 -13
  4. data/html/skins/hypertext/index.html +0 -2
  5. data/html/skins/standard/play.js +0 -66
  6. data/lib/gamefic-sdk.rb +2 -1
  7. data/lib/gamefic-sdk/build.rb +11 -19
  8. data/lib/gamefic-sdk/config.rb +126 -0
  9. data/lib/gamefic-sdk/platform.rb +12 -0
  10. data/lib/gamefic-sdk/platform/base.rb +35 -33
  11. data/lib/gamefic-sdk/platform/gfic.rb +5 -18
  12. data/lib/gamefic-sdk/platform/sinatra.rb +29 -31
  13. data/lib/gamefic-sdk/platform/web.rb +72 -65
  14. data/lib/gamefic-sdk/platform/web/app_config.rb +48 -48
  15. data/lib/gamefic-sdk/platform/web/engine.rb +10 -7
  16. data/lib/gamefic-sdk/platform/web/user.rb +3 -3
  17. data/lib/gamefic-sdk/server.rb +17 -19
  18. data/lib/gamefic-sdk/shell.rb +68 -16
  19. data/lib/gamefic-sdk/shell/init.rb +3 -19
  20. data/lib/gamefic-sdk/shell/test.rb +9 -14
  21. data/lib/gamefic-sdk/version.rb +1 -1
  22. data/scripts/save-restore-undo.plot.rb +25 -0
  23. data/scripts/snapshots.plot.rb +16 -14
  24. data/scripts/standard.plot.rb +3 -5
  25. data/scripts/standard/actions.plot.rb +1 -11
  26. data/scripts/standard/actions/drop.plot.rb +1 -1
  27. data/scripts/standard/actions/enter.plot.rb +4 -16
  28. data/scripts/standard/actions/go.plot.rb +2 -36
  29. data/scripts/standard/actions/insert.plot.rb +7 -21
  30. data/scripts/standard/actions/inventory.plot.rb +2 -1
  31. data/scripts/standard/actions/leave.plot.rb +7 -18
  32. data/scripts/standard/actions/look.plot.rb +45 -44
  33. data/scripts/standard/actions/nil.plot.rb +1 -1
  34. data/scripts/standard/actions/take.plot.rb +10 -28
  35. data/scripts/standard/actions/talk.plot.rb +9 -13
  36. data/scripts/standard/clothing.plot.rb +4 -0
  37. data/scripts/standard/clothing/actions.plot.rb +4 -0
  38. data/scripts/{clothing → standard/clothing}/actions/doff.plot.rb +0 -0
  39. data/scripts/{clothing → standard/clothing}/actions/drop.plot.rb +8 -8
  40. data/scripts/{clothing → standard/clothing}/actions/inventory.plot.rb +14 -14
  41. data/scripts/standard/clothing/actions/wear.plot.rb +20 -0
  42. data/scripts/standard/clothing/entities.plot.rb +7 -0
  43. data/scripts/{clothing → standard/clothing}/entities/clothing.plot.rb +0 -2
  44. data/scripts/standard/clothing/entities/coat.plot.rb +3 -0
  45. data/scripts/standard/clothing/entities/gloves.plot.rb +3 -0
  46. data/scripts/standard/clothing/entities/hat.plot.rb +3 -0
  47. data/scripts/standard/clothing/entities/pants.plot.rb +3 -0
  48. data/scripts/standard/clothing/entities/shirt.plot.rb +3 -0
  49. data/scripts/standard/clothing/entities/shoes.plot.rb +3 -0
  50. data/scripts/standard/container.plot.rb +28 -0
  51. data/scripts/{debug.plot.rb → standard/container/actions.plot.rb} +0 -0
  52. data/scripts/standard/container/entities.plot.rb +5 -0
  53. data/scripts/standard/direction.plot.rb +1 -2
  54. data/scripts/{edible.plot.rb → standard/edible.plot.rb} +5 -3
  55. data/scripts/standard/entities.plot.rb +3 -3
  56. data/scripts/standard/entities/character.plot.rb +9 -6
  57. data/scripts/standard/entities/fixture.plot.rb +1 -1
  58. data/scripts/standard/entities/item.plot.rb +2 -4
  59. data/scripts/standard/entities/portal.plot.rb +9 -5
  60. data/scripts/standard/entities/receptacle.plot.rb +1 -1
  61. data/scripts/standard/entities/room.plot.rb +5 -5
  62. data/scripts/standard/entities/scenery.plot.rb +2 -4
  63. data/scripts/standard/entities/supporter.plot.rb +4 -7
  64. data/scripts/standard/entities/thing.plot.rb +7 -0
  65. data/scripts/standard/{actions/give.plot.rb → give.plot.rb} +27 -25
  66. data/scripts/standard/lockable.plot.rb +79 -0
  67. data/scripts/standard/modules.plot.rb +2 -4
  68. data/scripts/standard/modules/attachable.plot.rb +1 -0
  69. data/scripts/standard/modules/locale_description.plot.rb +20 -0
  70. data/scripts/standard/{use.plot.rb → modules/use.plot.rb} +51 -47
  71. data/scripts/standard/openable.plot.rb +43 -0
  72. data/scripts/standard/pathfinder.plot.rb +11 -6
  73. data/scripts/standard/test.plot.rb +2 -0
  74. data/scripts/undo.plot.rb +13 -11
  75. metadata +30 -65
  76. data/lib/gamefic-sdk/plot_config.rb +0 -25
  77. data/scripts/ansi.plot.rb +0 -13
  78. data/scripts/autosuggest.plot.rb +0 -165
  79. data/scripts/clothing.plot.rb +0 -2
  80. data/scripts/clothing/actions.plot.rb +0 -4
  81. data/scripts/clothing/actions/wear.plot.rb +0 -19
  82. data/scripts/clothing/entities.plot.rb +0 -7
  83. data/scripts/clothing/entities/coat.plot.rb +0 -5
  84. data/scripts/clothing/entities/gloves.plot.rb +0 -5
  85. data/scripts/clothing/entities/hat.plot.rb +0 -5
  86. data/scripts/clothing/entities/pants.plot.rb +0 -5
  87. data/scripts/clothing/entities/shirt.plot.rb +0 -5
  88. data/scripts/clothing/entities/shoes.plot.rb +0 -5
  89. data/scripts/cover.plot.rb +0 -30
  90. data/scripts/furniture.plot.rb +0 -35
  91. data/scripts/hints.plot.rb +0 -31
  92. data/scripts/hypertext.plot.rb +0 -280
  93. data/scripts/media.plot.rb +0 -17
  94. data/scripts/multimedia.plot.rb +0 -41
  95. data/scripts/questions.plot.rb +0 -17
  96. data/scripts/room-modes.plot.rb +0 -48
  97. data/scripts/rough-sizes.plot.rb +0 -36
  98. data/scripts/save-restore.plot.rb +0 -22
  99. data/scripts/standard/actions/close.plot.rb +0 -16
  100. data/scripts/standard/actions/lock.plot.rb +0 -59
  101. data/scripts/standard/actions/look-under.plot.rb +0 -8
  102. data/scripts/standard/actions/open.plot.rb +0 -34
  103. data/scripts/standard/actions/read.plot.rb +0 -3
  104. data/scripts/standard/actions/search.plot.rb +0 -40
  105. data/scripts/standard/actions/show.plot.rb +0 -13
  106. data/scripts/standard/actions/unlock.plot.rb +0 -77
  107. data/scripts/standard/actions/use.plot.rb +0 -25
  108. data/scripts/standard/entities/container.plot.rb +0 -8
  109. data/scripts/standard/entities/door.plot.rb +0 -51
  110. data/scripts/standard/entities/entity.plot.rb +0 -12
  111. data/scripts/standard/entities/exterior.plot.rb +0 -5
  112. data/scripts/standard/modules/darkenable.plot.rb +0 -6
  113. data/scripts/standard/modules/lockable.plot.rb +0 -25
  114. data/scripts/standard/modules/openable.plot.rb +0 -15
  115. data/scripts/standard/modules/transparent.plot.rb +0 -6
  116. data/scripts/standard/plural.plot.rb +0 -2
  117. data/scripts/standard/plural/actions.plot.rb +0 -4
  118. data/scripts/standard/plural/actions/drop.plot.rb +0 -126
  119. data/scripts/standard/plural/actions/insert.plot.rb +0 -60
  120. data/scripts/standard/plural/actions/place.plot.rb +0 -37
  121. data/scripts/standard/plural/actions/take.plot.rb +0 -175
  122. data/scripts/standard/plural/queries.plot.rb +0 -5
  123. data/scripts/standard/plural/queries/ambiguous_visible.plot.rb +0 -13
  124. data/scripts/standard/plural/queries/any_expression.plot.rb +0 -17
  125. data/scripts/standard/plural/queries/many_visible.plot.rb +0 -13
  126. data/scripts/standard/plural/queries/not_expression.plot.rb +0 -16
  127. data/scripts/standard/plural/queries/plural_visible.plot.rb +0 -22
  128. data/scripts/suggestible.plot.rb +0 -54
@@ -5,6 +5,18 @@ module Gamefic::Sdk
5
5
  autoload :Gfic, 'gamefic-sdk/platform/gfic'
6
6
  autoload :Web, 'gamefic-sdk/platform/web'
7
7
  autoload :Sinatra, 'gamefic-sdk/platform/sinatra'
8
+
9
+ #def self.load directory, platform
10
+ # config_file = File.join(directory, 'config.yaml')
11
+ #end
12
+
13
+ def self.load config, name
14
+ target = config.targets[name]
15
+ raise ArgumentError.new("Config does not have a target '#{name}'") if target.nil?
16
+ cls = Gamefic::Sdk::Platform.const_get(target['platform'])
17
+ raise ArgumentError.new("Platform '#{target['platform']}' not found") if target.nil?
18
+ cls.new(config: config, target: target.merge('name' => name))
19
+ end
8
20
  end
9
21
 
10
22
  end
@@ -1,62 +1,64 @@
1
1
  require 'gamefic-sdk'
2
2
  require 'gamefic-sdk/debug/plot'
3
- require 'gamefic-sdk/plot_config'
3
+ #require 'gamefic-sdk/plot_config'
4
+ require 'pathname'
4
5
 
5
6
  module Gamefic::Sdk
6
7
  class Platform::Base
7
- # @return [Gamefic::Sdk::Debug::Plot]
8
- attr_reader :source_dir
9
-
10
- # @return [Hash]
8
+ # @return [Gamefic::Sdk::Config]
11
9
  attr_reader :config
12
-
13
- def initialize source_dir, config = {}
14
- @source_dir = source_dir
15
- @config = defaults.merge(config)
16
- @config['target_dir'] ||= "release/#{config['name'] || self.class.to_s.split("::").last}"
17
- @config['build_dir'] ||= "build/#{config['name'] || self.class.to_s.split("::").last}"
18
- # Convert config directories into absolute paths
19
- @config['target_dir'] = File.absolute_path(@config['target_dir'], source_dir)
20
- @config['build_dir'] = File.absolute_path(@config['build_dir'], source_dir)
10
+
11
+ # @return [Hash]
12
+ attr_reader :target
13
+
14
+ #def initialize config, name = nil
15
+ def initialize config: Gamefic::Sdk::Config.new, target: {}
16
+ #@source_dir = source_dir
17
+ #@name = name
18
+ #@config = config
19
+ #@config.freeze
20
+ @config = config
21
+ @target = target
21
22
  end
22
-
23
- # @return [PlotConfig]
24
- def plot_config
25
- @plot_config ||= PlotConfig.new("#{source_dir}/config.yaml")
23
+
24
+ def name
25
+ @name ||= (target['name'] || self.class.to_s.split('::').last.downcase)
26
+ end
27
+
28
+ def build_target
29
+ @build_target ||= File.join(config.build_path, name)
26
30
  end
27
-
31
+
32
+ def release_target
33
+ @release_target ||= File.join(config.release_path, name)
34
+ end
35
+
36
+ # @return [Gamefic::Plot]
28
37
  def plot
29
38
  if @plot.nil?
30
- paths = plot_config.script_paths + [Gamefic::Sdk::GLOBAL_SCRIPT_PATH]
39
+ paths = [config.script_path, config.import_path, Gamefic::Sdk::GLOBAL_SCRIPT_PATH]
40
+ # @todo: Should really use Gamefic::Sdk::Debug::Plot or just Gamfic::Plot?
31
41
  @plot = Gamefic::Sdk::Debug::Plot.new(Gamefic::Source::File.new(*paths))
32
42
  @plot.script 'main'
33
43
  end
34
44
  @plot
35
45
  end
36
-
37
- # Get a hash of default configuration values.
38
- # Platforms can overload this method to define their own defaults.
39
- # @return [Hash]
40
- def defaults
41
- @defaults ||= Hash.new
42
- end
43
-
46
+
44
47
  def build
45
48
  # Platforms need to build/compile the deployment here.
46
49
  raise "The base Platform class does not have a build method"
47
50
  end
48
-
51
+
49
52
  def clean
50
53
  puts "Nothing to do for this platform."
51
54
  end
52
-
53
- # Get a string of build metadata, represented as a hash.
55
+
56
+ # Get a hash of build metadata.
54
57
  #
55
58
  # @return [Hash]
56
59
  def metadata
57
60
  hash = {}
58
- uuid = File.exist?(source_dir + '/.uuid') ? File.read(source_dir + '/.uuid').strip : ''
59
- hash[:uuid] = "#{uuid}"
61
+ hash[:uuid] = config.uuid
60
62
  hash[:gamefic_version] = "#{Gamefic::VERSION}"
61
63
  hash[:sdk_version] = "#{Gamefic::Sdk::VERSION}"
62
64
  hash[:build_date] = "#{DateTime.now}"
@@ -5,26 +5,9 @@ require 'yaml'
5
5
  module Gamefic::Sdk
6
6
 
7
7
  class Platform::Gfic < Platform::Base
8
- def defaults
9
- @defaults ||= {
10
- :filename => nil,
11
- :with_html => true,
12
- :with_media => true
13
- }
14
- end
15
8
  def build
16
- target_dir = config['target_dir']
17
- if config['filename'].to_s == ''
18
- if plot_config.title.to_s == ''
19
- filename = File.join(target_dir, File.expand_path(source_dir).split('/').delete_if{|i| i.to_s == ''}.last + '.gfic')
20
- else
21
- filename = File.join(target_dir, plot_config.title.gsub(/ /, '-').downcase + '.gfic')
22
- end
23
- else
24
- filename = File.join(target_dir, config['filename'])
25
- end
26
9
  FileUtils.rm filename if File.file?(filename)
27
- FileUtils.mkdir_p target_dir
10
+ FileUtils.mkdir_p release_target
28
11
  Zip::File.open(filename, Zip::File::CREATE) do |zipfile|
29
12
  plot.imported_scripts.each { |script|
30
13
  zipfile.add File.join('scripts', "#{script.path}.plot.rb"), script.absolute_path
@@ -35,6 +18,10 @@ module Gamefic::Sdk
35
18
  end
36
19
  end
37
20
  end
21
+
22
+ def filename
23
+ @filename ||= File.join(release_target, (target['filename'] || 'game.gfic'))
24
+ end
38
25
  end
39
26
 
40
27
  end
@@ -8,26 +8,22 @@ module Gamefic::Sdk
8
8
 
9
9
  def build
10
10
  STDERR.puts "Building for Sinatra"
11
- target_dir = config['target_dir']
12
- build_dir = config['build_dir']
13
- html_dir = app_config.html_dir
14
-
15
- FileUtils.mkdir_p target_dir
16
- copy_html_files target_dir
17
- render_index target_dir
18
- copy_assets build_dir, target_dir
19
- copy_media source_dir, target_dir
20
- FileUtils.cp_r File.join(Gamefic::Sdk::HTML_TEMPLATE_PATH, 'sinatra', 'engine.js'), File.join(target_dir, 'core', 'engine.js')
11
+ FileUtils.mkdir_p release_target
12
+ copy_html_files
13
+ render_index
14
+ copy_assets
15
+ copy_media
16
+ FileUtils.cp_r File.join(Gamefic::Sdk::HTML_TEMPLATE_PATH, 'sinatra', 'engine.js'), File.join(release_target, 'core', 'engine.js')
21
17
  end
22
18
 
23
- def clean
24
- FileUtils.remove_entry_secure config['build_dir'] if File.exist?(config['build_dir'])
25
- FileUtils.mkdir_p config['build_dir']
26
- puts "#{config['build_dir']} cleaned."
27
- end
19
+ #def clean
20
+ # FileUtils.remove_entry_secure config['build_path'] if File.exist?(config['build_path'])
21
+ # FileUtils.mkdir_p config['build_path']
22
+ # puts "#{config['build_path']} cleaned."
23
+ #end
28
24
 
29
25
  def app_config
30
- @app_config ||= AppConfig.new source_dir, config, ["core/engine.js"]
26
+ @app_config ||= AppConfig.new config.source_dir, config, ["core/engine.js"]
31
27
  end
32
28
 
33
29
  private
@@ -45,52 +41,54 @@ module Gamefic::Sdk
45
41
  end
46
42
 
47
43
  # Copy everything in source except config and template
48
- def copy_html_files target_dir
44
+ def copy_html_files
49
45
  Dir.entries(app_config.html_dir).each { |entry|
50
46
  if entry != 'index.rb' and entry != 'index.html.erb' and entry != '.' and entry != '..'
51
- FileUtils.mkdir_p target_dir + '/' + File.dirname(entry)
52
- FileUtils.cp_r "#{app_config.html_dir}/#{entry}", "#{target_dir}/#{entry}"
47
+ FileUtils.mkdir_p release_target + '/' + File.dirname(entry)
48
+ FileUtils.cp_r "#{app_config.html_dir}/#{entry}", "#{release_target}/#{entry}"
53
49
  end
54
50
  }
55
51
  end
56
52
 
57
- def render_index target_dir
53
+ def render_index
58
54
  # Render index
59
- File.open(target_dir + "/index.html", "w") do |file|
55
+ File.open(release_target + "/index.html", "w") do |file|
60
56
  file << app_config.render
61
57
  end
62
58
  end
63
59
 
64
- def copy_assets build_dir, target_dir
60
+ def copy_assets
65
61
  paths = app_config.resource_paths
66
- paths.push build_dir
62
+ paths.push build_target
67
63
  app_config.javascripts.each { |js|
68
64
  absolute = resolve(js, paths)
69
- FileUtils.mkdir_p target_dir + "/" + File.dirname(js)
70
- FileUtils.cp_r absolute, target_dir + "/" + js
65
+ FileUtils.mkdir_p release_target + "/" + File.dirname(js)
66
+ FileUtils.cp_r absolute, release_target + "/" + js
71
67
  }
72
68
  app_config.stylesheets.each { |css|
73
69
  absolute = resolve(css, paths)
74
- FileUtils.mkdir_p target_dir + "/" + File.dirname(css)
75
- FileUtils.cp_r absolute, target_dir + "/" + css
70
+ FileUtils.mkdir_p release_target + "/" + File.dirname(css)
71
+ FileUtils.cp_r absolute, release_target + "/" + css
76
72
  }
77
73
  end
78
74
 
79
- def copy_media source_dir, target_dir
75
+ =begin
76
+ def copy_media
80
77
  # Copy media
81
78
  pc = PlotConfig.new "#{source_dir}/config.yaml"
82
79
  pc.media_paths.each { |path|
83
80
  if File.directory?(path)
84
- FileUtils.mkdir_p target_dir + "/media"
81
+ FileUtils.mkdir_p release_target + "/media"
85
82
  Dir.entries(path).each { |entry|
86
83
  if entry != '.' and entry != '..'
87
- FileUtils.mkdir_p target_dir + "/media/" + File.dirname(entry)
88
- FileUtils.cp_r path + "/" + entry, target_dir + "/media/" + entry
84
+ FileUtils.mkdir_p release_target + "/media/" + File.dirname(entry)
85
+ FileUtils.cp_r path + "/" + entry, release_target + "/media/" + entry
89
86
  end
90
87
  }
91
88
  end
92
89
  }
93
90
  end
91
+ =end
94
92
 
95
93
  def metadata_code
96
94
  "\nGameficOpal.static_plot.metadata = JSON.parse('#{metadata.to_json}')"
@@ -8,38 +8,38 @@ module Gamefic::Sdk
8
8
  class Platform::Web < Platform::Base
9
9
  autoload :AppConfig, 'gamefic-sdk/platform/web/app_config'
10
10
 
11
- def defaults
12
- @defaults ||= {
13
- 'html_skin' => 'standard',
14
- 'with_media' => true
15
- }
16
- end
17
-
18
11
  def app_config
19
- @app_config ||= AppConfig.new source_dir, config, ["core/opal.js", "core/gamefic.js", "core/static.js", "core/scripts.js", "core/engine.js"]
12
+ @app_config ||= AppConfig.new config.source_dir, config, ["core/opal.js", "core/gamefic.js", "core/static.js", "core/scripts.js", "core/engine.js"]
20
13
  end
21
14
 
22
15
  def build
23
- target_dir = config['target_dir']
24
- build_dir = config['build_dir']
25
- html_dir = app_config.html_dir
26
-
27
- FileUtils.mkdir_p target_dir
28
- copy_html_files target_dir
29
- build_opal_js build_dir
30
- build_gamefic_js build_dir
31
- build_static_js build_dir
32
- build_scripts_js build_dir
33
- render_index target_dir
34
- copy_assets build_dir, target_dir
35
- copy_media source_dir, target_dir
36
-
16
+ FileUtils.mkdir_p release_target
17
+ FileUtils.mkdir_p build_target
18
+ copy_html_files
19
+ build_opal_js
20
+ build_gamefic_js
21
+ build_static_js
22
+ build_scripts_js
23
+ render_index
24
+ copy_assets
25
+ copy_media
37
26
  end
38
27
 
39
28
  def clean
40
- FileUtils.remove_entry_secure config['build_dir'] if File.exist?(config['build_dir'])
41
- FileUtils.mkdir_p config['build_dir']
42
- puts "#{config['build_dir']} cleaned."
29
+ FileUtils.remove_entry_secure build_target if File.exist?(build_target)
30
+ puts "#{name} cleaned."
31
+ end
32
+
33
+ def html_dir
34
+ if @html_dir.nil?
35
+ local_dir = (target['html'] ? target['html'] : 'html')
36
+ @html_dir = Pathname.new(config.source_dir).join(local_dir).to_s
37
+ @html_dir = nil unless Dir.exist?(@html_dir)
38
+ if @html_dir.nil?
39
+ @html_dir = File.join(Gamefic::Sdk::HTML_TEMPLATE_PATH, 'skins', 'standard')
40
+ end
41
+ end
42
+ @html_dir
43
43
  end
44
44
 
45
45
  private
@@ -57,21 +57,22 @@ module Gamefic::Sdk
57
57
  end
58
58
 
59
59
  # Copy everything in source except config and template
60
- def copy_html_files target_dir
61
- Dir.entries(app_config.html_dir).each { |entry|
60
+ def copy_html_files
61
+ #Dir.entries(app_config.html_dir).each { |entry|
62
+ Dir.entries(html_dir).each { |entry|
62
63
  if entry != 'index.rb' and entry != 'index.html.erb' and entry != '.' and entry != '..'
63
- FileUtils.mkdir_p target_dir + '/' + File.dirname(entry)
64
- FileUtils.cp_r "#{app_config.html_dir}/#{entry}", "#{target_dir}/#{entry}"
64
+ FileUtils.mkdir_p release_target + '/' + File.dirname(entry)
65
+ FileUtils.cp_r "#{app_config.html_dir}/#{entry}", "#{release_target}/#{entry}"
65
66
  end
66
67
  }
67
68
  end
68
69
 
69
- def build_opal_js build_dir
70
+ def build_opal_js
70
71
  # Make sure core exists in build directory
71
- FileUtils.mkdir_p build_dir + "/core"
72
+ FileUtils.mkdir_p build_target + "/core"
72
73
  # Opal core
73
- if !File.exist?(build_dir + "/core/opal.js")
74
- File.open(build_dir + "/core/opal.js", "w") do |file|
74
+ if !File.exist?(build_target + "/core/opal.js")
75
+ File.open(build_target + "/core/opal.js", "w") do |file|
75
76
  file << Uglifier.compile(
76
77
  Opal::Builder.build('opal').to_s + "\n" + Opal::Builder.build('json').to_s + "\n" + Opal::Builder.build('native').to_s
77
78
  )
@@ -79,22 +80,20 @@ module Gamefic::Sdk
79
80
  end
80
81
  end
81
82
 
82
- def build_gamefic_js build_dir
83
+ def build_gamefic_js
83
84
  # Gamefic core
84
85
  Opal.use_gem 'gamefic'
85
- if !File.exist?(build_dir + "/core/gamefic.js")
86
- File.open(build_dir + "/core/gamefic.js", "w") do |file|
86
+ if !File.exist?(build_target + "/core/gamefic.js")
87
+ File.open(build_target + "/core/gamefic.js", "w") do |file|
87
88
  file << Uglifier.compile(Opal::Builder.build('gamefic').to_s)
88
89
  end
89
90
  end
90
91
  end
91
92
 
92
- def build_static_js build_dir
93
- # GameficOpal
93
+ def build_static_js
94
94
  Opal.append_path Gamefic::Sdk::LIB_PATH
95
- if !File.exist?(build_dir + "/core/static.js")
96
- File.open(build_dir + "/core/static.js", "w") do |file|
97
- #file << Opal::Builder.build('gamefic-sdk/platform/web/gamefic_opal')
95
+ if !File.exist?(build_target + "/core/static.js")
96
+ File.open(build_target + "/core/static.js", "w") do |file|
98
97
  file << Uglifier.compile(
99
98
  Opal::Builder.build('gamefic-sdk/platform/web/engine').to_s + "\n" + Opal::Builder.build('gamefic-sdk/platform/web/user').to_s
100
99
  )
@@ -102,8 +101,12 @@ module Gamefic::Sdk
102
101
  end
103
102
  end
104
103
 
105
- def build_scripts_js build_dir
106
- File.open("#{build_dir}/scripts.rb", 'w') do |file|
104
+ def build_scripts_js
105
+ File.open("#{build_target}/scripts.rb", 'w') do |file|
106
+ #file << "def Module.const_missing sym\n"
107
+ #file << "puts 'From Object to Gamefic'\n"
108
+ #file << "Gamefic.const_get sym\n"
109
+ #file << "end\n"
107
110
  file << "module Gamefic\n"
108
111
  file << "$scripts = {}\n"
109
112
  plot.imported_scripts.each { |script|
@@ -116,47 +119,51 @@ module Gamefic::Sdk
116
119
  file << "$plot.script 'main'\n"
117
120
  file << "$engine = Gamefic::Engine::Web.new($plot)\n"
118
121
  file << "end\n"
122
+ file << "$plot.stage do\n"
123
+ file << "def self.const_missing sym\n"
124
+ file << "Gamefic.const_get sym\n"
125
+ file << "end\n"
126
+ file << "end\n"
127
+ #file << "def $plot.theater.const_missing sym\n"
128
+ #file << 'puts "Trying to get #{sym} from object"' + "\n"
129
+ #file << "Object.const_get sym\n"
130
+ #file << "end\n"
119
131
  end
120
- Opal.append_path build_dir
121
- File.open(build_dir + "/core/scripts.js", 'w') do |file|
132
+ Opal.append_path build_target
133
+ File.open(build_target + "/core/scripts.js", 'w') do |file|
122
134
  file << Uglifier.compile(Opal::Builder.build('scripts').to_s)
123
135
  end
124
136
  end
125
137
 
126
- def render_index target_dir
138
+ def render_index
127
139
  # Render index
128
- File.open(target_dir + "/index.html", "w") do |file|
140
+ File.open(release_target + "/index.html", "w") do |file|
129
141
  file << app_config.render
130
142
  end
131
143
  end
132
144
 
133
- def copy_assets build_dir, target_dir
145
+ def copy_assets
134
146
  paths = app_config.resource_paths
135
- paths.push build_dir
147
+ paths.push build_target
136
148
  app_config.javascripts.each { |js|
137
149
  absolute = resolve(js, paths)
138
- FileUtils.mkdir_p target_dir + "/" + File.dirname(js)
139
- FileUtils.cp_r absolute, target_dir + "/" + js
150
+ FileUtils.mkdir_p release_target + "/" + File.dirname(js)
151
+ FileUtils.cp_r absolute, release_target + "/" + js
140
152
  }
141
153
  app_config.stylesheets.each { |css|
142
154
  absolute = resolve(css, paths)
143
- FileUtils.mkdir_p target_dir + "/" + File.dirname(css)
144
- FileUtils.cp_r absolute, target_dir + "/" + css
155
+ FileUtils.mkdir_p release_target + "/" + File.dirname(css)
156
+ FileUtils.cp_r absolute, release_target + "/" + css
145
157
  }
146
158
  end
147
159
 
148
- def copy_media source_dir, target_dir
149
- # Copy media
150
- pc = PlotConfig.new "#{source_dir}/config.yaml"
151
- pc.media_paths.each { |path|
152
- if File.directory?(path)
153
- FileUtils.mkdir_p target_dir + "/media"
154
- Dir.entries(path).each { |entry|
155
- if entry != '.' and entry != '..'
156
- FileUtils.mkdir_p target_dir + "/media/" + File.dirname(entry)
157
- FileUtils.cp_r path + "/" + entry, target_dir + "/media/" + entry
158
- end
159
- }
160
+ def copy_media
161
+ FileUtils.mkdir_p release_target + "/media"
162
+ return unless File.directory?(config.media_path)
163
+ Dir.entries(config.media_path).each { |entry|
164
+ if entry != '.' and entry != '..'
165
+ FileUtils.mkdir_p release_target + "/media/" + File.dirname(entry)
166
+ FileUtils.cp_r config.media_path + "/" + entry, release_target + "/media/" + entry
160
167
  end
161
168
  }
162
169
  end