eidolon 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDE4MzAyZjFlOWE3ZTJlZmNjNzIxNWFlN2RjOWQ2ZWYxOTA4YTUxOA==
4
+ OGMzNDAyODEyMGZmOTQwYmJmNzc4NDNiZmU4MWU5MDRhY2Q1NGJlMg==
5
5
  data.tar.gz: !binary |-
6
- MTJjZGE1YmQ0YjNhNGJmNTY1MzdiZDM5YjNiNDI4MDQyMmI1MmE3Nw==
6
+ NTNjMDMxMGYwNjliMGI5MDc4YjE0ZjIwODdkZDk4NzA2ZjUxNmZlMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDI0YTY3MmMwYmJiOWQ2OThmZjY2MDZlN2U0NWY2N2E2NTc3NmI3NDM5NDMz
10
- MzVlNGMxMmYyZjkzNmUwOTg5NzJiMTEyZTJkMDY1MjI1ZGY5ZmY1Yjc0ZTQw
11
- MmQ1MGI1YzNhOWY4NjA5ZDBhNjY5ZmZlOTY5YmYxNjRjNjk2NWM=
9
+ YzEwZjc1MTVmNDhjNmYzNWNlZGNhMzk2ZWFmNjQzZjdlN2JlMjgzZGExODhl
10
+ MmNlZDRjOGQzNDIyNTQ2N2Y5NGUwNGI3MGNiODYwNzg3MTJmOGRmMmNjMjE0
11
+ NjU0NjEzMmRlZWU1MjAxZjcyYzM4NTE4MTExYjRkYTBlNWM0NGY=
12
12
  data.tar.gz: !binary |-
13
- ODJhNGI3NGVmMWViOWQzNzljMzcyZTMxOTYyYjYzYzExMzg1YTU3ZDIzM2I0
14
- YWMwNDk5MmNjMmFlYTFlZTRiMTRkOTBkYTA5MDA3N2IxZjRjNWYwZmM3MWE5
15
- NmRjZjg1NzA1MWM3YjhjNjZlYjc2NDFkYjhiYzA4MTFmZmVlODM=
13
+ NjcxZWE5YWM3OTMyODg5MDc2OThmMTE1YmUxOWI0OWFmNmNiNjgxNjY3MTEz
14
+ MDgzZGM1MTMxZTYxN2IxNzdiZTYyYWUzOTk4MjA5ZDEzZmFlNzBkODFhZDdm
15
+ Yjg1NTgwMWFhMWRmOTE2NjQzN2JmNmFiYWZlOTM0YmE0ZDk1Mjg=
data/README.md CHANGED
@@ -23,31 +23,37 @@ require 'eidolon/rgss2'
23
23
  require 'eidolon/rgss3'
24
24
  ```
25
25
 
26
- Note that only one version may be required this way: attempting to require more than one version of the RGSS data structures will result in superclass mismatches. For this reason, if you potentially need to operate with more than one of the RGSS versions, you should use the core Eidolon module; essentially, the usage of this module allows you to dynamically create and destroy the needed RPG data structures whenever they are required. See the included documentation for more detailed information about the usage of the Eidolon module.
26
+ Note that only one version may be required this way: attempting to `require` more than one version of the RGSS data structures will result in superclass mismatches. For this reason, if you potentially need to operate with more than one of the RGSS versions, you should use the core Eidolon module instead; essentially, the usage of this module allows you to dynamically create and destroy the needed RPG data structures whenever they are required. See the included documentation for more detailed information about the usage of the Eidolon module.
27
27
 
28
28
  ```ruby
29
29
  require 'eidolon'
30
30
 
31
+ # Equivalent to the RGSSx +load_data+ method.
31
32
  def load_data(filename)
32
- File.open(filename, 'rb') do |file|
33
- return Marshal.load(file)
34
- end
33
+ File.open(filename, 'rb') { |data| Marshal.load(data) }
35
34
  end
36
35
 
37
- @rgss_data = []
38
- @rgss3_data = []
39
-
40
- Eidolon.build('RGSS')
41
- Dir.glob('**/*.rxdata') do |rxdata|
42
- @rgss_data.push(load_data(rxdata))
36
+ # Build the RGSS data structures and return RMXP project data.
37
+ Eidolon.build('RGSS') do
38
+ data = []
39
+ Dir.glob('**/*.rxdata') { |rxdata| data << load_data(rxdata) }
40
+ data
43
41
  end
42
+ ```
44
43
 
45
- Eidolon.destroy!
44
+ ## Local Extensions
45
+ Eidolon has been written in a way that allows developers to easily extend or modify the RGSSx data that it loads. This feature was primarily included to allow newer versions of RGSSx to be easily added to Eidolon in case of their release.
46
46
 
47
- Eidolon.build('RGSS3')
48
- Dir.glob('**/*.rvdata2') do |rvdata2|
49
- @rgss3_data.push(load_data(rvdata2))
50
- end
47
+ Essentially, Eidolon looks through a defined path for specific files to load RGSS data dependent on the RGSS version you request. For RGSS, it looks for `eidolon/rgss/loader.rb`, RGSS2 looks for `eidolon/rgss2/loader.rb`, and so on. In order to create RGSS4, for example, you simply need to recreate this structure locally -- and Eidolon will allow you to use it.
48
+
49
+ ```
50
+ $ cat eidolon/rgss4/loader.rb
51
+ # Load all of your needed modifications here.
52
+ load 'eidolon/rgssx/loader.rb'
53
+ load 'eidolon/rgss4/rpg/example.rb'
54
+
55
+ $ cat rgss4_application.rb
56
+ Eidolon.build(:RGSS4) { ... }
51
57
  ```
52
58
 
53
59
  ## Installation
@@ -1,94 +1,99 @@
1
1
  require 'eidolon/version'
2
2
 
3
3
  # == Eidolon
4
- # This module provides methods for building the data structures used by the RPG
5
- # Maker series of game development programs so that the serialized data may be
6
- # loaded into an external Ruby implementation. The methods used are platform
7
- # and dependency agnostic.
4
+ # This module provides methods for creating and destroying the data structures
5
+ # used by the RPG Maker series of game development programs so that their data
6
+ # may be loaded into an external Ruby implementation. The methods used are
7
+ # platform and dependency agnostic.
8
8
  #
9
9
  # == Usage
10
10
  # It is recommended that you explicitly declare which RGSS version Eidolon
11
11
  # should use before building the RGSSx data structures required; this is done
12
12
  # through the +Eidolon.rgss_version=+ method. This method accepts both integer
13
- # and representative string values -- for example, passing it an argument of
14
- # 1 or "RGSS" will both set the Eidolon RGSS version to the appropriate value.
15
- # Recognized RGSS versions are "RGSS" (XP), "RGSS2" (VX), and "RGSS3" (VX Ace).
13
+ # and representative string or symbol values -- for example, passing it an
14
+ # argument of 1, 'RGSS2', or :rgss3 will set the Eidolon RGSS version to the
15
+ # appropriate value.
16
16
  #
17
17
  # After explicitly requesting the desired RGSS version, you will want to build
18
18
  # the desired data structures with the +Eidolon.build+ method. This will create
19
19
  # the data structures for the specified RGSS version for use by the currently
20
20
  # running Ruby implementation. Note that the +Eidolon.build+ method will only
21
- # build data structures *once*.
21
+ # build data structures *once*. You may also explicitly pass an RGSS version to
22
+ # build as an argument to this method.
22
23
  #
23
- # You will need to use the +Eidolon.destroy!+ method if you intend to use more
24
- # than one RGSS version in a single Ruby session. On their own, the RGSSx data
25
- # structures are inherently incompatible with one another -- as such, the
26
- # previous data structures must be destroyed, which is what +Eidolon.destroy!+
27
- # does for you.
24
+ # Be aware that you will need to use the +Eidolon.destroy!+ method if you wish
25
+ # to use more than one RGSS version in a single Ruby session. On their own, the
26
+ # RGSSx data structures are inherently incompatible with one another (raising
27
+ # superclass mismatch errors) -- as such, the previous data structures must be
28
+ # destroyed, which the +Eidolon.destroy!+ method does for you.
28
29
  #
29
- # == Example
30
+ # In addition to this, you may pass a block to the +Eidolon.build+ method which
31
+ # automatically creates and destroys the data structures for the passed RGSS
32
+ # version. The specified RGSS version is available inside of the block and
33
+ # destroyed immediately after the block returns. Using a block will also return
34
+ # the value of the *block* rather than the usual +true+ or +false+ value.
35
+ #
36
+ # == Examples
30
37
  # require 'eidolon'
31
38
  #
32
- # # Building the RGSS3 (VX Ace) data structures.
39
+ # # Equivalent to the RGSSx method of the same name.
40
+ # def load_data(filename)
41
+ # File.open(filename, 'rb') { |data| Marshal.load(data) }
42
+ # end
43
+ #
44
+ # # Build the RGSS3 (VX Ace) data structures and obtain the project data of
45
+ # # an unencrypted RMVX Ace game.
33
46
  # Eidolon.rgss_version = 'RGSS3'
34
- # Eidolon.rgss_version # => "rgss3"
35
- # Eidolon.build # => true
36
- # Eidolon.built? # => true
47
+ # Eidolon.build # => true
48
+ # Eidolon.built? # => true
37
49
  #
38
- # # Destroy the previously built RGSS3 data structures.
39
- # Eidolon.destroy!
40
- # Eidolon.built? # => false
50
+ # # Initialize an array for storing the data, then fill it.
51
+ # @rgss3_data = []
52
+ # Dir.glob('**/*.rvdata2') { |data| @rgss3_data << load_data(data) }
53
+ # @rgss3_data # => [[nil, #<RPG::Actor...> ... ] ... ]
41
54
  #
42
- # # Now we can build the RGSS (XP) data structures as well.
43
- # Eidolon.build(1) # => true
55
+ # # Destroy the previously built RGSS3 data structures.
56
+ # Eidolon.destroy! # => true
57
+ # Eidolon.built? # => false
44
58
  #
45
- # # Obtaining an array of the built RGSSx structures.
46
- # Eidolon.built # => ["rgss", "rgss3"]
59
+ # # Now we can build the RGSS (XP) data structures with a block and return
60
+ # # the project data for an unencrypted RMXP game.
61
+ # Eidolon.build(1) do
62
+ # # Initialize an array for storing the data, fill it, then use it as the
63
+ # # block's return value.
64
+ # @xp_data = []
65
+ # Dir.glob('**/*.rxdata') { |data| @xp_data << load_data(data) }
66
+ # @xp_data
67
+ # end # => [[nil, #<RPG::Actor...> ... ] ... ]
68
+ # Eidolon.built? # => false
47
69
  module Eidolon
48
70
  class << self
49
- # The RGSSx version used by Eidolon. This determines which data structures
50
- # to require in order to facilitate working with serialized RGSSx data.
51
- attr_reader :rgss_version
52
-
53
- # An array of the RGSS versions which have had their data structures built
54
- # by Eidolon.
55
- attr_reader :built
56
- end
57
-
58
- # Initialize the array of built RGSS versions.
59
- @built = []
60
-
61
- # Set the RGSS version used by Eidolon to the passed value. May be set to an
62
- # integer or representative string value for the desired RGSS version.
63
- #
64
- # Examples:
65
- # Eidolon.rgss_version = "RGSS3" # Sets the version to "rgss3".
66
- # Eidolon.rgss_version = 1 # Sets the version to "rgss".
67
- def self.rgss_version=(value)
68
- return unless valid?(value)
69
- @rgss_version = transform(value)
71
+ # The default RGSS version for Eidolon to build if no argument is given to
72
+ # the +Eidolon.build+ method. This is +nil+ by default.
73
+ attr_accessor :rgss_version
70
74
  end
71
75
 
72
76
  # Builds the data structures for the desired RGSS version. Returns +true+ if
73
77
  # the data structures were built, +false+ otherwise. This is a safe method,
74
78
  # ensuring that only the data structures from a single RGSS version will be
75
79
  # built.
80
+ #
81
+ # If a block is given, the data structures are built before the block is
82
+ # executed and then automatically destroyed. This is particularly useful for
83
+ # temporarily accessing RGSSx data, and returns the return value of the given
84
+ # block.
76
85
  def self.build(version = @rgss_version)
77
- return false if version.nil?
78
- built? ? false : build!(version)
79
- end
80
-
81
- # Forces building of the data structures for the desired RGSS version.
82
- # Returns +true+ if the data structures were built, +false+ otherwise.
83
- def self.build!(version = @rgss_version)
84
- return false if version.nil?
85
- self.rgss_version = version
86
- @built.push(@rgss_version).compact.sort!.uniq!
87
- load 'eidolon/rgssx/loader.rb'
88
- load "eidolon/#{@rgss_version}/loader.rb"
89
- rescue LoadError
86
+ return false if version.nil? || built?
87
+ begin
88
+ load "eidolon/#{transform(version)}/loader.rb"
89
+ return true unless block_given?
90
+ rescue ArgumentError, LoadError
91
+ destroy!
92
+ return false
93
+ end
94
+ return_value = yield
90
95
  destroy!
91
- false
96
+ return_value
92
97
  end
93
98
 
94
99
  # Destroys the currently built RGSS data structures. Returns +true+ if the
@@ -108,22 +113,18 @@ module Eidolon
108
113
  class << self
109
114
  private
110
115
  # Transforms the given value into an applicable string used to find the
111
- # appropriate RGSS version.
116
+ # appropriate RGSS version. Returns the transformed string. Raises an
117
+ # +ArgumentError+ if the string could not be transformed.
112
118
  def transform(version)
119
+ return version if version == (string = 'rgss')
113
120
  if version =~ /^rgss(\d?)/i
114
- return 'rgss' if $1.empty?
115
- 'rgss' << $1
121
+ string << $1 unless $1.empty?
116
122
  else
117
- return 'rgss' if version == 1
118
- 'rgss' << version.to_s
123
+ string << version.to_s unless version.between?(0, 1)
119
124
  end
120
- end
121
-
122
- # Returns +true+ if a "loader.rb" file exists for the given RGSS version,
123
- # +false+ otherwise.
124
- def valid?(version)
125
- fn = File.dirname(__FILE__) << "/eidolon/#{transform(version)}/loader.rb"
126
- File.file?(fn)
125
+ string
126
+ rescue
127
+ raise ArgumentError.new("'#{version}' is an invalid RGSS version.")
127
128
  end
128
129
  end
129
130
  end
@@ -6,7 +6,8 @@
6
6
  # be loaded -- the actual order of loading them is unimportant (unlike the data
7
7
  # structures used by VX and VX Ace, which require some specific ordering).
8
8
 
9
- require 'eidolon/rgssx'
9
+ # Load the generic RGSSx data structures.
10
+ load 'eidolon/rgssx/loader.rb'
10
11
 
11
12
  load 'eidolon/rgss/rpg/actor.rb'
12
13
  load 'eidolon/rgss/rpg/armor.rb'
@@ -2,7 +2,8 @@
2
2
  # Essentially, requiring this file will build a generic copy of the VX data
3
3
  # structures for use in a Ruby installation outside of VX itself.
4
4
 
5
- require 'eidolon/rgssx'
5
+ # Load the generic RGSSx data structures.
6
+ load 'eidolon/rgssx/loader.rb'
6
7
 
7
8
  # Audio data structures.
8
9
  load 'eidolon/rgss2/rpg/bgm.rb'
@@ -2,7 +2,8 @@
2
2
  # Ace. Essentially, requiring this file will build a generic copy of the VX Ace
3
3
  # data structures for use in a Ruby installation outside of Ace itself.
4
4
 
5
- require 'eidolon/rgssx'
5
+ # Load the generic RGSSx data structures.
6
+ load 'eidolon/rgssx/loader.rb'
6
7
 
7
8
  # Audio data structures.
8
9
  load 'eidolon/rgss3/rpg/bgm.rb'
@@ -6,5 +6,5 @@ module Eidolon
6
6
  }
7
7
 
8
8
  # Semantic version of the Eidolon RGSSx builder.
9
- VERSION = '0.1.3'
9
+ VERSION = '0.2.0'
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eidolon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solistra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-25 00:00:00.000000000 Z
11
+ date: 2014-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard