Class: Gamefic::Sdk::Platform::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic-sdk/platform/base.rb

Direct Known Subclasses

Gfic, Web

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_dir, config = {}) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
21
# File 'lib/gamefic-sdk/platform/base.rb', line 13

def initialize source_dir, config = {}
  @source_dir = source_dir
  @config = defaults.merge(config)
  @config['target_dir'] ||= "release/#{config['name'] || self.class.to_s.split("::").last}"
  @config['build_dir'] ||= "build/#{config['name'] || self.class.to_s.split("::").last}"
  # Convert config directories into absolute paths
  @config['target_dir'] = File.absolute_path(@config['target_dir'], source_dir)
  @config['build_dir'] = File.absolute_path(@config['build_dir'], source_dir)
end

Instance Attribute Details

#configHash (readonly)

Returns:

  • (Hash)


11
12
13
# File 'lib/gamefic-sdk/platform/base.rb', line 11

def config
  @config
end

#source_dirGamefic::Sdk::Debug::Plot (readonly)



8
9
10
# File 'lib/gamefic-sdk/platform/base.rb', line 8

def source_dir
  @source_dir
end

Instance Method Details

#buildObject



44
45
46
47
# File 'lib/gamefic-sdk/platform/base.rb', line 44

def build
  # Platforms need to build/compile the deployment here.
  raise "The base Platform class does not have a build method"
end

#cleanObject



49
50
51
# File 'lib/gamefic-sdk/platform/base.rb', line 49

def clean
  puts "Nothing to do for this platform."
end

#defaultsHash

Get a hash of default configuration values. Platforms can overload this method to define their own defaults.

Returns:

  • (Hash)


40
41
42
# File 'lib/gamefic-sdk/platform/base.rb', line 40

def defaults
  @defaults ||= Hash.new
end

#metadataHash

Get a string of build metadata, represented as a hash.

Returns:

  • (Hash)


56
57
58
59
60
61
62
63
64
# File 'lib/gamefic-sdk/platform/base.rb', line 56

def 
  hash = {}
  uuid = File.exist?(source_dir + '/.uuid') ? File.read(source_dir + '/.uuid').strip : ''
  hash[:uuid] = "#{uuid}"
  hash[:gamefic_version] = "#{Gamefic::VERSION}"
  hash[:sdk_version] = "#{Gamefic::Sdk::VERSION}"
  hash[:build_date] = "#{DateTime.now}"
  hash
end

#plotObject



28
29
30
31
32
33
34
35
# File 'lib/gamefic-sdk/platform/base.rb', line 28

def plot
  if @plot.nil?
    paths = plot_config.script_paths + [Gamefic::Sdk::GLOBAL_SCRIPT_PATH]
    @plot = Gamefic::Sdk::Debug::Plot.new(Gamefic::Source::File.new(*paths))
    @plot.script 'main'
  end
  @plot
end

#plot_configPlotConfig

Returns:



24
25
26
# File 'lib/gamefic-sdk/platform/base.rb', line 24

def plot_config
  @plot_config ||= PlotConfig.new("#{source_dir}/config.yaml")
end