# frozen_string_literal: true require 'yaml' # Encapsulation of the user's Character class BaseCharacter class << self def load(file_path) char = YAML.safe_load(File.read(file_path)) sys = char['system'] raise StandardError, "Character file does not have a 'system' entry!" if sys.nil? || sys.empty? system_namespace = Object.const_get(sys) system_namespace::Character.new(char) rescue NameError raise StandardError, "System '#{sys}' not known - please check spelling." end end def initialize(character_data) @core = character_data calculate_skills end def calculate_skills; end def name @core['name'] end def attributes @core['attributes'] end def attr_names @core['attributes'].keys end def attr_values @core['attributes'].values end def skills @core['skills'].keys end def skill_value(skill_name) @skill_values[skill_name] end def basics_table; end def skills_table @core['skills'].map do |k, _| [k, skill_value(k)] end end def ratings_table @core['ratings'].to_a end def testable_skills unless defined? @testable_skills @testable_skills = @system::SKILLS.map do |skill, props| next unless props['untrained'] || skills.include?(skill) skill end.compact end @testable_skills end def rating(ability) if attributes.key? ability attributes[ability] elsif @core['skills'].key? ability skill_value(ability) else attributes[@system.attribute(ability)] end end end