Class: Gamefic::Sdk::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory, data = {}) ⇒ Config

Returns a new instance of Config.



10
11
12
13
14
15
16
# File 'lib/gamefic-sdk/config.rb', line 10

def initialize directory, data = {}
  @source_dir = directory
  @data = data

  @source_dir.freeze
  @data.freeze
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#source_dirObject (readonly)

Returns the value of attribute source_dir.



7
8
9
# File 'lib/gamefic-sdk/config.rb', line 7

def source_dir
  @source_dir
end

Class Method Details

.generate(author = 'Anonymous', title = 'Untitled') ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/gamefic-sdk/config.rb', line 103

def self.generate author = 'Anonymous', title = 'Untitled'
"title: \#{title}\nauthor: \#{author}\n\nscript_path: ./scripts\nimport_path: ./imports\nmedia_path: ./media\n\nbuild_path: ./build\nrelease_path: ./release\n\ntargets:\n  web:\n    platform: Web\n    html: ./html\n  gfic:\n    platform: Gfic\n    filename: game.gfic\n"
end

.load(directory) ⇒ Gamefic::Sdk::Config



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/gamefic-sdk/config.rb', line 91

def self.load directory
  config = {}
  ['config.yml', 'config.yaml'].each do |cy|
    config_file = File.join(directory, cy)
    if File.exist?(config_file)
      config = YAML.load(File.read(config_file))
      break
    end
  end
  Config.new(directory, config)
end

Instance Method Details

#authorString

The game’s author.

Returns:

  • (String)


28
29
30
# File 'lib/gamefic-sdk/config.rb', line 28

def author
  @author ||= (data['author'] || 'Anonymous')
end

#auto_import?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/gamefic-sdk/config.rb', line 67

def auto_import?
  @auto_import ||= (data['auto_import'] || true)
end

#build_pathString

The absolute path to the project’s build directory.

Returns:

  • (String)


56
57
58
# File 'lib/gamefic-sdk/config.rb', line 56

def build_path
  @build_path ||= Pathname.new(source_dir).join(data['build_path'] || './build').to_s
end

#import_pathString

The absolute path to the project’s import directory.

Returns:

  • (String)


42
43
44
# File 'lib/gamefic-sdk/config.rb', line 42

def import_path
  @import_paths ||= Pathname.new(source_dir).join(data['import_path'] || './imports').to_s
end

#media_pathString

The absolute path to the project’s media directory.

Returns:

  • (String)


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

def media_path
  @media_path ||= Pathname.new(source_dir).join(data['media_path'] || './media').to_s
end

#release_pathString

The absolute path to the project’s release directory.

Returns:

  • (String)


63
64
65
# File 'lib/gamefic-sdk/config.rb', line 63

def release_path
  @release_path ||= Pathname.new(source_dir).join(data['release_path'] || './release').to_s
end

#script_pathString

The absolute path to the project’s script directory.

Returns:

  • (String)


35
36
37
# File 'lib/gamefic-sdk/config.rb', line 35

def script_path
  @script_paths ||= Pathname.new(source_dir).join(data['script_path'] || './scripts').to_s
end

#targetsHash

A hash of each target’s name and its configuration options.

Returns:

  • (Hash)


74
75
76
# File 'lib/gamefic-sdk/config.rb', line 74

def targets
  @targets ||= (data['targets'] || {})
end

#titleString

The game’s title.

Returns:

  • (String)


21
22
23
# File 'lib/gamefic-sdk/config.rb', line 21

def title
  @title ||= (data['title'] || 'Untitled')
end

#uuidString

A universal unique identifier for the project.

Returns:

  • (String)


81
82
83
84
85
86
87
88
# File 'lib/gamefic-sdk/config.rb', line 81

def uuid
  if @uuid.nil?
    if File.file?(File.join source_dir, '.uuid')
      @@uuid = File.read(File.join source_dir, '.uuid').strip
    end
  end
  @uuid
end