Skip to content

Commit

Permalink
Unwind the dice bits
Browse files Browse the repository at this point in the history
They were interesting but ultimately unsatisfying. I want to focus on
the frame and then start filling it with mechanic.
  • Loading branch information
zspencer committed Feb 7, 2024
1 parent 4764b5f commit 867a8dc
Show file tree
Hide file tree
Showing 53 changed files with 264 additions and 706 deletions.
7 changes: 7 additions & 0 deletions app/furniture/layouts/slipvector.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%- content_for :content do %>
<%= turbo_frame_tag(surveyors_guild, data: { turbo_action: :advance }) do %>
<%= yield %>
<%- end %>
<%- end %>

<%= render template: "layouts/application" %>
3 changes: 3 additions & 0 deletions app/furniture/slipvector/_in_room_template.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= turbo_frame_tag(furniture, src: furniture.location, data: { turbo_action: :advance }) do %>
<%= render furniture %>
<%- end %>
19 changes: 19 additions & 0 deletions app/furniture/slipvector/breadcrumbs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

# @see https://github.com/kzkn/gretel

crumb :slipvector_survey do |survey|
parent :slipvector_star_system, survey.star_system
link survey.id, survey.location
end

crumb :slipvector_star_system do |star_system|
parent :slipvector_surveyors_guild, star_system.surveyors_guild
link star_system.name, star_system.location
end


crumb :slipvector_surveyors_guild do |surveyors_guild|
parent :room, surveyors_guild.room
link "Surveyors Guild", surveyors_guild.location
end
7 changes: 7 additions & 0 deletions app/furniture/slipvector/controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Slipvector
class Controller < ApplicationController
layout "slipvector"

expose :surveyors_guild, model: SurveyorsGuild
end
end
10 changes: 10 additions & 0 deletions app/furniture/slipvector/data_level.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Slipvector
class DataLevel
include ActiveModel::Model
include ActiveModel::Attributes
include ActiveModel::Validations

attribute :observes, :string
validates :observes, inclusion: {in: [:energy, :life, :materials, :oddities]}
end
end
10 changes: 10 additions & 0 deletions app/furniture/slipvector/data_level_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Slipvector
class DataLevelType < ActiveRecord::Type::Json
def deserialize(string)
return [] if string.nil?
super.map do |data_level|
DataLevel.new(**data_level)
end
end
end
end
24 changes: 9 additions & 15 deletions app/furniture/slipvector/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
en:
slipvector:
surveyors_guild:
star_systems:
create:
success: "Registered Star System!"
failure: "Couldn't Register Star System!"
star_system:
surveys:
create:
success: "Launched a Survey in Star System"
failure: "Couldn't Survey Star System"
survey:
rolls:
create:
success: "Experiment Complete!"
failure: "Experiment Failed!"

star_systems:
create:
success: "Registered Star System!"
failure: "Couldn't Register Star System!"
surveys:
create:
success: "Launched a Survey in Star System"
failure: "Couldn't Survey Star System"
1 change: 1 addition & 0 deletions app/furniture/slipvector/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render survey %>
17 changes: 17 additions & 0 deletions app/furniture/slipvector/star_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Slipvector
class StarSystem < Record
self.table_name = "slipvector_star_systems"

belongs_to :surveyors_guild, inverse_of: :star_systems
location(parent: :surveyors_guild)

attribute :data_levels, DataLevelType.new

has_many :surveys, inverse_of: :star_system, dependent: :destroy
has_many :active_surveys, -> { active }, class_name: :Survey

def name
super.presence || id
end
end
end
17 changes: 17 additions & 0 deletions app/furniture/slipvector/star_system_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Slipvector
class StarSystemPolicy < ApplicationPolicy
alias_method :star_system, :object

def create?
person&.operator? || person&.member_of?(star_system.surveyors_guild.space)
end

alias_method :update?, :create?

class Scope < ApplicationScope
def resolve
scope.all
end
end
end
end
22 changes: 22 additions & 0 deletions app/furniture/slipvector/star_systems/_star_system.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= render CardComponent.new do |card| %>
<%- card.with_header do %>
<h2><%= star_system.name %></h2>
<%- end %>

<%- @pagy, @surveys = pagy(policy_scope(star_system.surveys.complete.recent), items: 8) %>

<div class="grid sm:grid-cols-2">
<%= render @surveys %>
</div>

<%== pagy_nav(@pagy, nav_extra: 'flex justify-between') %>

<%- card.with_footer(variant: :action_bar) do %>
<%- if star_system.active_surveys.present? %>
<%- active_survey = star_system.active_surveys.first %>
<%= link_to "Resume Survey #{active_survey.id}", star_system.active_surveys.first.location, class: "w-full button" %>
<%- else %>
<%= button_to("Begin Survey", star_system.location(child: :surveys), params: { survey: { status: :active } }, form_class: "w-full", class: "w-full") %>
<%- end %>
<%- end %>
<%- end %>
5 changes: 5 additions & 0 deletions app/furniture/slipvector/star_systems/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%- breadcrumb :slipvector_star_system, star_system%>
<div class="my-4">
<%= link_to("⬅️ Back to Surveyors Guild", star_system.surveyors_guild.location) %>
</div>
<%= render star_system %>
22 changes: 22 additions & 0 deletions app/furniture/slipvector/star_systems_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Slipvector
class StarSystemsController < Controller
expose :star_system, scope: -> { surveyors_guild.star_systems }, model: StarSystem

def new
authorize(star_system)
end

def create
authorize(star_system)
if star_system.save
redirect_to(star_system.surveyors_guild.location, notice: t(".success"))
else
redirect_to(star_system.surveyors_guild.location, error: t(".failure"))
end
end

def show
authorize(star_system)
end
end
end
17 changes: 17 additions & 0 deletions app/furniture/slipvector/survey.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Slipvector
class Survey < Record
self.table_name = "slipvector_surveys"

belongs_to :star_system, inverse_of: :surveys
location(parent: :star_system)
has_one :surveyors_guild, through: :star_system

scope :recent, -> { order(updated_at: :desc) }

enum status: {
preparing: "preparing",
active: "active",
complete: "complete"
}
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Slipvector
class SurveyorsGuild::StarSystem::SurveyPolicy < ApplicationPolicy
class SurveyPolicy < ApplicationPolicy
alias_method :survey, :object

def create?
Expand Down
7 changes: 7 additions & 0 deletions app/furniture/slipvector/surveyors_guild.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ class SurveyorsGuild < Furniture
default_scope { where(furniture_kind: :slipvector_surveyors_guild) }
extend StripsNamespaceFromModelName

setting :star_system_tickets

location(parent: :room)

has_many :surveys, inverse_of: :surveyors_guild, dependent: :destroy
has_many :surveyed_star_systems, through: :surveys, class_name: :StarSystem
has_many :star_systems, dependent: :destroy, inverse_of: :surveyors_guild


def in_room_template
"slipvector/in_room_template"
end
end
end
6 changes: 3 additions & 3 deletions app/furniture/slipvector/surveyors_guild/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class SurveyorsGuild
class Routes
def self.append_routes(router)
router.resources(:surveyors_guilds, only: [:show], module: "slipvector") do
router.resources(:star_systems, only: [:new, :create, :show], module: "surveyors_guild") do
router.resources(:surveys, only: [:create, :show, :update], module: "star_system") do
router.resources(:rolls, only: [:create], module: "survey")
router.resources(:star_systems, only: [:new, :create, :show]) do
router.resources(:surveys, only: [:new, :create, :show, :update]) do
router.resources(:rolls, only: [:create])
end
end
end
Expand Down
28 changes: 0 additions & 28 deletions app/furniture/slipvector/surveyors_guild/star_system.rb

This file was deleted.

65 changes: 0 additions & 65 deletions app/furniture/slipvector/surveyors_guild/star_system/survey.rb

This file was deleted.

Loading

0 comments on commit 867a8dc

Please sign in to comment.