2024-01-24 06:53:37 -08:00
|
|
|
class AltStylesController < ApplicationController
|
2024-09-30 17:21:45 -07:00
|
|
|
before_action :support_staff_only, except: [:index]
|
|
|
|
|
2024-01-24 06:53:37 -08:00
|
|
|
def index
|
2024-12-29 15:52:50 -08:00
|
|
|
@all_series_names = AltStyle.all_series_names
|
|
|
|
@all_color_names = AltStyle.all_supported_colors.map(&:human_name).sort
|
|
|
|
@all_species_names = AltStyle.all_supported_species.map(&:human_name).sort
|
2024-09-30 16:35:58 -07:00
|
|
|
|
2024-09-30 17:25:51 -07:00
|
|
|
@series_name = params[:series]
|
2024-09-30 16:06:22 -07:00
|
|
|
@color = find_color
|
|
|
|
@species = find_species
|
|
|
|
|
2024-12-29 15:52:50 -08:00
|
|
|
@alt_styles = AltStyle.includes(:color, :species, :swf_assets)
|
2024-09-30 17:25:51 -07:00
|
|
|
@alt_styles.where!(series_name: @series_name) if @series_name.present?
|
2024-09-30 16:06:22 -07:00
|
|
|
@alt_styles.merge!(@color.alt_styles) if @color
|
|
|
|
@alt_styles.merge!(@species.alt_styles) if @species
|
2024-01-28 07:30:06 -08:00
|
|
|
|
2024-09-30 16:35:58 -07:00
|
|
|
# We're using the HTML5 image for our preview, so make sure we have all the
|
2024-02-23 13:45:12 -08:00
|
|
|
# manifests ready!
|
|
|
|
SwfAsset.preload_manifests @alt_styles.map(&:swf_assets).flatten
|
|
|
|
|
2024-01-28 07:30:06 -08:00
|
|
|
respond_to do |format|
|
2024-11-15 20:28:38 -08:00
|
|
|
format.html {
|
|
|
|
@alt_styles = @alt_styles.
|
|
|
|
by_creation_date.order(:color_id, :species_id, :series_name).
|
|
|
|
paginate(page: params[:page], per_page: 30)
|
|
|
|
render
|
|
|
|
}
|
2024-01-29 03:20:48 -08:00
|
|
|
format.json {
|
2025-01-12 11:57:43 -08:00
|
|
|
@alt_styles = @alt_styles.includes(swf_assets: [:zone]).by_name_grouped
|
2024-11-15 20:28:38 -08:00
|
|
|
render json: @alt_styles.as_json(
|
2025-01-12 12:02:52 -08:00
|
|
|
only: [:id, :species_id, :color_id, :body_id, :thumbnail_url],
|
2024-01-31 03:02:19 -08:00
|
|
|
include: {
|
|
|
|
swf_assets: {
|
2024-02-24 16:25:55 -08:00
|
|
|
only: [:id, :body_id],
|
2024-01-31 03:02:19 -08:00
|
|
|
include: [:zone],
|
2024-02-24 16:31:05 -08:00
|
|
|
methods: [:urls, :known_glitches],
|
2024-01-31 03:02:19 -08:00
|
|
|
}
|
|
|
|
},
|
2025-01-12 12:02:52 -08:00
|
|
|
methods: [:series_main_name, :adjective_name],
|
2024-01-29 03:20:48 -08:00
|
|
|
)
|
|
|
|
}
|
2024-01-28 07:30:06 -08:00
|
|
|
end
|
2024-01-24 06:53:37 -08:00
|
|
|
end
|
2024-09-30 16:06:22 -07:00
|
|
|
|
2024-09-30 17:21:45 -07:00
|
|
|
def edit
|
|
|
|
@alt_style = AltStyle.find params[:id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@alt_style = AltStyle.find params[:id]
|
|
|
|
|
|
|
|
if @alt_style.update(alt_style_params)
|
|
|
|
flash[:notice] = "\"#{@alt_style.full_name}\" successfully saved!"
|
2024-10-22 16:39:25 -07:00
|
|
|
redirect_to destination_after_save
|
2024-09-30 17:21:45 -07:00
|
|
|
else
|
|
|
|
render action: :edit, status: :bad_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-09-30 16:06:22 -07:00
|
|
|
protected
|
|
|
|
|
2024-09-30 17:21:45 -07:00
|
|
|
def alt_style_params
|
Add configurable full name field to alt styles
Sigh, the "Valentine Plushie" series is messing with me again! It
doesn't follow the previously established pattern of the names being
"<series> <color> <species>", because in this case the base color is
considered "Valentine".
Okay, well! In this change we add `full_name` as an explicit database
field, and set the previous full name value as a fallback. (We also
extract the generic fallback logic into `ApplicationRecord`, to help us
express it more concisely.)
We also tweak `adjective_name` to be able to shorten custom `full_name`
values, too. That way, in the outfit editor, the Styles options show
correct values like "Cherub Plushie" for the "Cherub Plushie Acara".
I also make some changes in the outfit editor to better accommodate the
longer series names, to try to better handle long words but also to
just only use the first word of the series main name anyway. (Currently,
all series main names are one word, except "Valentine Plushie" becomes
"Valentine".)
2025-02-15 21:52:47 -08:00
|
|
|
params.require(:alt_style).
|
|
|
|
permit(:real_series_name, :real_full_name, :thumbnail_url)
|
2024-09-30 17:21:45 -07:00
|
|
|
end
|
|
|
|
|
2024-09-30 16:06:22 -07:00
|
|
|
def find_color
|
|
|
|
if params[:color]
|
|
|
|
Color.find_by(name: params[:color])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_species
|
|
|
|
if params[:species_id]
|
|
|
|
Species.find_by(id: params[:species_id])
|
|
|
|
elsif params[:species]
|
|
|
|
Species.find_by(name: params[:species])
|
|
|
|
end
|
|
|
|
end
|
2024-10-22 16:39:25 -07:00
|
|
|
|
|
|
|
def destination_after_save
|
|
|
|
if params[:next] == "unlabeled-style"
|
|
|
|
next_unlabeled_style_path
|
|
|
|
else
|
|
|
|
alt_styles_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_unlabeled_style_path
|
|
|
|
unlabeled_style = AltStyle.unlabeled.newest.first
|
|
|
|
if unlabeled_style
|
|
|
|
edit_alt_style_path(unlabeled_style, next: "unlabeled-style")
|
|
|
|
else
|
|
|
|
alt_styles_path
|
|
|
|
end
|
|
|
|
end
|
2024-01-24 06:53:37 -08:00
|
|
|
end
|