# frozen_string_literal: true require_relative "api/ability_id" require_relative "api/unit_type_id" require_relative "api/upgrade_id" require_relative "api/buff_id" require_relative "api/effect_id" require_relative "api/tech_tree" module Sc2 # Holds game data from tech tree and Api::ResponseData # Called once on game start class Data # @!attribute abilities # @return [Hash] AbilitId => AbilityData attr_accessor :abilities # @!attribute units # @return [Hash] UnitId => UnitData attr_accessor :units # @!attribute upgrades # @return [Hash] UpgradeId => UpgradeData attr_accessor :upgrades # @!attribute buffs # Not particularly useful data. Just use BuffId directly # @return [Hash] BuffId => BuffData attr_accessor :buffs # @!attribute effects # Not particularly useful data. Just use EffectId directly # @return [Hash] EffectId => EffectData attr_accessor :effects # @param data [Api::ResponseData] def initialize(data) return unless data @abilities = abilities_from_proto(data.abilities) @units = units_from_proto(data.units) @upgrades = upgrades_from_proto(data.upgrades) @buffs = buffs_from_proto(data.buffs) @effects = effects_from_proto(data.effects) end private # Indexes ability data by ability id # @param abilities [Array] # @return [Hash] # @return [Hash] indexed data def units_from_proto(units) result = {} units.each do |u| next unless u.available result[u.unit_id] = u end result end # Indexes upgrades data by id # @param upgrades [Array] # @return [Hash