god_of_thunder_save 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a74ac6be19a0a4873e6cce405fcc2198ac5d45be9b59d5141ae3ae1cb163442
4
- data.tar.gz: 6a80bd7c0c364d6b9ecc8e41a3b627bbf2680120a9db81b7f2da62c34ed7a7ba
3
+ metadata.gz: b2ea1c9dfcd69f62206fd3f42b85892c84d3929fb033692d016e325374529198
4
+ data.tar.gz: a296ceb1ee63c8b33f4a458f1c99fe8b157fa5c8580c21e86f40131aeb5d6799
5
5
  SHA512:
6
- metadata.gz: 262a762da0a040b80b035b9b0acbb39f3f987aa5549189617c9ae5b7bc2425f16e0172042c21222b3b21b21cce9e87d807765fadb28db5acc96099271a6d18c9
7
- data.tar.gz: 88d2928c67d6b05e2ff97d4954fffbf6aa7a7d90e386ff4dc9ae367f8142833c36e87e15de9ee5d7691236f65b817b8479e125f76bac79f13deb849629f2dda0
6
+ metadata.gz: a77ccc5a6b5c93b1b50aed983e69e707b4cf7df12484df64abfb2b4a120d9a70846cb246af7013e2fcd20d13b7319eb558c8bd34f46014c6220200ed6615944f
7
+ data.tar.gz: 6ec55889d4be9ab2a77c115f6ef0ddde1e5e921fc3bf3f3a1d6af9c7a14c9b89a8d0957d0cb333e9abf12457b693fbad620c1ddc66445e3d92c3edaf7c5b826c
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GodOfThunderSave
4
+ class EnumValue
5
+ attr_reader :pos, :enums
6
+
7
+ def initialize(pos:, enums:)
8
+ @pos = pos
9
+ @enums = enums
10
+ end
11
+
12
+ def read(file)
13
+ file.seek(pos)
14
+ index = file.readchar
15
+
16
+ enums.invert.fetch(index)
17
+ end
18
+
19
+ def write(file, enum_key)
20
+ index = enums.fetch(enum_key)
21
+
22
+ file.seek(pos)
23
+ file.write(index)
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class GodOfThunderSave
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -1,15 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "god_of_thunder_save/bitmask_value"
4
+ require "god_of_thunder_save/enum_value"
4
5
  require "god_of_thunder_save/integer_value"
5
6
  require "god_of_thunder_save/string_value"
6
7
  require "god_of_thunder_save/version"
7
8
 
8
9
  class GodOfThunderSave
10
+ ITEM_ENUMS = {
11
+ nil => "\x00",
12
+ :enchanted_apple => "\x01",
13
+ :lightning_power => "\x02",
14
+ :winged_boots => "\x03",
15
+ :wind_power => "\x04",
16
+ :amulet_of_protection => "\x05",
17
+ :thunder_power => "\x06"
18
+ }.freeze
19
+
9
20
  ENTRIES = {
10
21
  name: StringValue.new(pos: 0x00, length: 22),
11
22
  health: IntegerValue.new(pos: 0x63, bytes: 1),
12
23
  magic: IntegerValue.new(pos: 0x64, bytes: 1),
24
+ item: EnumValue.new(pos: 0x68, enums: ITEM_ENUMS),
13
25
  jewels: IntegerValue.new(pos: 0x65, bytes: 2),
14
26
  keys: IntegerValue.new(pos: 0x67, bytes: 1),
15
27
  score: IntegerValue.new(pos: 0x70, bytes: 4),
@@ -31,27 +43,27 @@ class GodOfThunderSave
31
43
  end
32
44
 
33
45
  def attributes
34
- ENTRIES.keys.each_with_object({}) do |entry_name, hash|
35
- hash[entry_name] = instance_variable_get(:"@#{entry_name}")
46
+ ENTRIES.keys.to_h do |entry_name|
47
+ [entry_name, instance_variable_get(:"@#{entry_name}")]
36
48
  end
37
49
  end
38
50
 
39
- def write!
40
- File.open(path, File::RDWR) do |file|
51
+ def read!
52
+ File.open(path) do |file|
41
53
  ENTRIES.each do |entry_name, entry|
42
- memory_value = instance_variable_get(:"@#{entry_name}")
43
- entry.write(file, memory_value)
54
+ file_value = entry.read(file)
55
+ instance_variable_set(:"@#{entry_name}", file_value)
44
56
  end
45
57
  end
46
58
 
47
59
  self
48
60
  end
49
61
 
50
- def read!
51
- File.open(path) do |file|
62
+ def write!
63
+ File.open(path, File::RDWR) do |file|
52
64
  ENTRIES.each do |entry_name, entry|
53
- file_value = entry.read(file)
54
- instance_variable_set(:"@#{entry_name}", file_value)
65
+ memory_value = instance_variable_get(:"@#{entry_name}")
66
+ entry.write(file, memory_value)
55
67
  end
56
68
  end
57
69
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: god_of_thunder_save
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxwell Pray
@@ -46,6 +46,7 @@ extra_rdoc_files: []
46
46
  files:
47
47
  - lib/god_of_thunder_save.rb
48
48
  - lib/god_of_thunder_save/bitmask_value.rb
49
+ - lib/god_of_thunder_save/enum_value.rb
49
50
  - lib/god_of_thunder_save/integer_value.rb
50
51
  - lib/god_of_thunder_save/string_value.rb
51
52
  - lib/god_of_thunder_save/version.rb