Class: Gamefic::Sdk::Config
- Inherits:
-
Object
- Object
- Gamefic::Sdk::Config
- Defined in:
- lib/gamefic-sdk/config.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#source_dir ⇒ Object
readonly
Returns the value of attribute source_dir.
Class Method Summary collapse
- .generate(author = 'Anonymous', title = 'Untitled') ⇒ Object
- .load(directory) ⇒ Gamefic::Sdk::Config
Instance Method Summary collapse
-
#author ⇒ String
The game’s author.
- #auto_import? ⇒ Boolean
-
#build_path ⇒ String
The absolute path to the project’s build directory.
-
#import_path ⇒ String
The absolute path to the project’s import directory.
-
#initialize(directory, data = {}) ⇒ Config
constructor
A new instance of Config.
-
#media_path ⇒ String
The absolute path to the project’s media directory.
-
#release_path ⇒ String
The absolute path to the project’s release directory.
-
#script_path ⇒ String
The absolute path to the project’s script directory.
-
#targets ⇒ Hash
A hash of each target’s name and its configuration options.
-
#title ⇒ String
The game’s title.
-
#uuid ⇒ String
A universal unique identifier for the project.
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/gamefic-sdk/config.rb', line 8 def data @data end |
#source_dir ⇒ Object (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 = '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
#author ⇒ String
The game’s author.
28 29 30 |
# File 'lib/gamefic-sdk/config.rb', line 28 def ||= (data['author'] || 'Anonymous') end |
#auto_import? ⇒ Boolean
67 68 69 |
# File 'lib/gamefic-sdk/config.rb', line 67 def auto_import? @auto_import ||= (data['auto_import'] || true) end |
#build_path ⇒ String
The absolute path to the project’s build directory.
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_path ⇒ String
The absolute path to the project’s import directory.
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_path ⇒ String
The absolute path to the project’s media directory.
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_path ⇒ String
The absolute path to the project’s release directory.
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_path ⇒ String
The absolute path to the project’s script directory.
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 |
#targets ⇒ Hash
A hash of each target’s name and its configuration options.
74 75 76 |
# File 'lib/gamefic-sdk/config.rb', line 74 def targets @targets ||= (data['targets'] || {}) end |
#title ⇒ String
The game’s title.
21 22 23 |
# File 'lib/gamefic-sdk/config.rb', line 21 def title @title ||= (data['title'] || 'Untitled') end |
#uuid ⇒ String
A universal unique identifier for the project.
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 |