From cae8f698b0a3a8468f2e15da1b63737187f50103 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Tue, 6 Feb 2024 19:47:37 -0800 Subject: [PATCH] Refactor a bit --- Gemfile | 3 ++ Gemfile.lock | 3 ++ app/furniture/slipvector.rb | 6 +++ app/furniture/slipvector/README.md | 16 ++++---- app/furniture/slipvector/data_level.rb | 11 ++++- app/furniture/slipvector/star_system.rb | 2 +- .../slipvector/star_system/experience.rb | 40 +++++++++++++++++++ .../star_systems/_star_system.html.erb | 21 +++++++++- app/furniture/slipvector/survey.rb | 24 +++++++++++ .../_surveyors_guild.html.erb | 1 + .../slipvector/surveys/_survey.html.erb | 3 -- .../slipvector/surveys/show.html.erb | 8 ++++ ...42142_create_slipvector_surveyors_guild.rb | 3 +- db/schema.rb | 3 +- 14 files changed, 124 insertions(+), 20 deletions(-) create mode 100644 app/furniture/slipvector/star_system/experience.rb diff --git a/Gemfile b/Gemfile index 2100e43d4..5db833553 100644 --- a/Gemfile +++ b/Gemfile @@ -68,6 +68,9 @@ gem "strong_migrations", "~> 1.7" # Soft Deletion gem "discard", "~> 1.2" +# JSON models +gem "store_model" + # ActiveModel extension to remove extra whitespace from attributes gem "strip_attributes", "~> 1.13" diff --git a/Gemfile.lock b/Gemfile.lock index 0cec88ce7..002c4a1cc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -495,6 +495,8 @@ GEM rubocop-performance (~> 1.20.1) stimulus-rails (1.3.3) railties (>= 6.0.0) + store_model (1.2.0) + activerecord (>= 5.2) stringio (3.1.0) strip_attributes (1.13.0) activemodel (>= 3.0, < 8.0) @@ -593,6 +595,7 @@ DEPENDENCIES square.rb standard (~> 1.33) stimulus-rails + store_model strip_attributes (~> 1.13) stripe strong_migrations (~> 1.7) diff --git a/app/furniture/slipvector.rb b/app/furniture/slipvector.rb index 3ef65cf5a..a50a9416f 100644 --- a/app/furniture/slipvector.rb +++ b/app/furniture/slipvector.rb @@ -1,2 +1,8 @@ class Slipvector + ELMOS = { + energy: "⚡️ Energy", + life: "🧬 Life", + matter: "⚛️ Matter", + oddities: "⁉️ Oddity" + } end diff --git a/app/furniture/slipvector/README.md b/app/furniture/slipvector/README.md index 2e144f0a2..a4fae1d06 100644 --- a/app/furniture/slipvector/README.md +++ b/app/furniture/slipvector/README.md @@ -59,14 +59,14 @@ Binds [Star Systems](#star-systems) together. By spending considerable [Energy]( Every [Star System](#star-systems) in Slipvector has Potential and Kinetic ELMO -- [Energy](#energy) -- [Matter](#matter) -- [Life](#life) -- [Oddity](#oddity) +- [⚡️ Energy](#energy) +- [⚛️ Matter](#matter) +- [🧬 Life](#life) +- [⁉️ Oddity](#oddity) -#### Energy -#### Matter +#### ⚡️ Energy +#### ⚛️ Matter -#### Life +#### 🧬 Life -#### Oddity +#### ⁉️ Oddity diff --git a/app/furniture/slipvector/data_level.rb b/app/furniture/slipvector/data_level.rb index 95bb9fe7e..6bd0a6cdf 100644 --- a/app/furniture/slipvector/data_level.rb +++ b/app/furniture/slipvector/data_level.rb @@ -4,7 +4,14 @@ class DataLevel include ActiveModel::Attributes include ActiveModel::Validations - attribute :observes, :string - validates :observes, inclusion: {in: [:energy, :life, :materials, :oddities]} + attribute :elmo, :string + validates :elmo, inclusion: {in: [:energy, :life, :materials, :oddities]} + + attribute :xp, :integer + validates :xp, numericality: true + + def label + ELMOS.fetch(elmo.to_sym) + end end end diff --git a/app/furniture/slipvector/star_system.rb b/app/furniture/slipvector/star_system.rb index 219fc98a1..d0858bb7d 100644 --- a/app/furniture/slipvector/star_system.rb +++ b/app/furniture/slipvector/star_system.rb @@ -5,7 +5,7 @@ class StarSystem < Record belongs_to :surveyors_guild, inverse_of: :star_systems location(parent: :surveyors_guild) - attribute :data_levels, DataLevelType.new + attribute :experience, Experience.to_type, default: -> { Experience.new } has_many :surveys, inverse_of: :star_system, dependent: :destroy has_many :active_surveys, -> { active }, class_name: :Survey diff --git a/app/furniture/slipvector/star_system/experience.rb b/app/furniture/slipvector/star_system/experience.rb new file mode 100644 index 000000000..a1a2dc4e2 --- /dev/null +++ b/app/furniture/slipvector/star_system/experience.rb @@ -0,0 +1,40 @@ +class Slipvector + class StarSystem::Experience + include StoreModel::Model + + attribute :energy, :integer, default: 0 + attribute :energy_level, :integer, default: 1 + attribute :life, :integer, default: 0 + attribute :life_level, :integer, default: 1 + attribute :matter, :integer, default: 0 + attribute :matter_level, :integer, default: 1 + attribute :oddities, :integer, default: 0 + attribute :oddities_level, :integer, default: 1 + + def bump(result) + assign_attributes({result.elmo => attribute(result.elmo) + result.xp}) + end + + def pools + @experience ||= [ + Level.new(elmo: :energy, xp: energy, level: energy_level), + Level.new(elmo: :life, xp: life, level: life_level), + Level.new(elmo: :matter, xp: matter, level: matter_level), + Level.new(elmo: :oddities, xp: oddities, level: oddities_level) + ] + end + + class Level < DataLevel + attribute :level, :integer, default: 0 + + def next_level_xp + level * 125 + end + + def ready_for_level_up? + xp > next_level_xp + end + + end + end +end diff --git a/app/furniture/slipvector/star_systems/_star_system.html.erb b/app/furniture/slipvector/star_systems/_star_system.html.erb index d43c62365..8684e9973 100644 --- a/app/furniture/slipvector/star_systems/_star_system.html.erb +++ b/app/furniture/slipvector/star_systems/_star_system.html.erb @@ -1,12 +1,29 @@ <%= render CardComponent.new do |card| %> <%- card.with_header do %>
Surveying <%= survey.star_system.name %>
<%- end %> +Gathered... +