reinforce 0.2.4 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28a29c842c8aeb4abbaef8e61dc98ebb806d9f5d750b1e5d63f27183ec2b207b
4
- data.tar.gz: d80fc85f0d2b5e2a7f5b8cd6091852bbb398d4f3d8c31c5a822cbbf00d295aee
3
+ metadata.gz: da081d8d6618a6eceb817fe71f82d123888155c5570ff61da94c03e44ccb7b27
4
+ data.tar.gz: 40749866a2e40bb0b273c21d1552c094e41f8c60c2cf3be58c1987c7f498044d
5
5
  SHA512:
6
- metadata.gz: d1fda82069bdd02f0422c5cb1afc32a1f6e5a2cffe7adea3c8a9dc29402e6eed17338a00740ed8105f7d8969d1cb356a8de0e1bb305a296fd6dbbdb2ff395bca
7
- data.tar.gz: d4edac2bd51ee54e8eb4ff19c3eb28ff284bcdda52ca5fbc63f26f81141b7f1eb3818a165d0424325a73eaf6ca4f89d79383cc0e5c5477993dda395a1ad91c61
6
+ metadata.gz: cd5409a0c4544a3e62eded72e0465a5ca94e6649fd6467b7ec45dfa699996926a38448ffc06f7bc6ba0960fcbc216e06ce169a6ae933a2726883d8d54f4e3b04
7
+ data.tar.gz: 5f1ebb0e4bdf9f7214968fd2f79f9f43bfd18777ff4a3014ba27a8ea8b50fc58d169ead17e35d09a269b8e187e94a2c43a63fcd93e5744a57f438e17df103997
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Reinforce
4
4
  class Command
5
- attr_reader :action_type, :tick, :pbgid, :source, :index, :details
5
+ attr_reader :action_type, :tick, :source, :index, :details
6
+
7
+ PBGID_MAX = 2_147_483_648
6
8
 
7
9
  # rubocop:disable Metrics/AbcSize
8
10
  def initialize(command_hash, build_number)
@@ -11,12 +13,18 @@ module Reinforce
11
13
  @pbgid = command_hash.values.first[:pbgid]
12
14
  @source = command_hash.values.first[:source_identifier]
13
15
  @index = command_hash.values.first[:queue_index]
14
- @details = Attributes::Collection.instance.get_by_pbgid(@pbgid, build: build_number)
16
+ @details = Reinforce.dictionary.get_by_pbgid(@pbgid, build: build_number)
15
17
  @cancelled = false
16
18
  @suspect_from_tick = nil
17
19
  end
18
20
  # rubocop:enable Metrics/AbcSize
19
21
 
22
+ def pbgid
23
+ Reinforce.logger.warn("pbgid #{@pbgid} will overflow a 4-byte signed int") if @pbgid > PBGID_MAX
24
+
25
+ @pbgid
26
+ end
27
+
20
28
  def cancelled?
21
29
  @cancelled
22
30
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'singleton'
5
+
6
+ module Reinforce
7
+ class Dictionary
8
+ include Singleton
9
+ extend Forwardable
10
+
11
+ def_delegators :@collection, :get_by_pbgid, :get_by_path
12
+
13
+ def initialize
14
+ @collection = Attributes::Collection.new
15
+
16
+ [Attributes::Ability, Attributes::Entity, Attributes::Squad, Attributes::Upgrade].each do |klass|
17
+ generated_path = File.join(Reinforce.root, 'generated', klass::FILENAME)
18
+ File.open(generated_path) do |file|
19
+ data = JSON.parse(file.read)
20
+ data.each do |build, attributes|
21
+ @collection.populate(build, attributes.map { |a| klass.new(**a.transform_keys(&:to_sym)) }, rehash: false)
22
+ end
23
+ end
24
+ end
25
+
26
+ @collection.rehash_all
27
+ end
28
+ end
29
+ end
@@ -100,7 +100,7 @@ module Reinforce
100
100
  commands.each_with_index do |command, idx|
101
101
  next unless command.suspect?
102
102
 
103
- building_details = Attributes::Collection.instance.get_by_path(command.details&.builds, build: @build_number)
103
+ building_details = Reinforce.dictionary.get_by_path(command.details&.builds, build: @build_number)
104
104
  remaining = commands[(idx + 1)..]
105
105
  relevant = remaining.take_while { |c| c.pbgid != command.pbgid }
106
106
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Reinforce
4
- VERSION = '0.2.4'
4
+ VERSION = '0.3.1'
5
5
  end
data/lib/reinforce.rb CHANGED
@@ -12,6 +12,7 @@ require_relative 'reinforce/attributes/upgrade'
12
12
  require_relative 'reinforce/attributes/collection'
13
13
 
14
14
  require_relative 'reinforce/command'
15
+ require_relative 'reinforce/dictionary'
15
16
  require_relative 'reinforce/factory'
16
17
 
17
18
  require_relative 'reinforce/version'
@@ -32,6 +33,10 @@ module Reinforce
32
33
  Factory.new(player, build_number).build(with_cancellations:)
33
34
  end
34
35
 
36
+ def self.dictionary
37
+ Dictionary.instance
38
+ end
39
+
35
40
  # Parses data into structures for build order generation
36
41
  def self.generate(pretty: false)
37
42
  [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reinforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryantaylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-13 00:00:00.000000000 Z
11
+ date: 2024-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vault_coh
@@ -51,6 +51,7 @@ files:
51
51
  - lib/reinforce/attributes/squad.rb
52
52
  - lib/reinforce/attributes/upgrade.rb
53
53
  - lib/reinforce/command.rb
54
+ - lib/reinforce/dictionary.rb
54
55
  - lib/reinforce/factory.rb
55
56
  - lib/reinforce/version.rb
56
57
  homepage: https://github.com/ryantaylor/reinforce