Skip to content

Commit

Permalink
Start inking in the line-of-action for the middle gameplay loop
Browse files Browse the repository at this point in the history
  • Loading branch information
zspencer committed Feb 24, 2024
1 parent 0c32b71 commit 8804573
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 49 deletions.
5 changes: 3 additions & 2 deletions app/furniture/slipvector/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def pundit_user

helper_method def current_surveyor
@current_surveyor ||= if session[:slipvector_current_surveyor_id]
@current_surveyor =
Surveyor.find(session[:slipvector_current_surveyor_id])
Surveyor.find_by(id: session[:slipvector_current_surveyor_id])
end


end

def current_surveyor= surveyor
Expand Down
17 changes: 17 additions & 0 deletions app/furniture/slipvector/crewmate_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Slipvector
class CrewmatePolicy < ApplicationPolicy
alias_method :crewmate, :object

def create?
person&.operator? || current_person.surveyor == crewmate.surveyor
end

alias_method :update?, :create?

class Scope < ApplicationScope
def resolve
scope.all
end
end
end
end
24 changes: 24 additions & 0 deletions app/furniture/slipvector/crewmates/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%= render CardComponent.new do |card| %>
<h3>Captain Darvin</h3>
<p>Welcome, <%= crewmate.surveyor.name %>!</p>

<p>It seems like you're interested in joining us on our survey of
<%= survey.star_system.name %>!</p>

<p>I know, quite a mouthful! Don't worry, if we find anything interesting
we'll give it an easier name!</p>

<p>I'm Captain Darvin, and my job is to make sure we arrive and return
safely.</p>

<p>Your job is to collect observations.</p>

<p>Ready?</p>

<%- card.with_footer(variant: :action_bar) do %>
<a href="<%= href_to(surveyors_guild) %>"
class="button --secondary w-1/2">Wait a sec, I'm not ready...</a>

<%= button_to "Let's Go!", survey.location(child: :crewmates), form_class: "w-1/2", class: "w-full --primary" %>
<%- end %>
<%- end %>
20 changes: 20 additions & 0 deletions app/furniture/slipvector/crewmates_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Slipvector
class CrewmatesController < Controller
expose :crewmate, scope: -> { policy_scope(survey.crewmates) }, model: Crewmate,
build: ->(params, scope) { scope.new(params.merge(surveyor: current_surveyor)) }
expose :survey, scope: -> { policy_scope(surveyors_guild.surveys.seeking_crew) }, model: Survey

def new
authorize(crewmate)
end

def create
authorize(crewmate)
if crewmate.save
redirect_to survey.location, notice: t(".success")
else
render :new, status: :unprocessable_entity
end
end
end
end
10 changes: 9 additions & 1 deletion app/furniture/slipvector/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
space = if Space.exists?(name: "Slipvector Demo")
Space.find_by(name: "Slipvector Demo")
else
FactoryBot.create(:space, :with_entrance, name: "Slipvector Demo")
FactoryBot.create(:space, name: "Slipvector Demo")
end

sol_system = if space.rooms.exists?(name: "Sol System")
space.rooms.find_by(name: "Sol System")
else
FactoryBot.create(:room, name: "Sol System", space:)
end

space.update(entrance: sol_system)

unless space.entrance.gizmos.exists?(furniture_kind: :slipvector_surveyors_guild)
FactoryBot.create(:slipvector_surveyors_guild, room: space.entrance)
end
11 changes: 2 additions & 9 deletions app/furniture/slipvector/star_systems/_star_system.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@
<%- end %>
</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 %>
<%- if @pagy.pages > 1 %>
<%== pagy_nav(@pagy, nav_extra: 'flex justify-between') %>
<%- end %>
<%- end %>
4 changes: 2 additions & 2 deletions app/furniture/slipvector/survey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Survey < Record
complete: "complete"
}

scope :preparing_or_active, -> { preparing.or(active) }

after_commit :update_star_system

def update_star_system
Expand All @@ -42,7 +44,5 @@ def results
DataLevel.new(elmo:, xp: rng.rand(3).times.sum { rng.rand(20) })
end
end


end
end
20 changes: 0 additions & 20 deletions app/furniture/slipvector/surveyors/_surveyor.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,3 @@
</dl>
<%- end %>
</div>

<h3>Surveys Seeking Crew</h3>
<%- surveyors_guild.surveys_seeking_crew.includes(:star_system).each do |survey| %>
<%= render CardComponent.new do |card| %>
<%- card.with_header do %>
<h4><%= survey.id%></h4>
<%- end %>
<p>Traveling to <%= survey.star_system.name %></p>

<%- card.with_footer(variant: :action_bar) do %>
<a
class="button w-full"
href="<%= href_to(survey, action: :new, child: :crewmate) %>">
Inquire
</a>


<%- end %>
<%- end %>
<%- end %>
4 changes: 4 additions & 0 deletions app/furniture/slipvector/surveyors/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<%- breadcrumb :slipvector_surveyor, surveyor %>
<div class="my-4">
<%= link_to("⬅️ Back to #{surveyors_guild.room.name}", surveyors_guild.location) %>
</div>

<%= render surveyor %>
4 changes: 2 additions & 2 deletions app/furniture/slipvector/surveyors_guild/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Routes
def self.append_routes(router)
router.resources(:surveyors_guilds, only: [:show], module: "slipvector") do
router.resources(:surveyors, only: [:new, :create, :show])
router.resources(:surveys, only: []) do
router.resources(:crewmates, only: [:new])
router.resources(:surveys, only: [:show, :update]) do
router.resources(:crewmates, only: [:new, :create])
end
router.resources(:star_systems, only: [:new, :create, :show]) do
router.resources(:surveys, only: [:new, :create, :show, :update]) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
<%- if current_surveyor.present?%>
<%= render current_surveyor %>
<div>
<h3>Surveys in Progress</h3>
<%- if current_surveyor.surveys.preparing_or_active.present? %>
<%- current_surveyor.surveys.preparing_or_active.includes(:star_system).each do |survey| %>
<%= render CardComponent.new do |card| %>
<%- card.with_header do %>
<h4><%= survey.id%></h4>
<%- end %>
<p>Traveling to <%= survey.star_system.name %></p>
<%- card.with_footer(variant: :action_bar) do %>
<a
class="button w-full"
href="<%= href_to(survey) %>">
Return to Survey
</a>
<%- end %>
<%- end %>
<%- end %>
<%- else %>
<h3>Surveys Seeking Crew</h3>
<%- surveyors_guild.surveys_seeking_crew.includes(:star_system).each do |survey| %>
<%= render CardComponent.new do |card| %>
<%- card.with_header do %>
<h4><%= survey.id%></h4>
<%- end %>
<p>Traveling to <%= survey.star_system.name %></p>

<%- card.with_footer(variant: :action_bar) do %>
<a
class="button w-full --primary"
href="<%= href_to(survey, action: :new, child: :crewmate) %>">
Inquire
</a>
<%- end %>
<%- end %>
<%- end %>
<%- end %>
</div>
<div>
<h3>Star Systems</h3>

<%= render surveyors_guild.star_systems %>
</div>
<%- else %>
Expand All @@ -20,7 +59,7 @@
-->

<a href="<%= href_to(surveyors_guild, action: :new, child: :surveyor) %>"
class="button w-full">I'd like to join the guild!</a>
class="button --primary w-full">I'd like to join the guild!</a>
<%- end %>
<%- end %>
<%- end %>
Empty file.
22 changes: 12 additions & 10 deletions app/furniture/slipvector/surveys/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
<%- breadcrumb :slipvector_survey, survey %>
<div class="my-4">
<%= link_to("⬅️ Back to #{star_system.name}", survey.star_system.location) %>
</div>
<%= render CardComponent.new do |card| %>
<%- card.with_header do %>
<h2><%= survey.id %></h2>
<p class="text-sm">Surveying <%= survey.star_system.name %></p>
<%- end %>
<p>Gathered...
<ul>
<%- survey.results.each do |result| %>
<li><%= result.xp %> <%= result.label %></li>
<%- end %>
</ul>
<%- if !survey.preparing? %>

<p>Gathered...
<ul>
<%- survey.results.each do |result| %>
<li><%= result.xp %> <%= result.label %></li>
<%- end %>
</ul>
<%- end %>
<%- card.with_footer(variant: :action_bar) do %>
<%- if survey.active? %>
<%= button_to("Complete Survey", survey.location, form_class: "w-full", class: "w-full", params: { survey: { status: :complete } })%>
<%= button_to("Complete Survey", survey.location, form_class: "w-full", class: "w-full --primary", params: { survey: { status: :complete } })%>
<%- elsif survey.preparing? %>
<%= link_to("Mmmm, one sec...", surveyors_guild.location, class: "button w-1/2") %>
<%= button_to("Embark", survey.location, form_class: "w-1/2", class: "w-full --primary", params: { survey: { status: :active } })%>
<%- end %>
<%- end %>
<%- end %>
15 changes: 13 additions & 2 deletions app/furniture/slipvector/surveys_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
class Slipvector
class SurveysController < Controller
expose :surveyor, scope: -> { policy_scope(Surveyor) }, model: Surveyor
expose :surveys, -> { policy_scope(surveyor.surveys) }
expose :surveys, (lambda do
surveys = if params[:surveyor_id].present?
surveyor.surveys
else
surveyors_guild.surveys
end
policy_scope(surveys)
end)

expose :survey, scope: -> { surveys }, model: Survey,
build: ->(params, scope) { scope.new(params.merge(surveyors: [surveyor])) }
Expand All @@ -22,7 +29,11 @@ def create
def update
authorize(survey)
survey.update(survey_params)
redirect_to(survey.star_system.location)
if survey.complete?
redirect_to(surveyors_guild.location)
else
redirect_to(survey.location)
end
end

def show
Expand Down

0 comments on commit 8804573

Please sign in to comment.