Skip to content

Commit

Permalink
Add: Add setting to switch background
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Sep 28, 2024
1 parent ca99809 commit 211143d
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
frontend: cd frontend && pnpm dev
backend: cd backend && CONSOLE_OUTPUT=XTerm bundle exec falcon serve -b http://127.0.0.1:3000
backend-sidekiq: cd backend && CONSOLE_OUTPUT=XTerm bundle exec sidekiq
sub-audio: cd sub-audio && poetry poe dev
sub-audio: cd sub-audio && rye run dev
sub-image: cd sub-image && cargo run
sub-chart: cd sub-chart && pnpm dev

11 changes: 10 additions & 1 deletion backend/app/controllers/sonolus/info_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ def info
{ type: "configuration" }
],
configuration: {
options: []
options: [
{
query: :c_background,
name: I18n.t("sonolus.configuration.background.title"),
type: "select",
required: false,
def: 1,
values: I18n.t("sonolus.configuration.background.options")
}
]
},
description:
}
Expand Down
21 changes: 13 additions & 8 deletions backend/app/controllers/sonolus/levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ def info
author_id: [current_user.id] + alt_users.map(&:id)
)
.sonolus_listed
.map(&:to_sonolus)
.map { _1.to_sonolus(background_version:) }
}
end

popular_section = {
title: "#POPULAR",
itemType: "level",
items: self.popular_charts.map(&:to_sonolus)
items: self.popular_charts.map { _1.to_sonolus(background_version:) }
}

newest_section = {
Expand All @@ -170,7 +170,7 @@ def info
.eager_load(:tags, file_resources: { file_attachment: :blob })
.where(visibility: :public)
.sonolus_listed
.map(&:to_sonolus)
.map { _1.to_sonolus(background_version:) }
}
random_section = {
title: "#RANDOM",
Expand All @@ -183,7 +183,7 @@ def info
.eager_load(:tags, file_resources: { file_attachment: :blob })
.where(visibility: :public)
.sonolus_listed
.map(&:to_sonolus)
.map { _1.to_sonolus(background_version:) }
}
render json: {
searches:,
Expand Down Expand Up @@ -394,7 +394,7 @@ def list
charts = charts.offset([params[:page].to_i * 20, 0].max).limit(20)

render json: {
items: charts.map(&:to_sonolus),
items: charts.map { _1.to_sonolus(background_version:) },
searches:,
pageCount: page_count
}
Expand All @@ -412,7 +412,7 @@ def show
Like.find_by(user_id: current_user.id, chart_id: chart.id)

render json: {
item: chart.to_sonolus,
item: chart.to_sonolus(background_version: ),
hasCommunity: false,
actions: [
(
Expand Down Expand Up @@ -441,12 +441,17 @@ def show
{
title: I18n.t("sonolus.levels.sections.variant_of"),
itemType: "level",
items: [chart.variant_of&.to_sonolus]
items: [
chart.variant_of&.to_sonolus(background_version:)
].compact
},
{
title: I18n.t("sonolus.levels.sections.variants"),
itemType: "level",
items: chart.variants.map(&:to_sonolus)
items:
chart.variants.map {
_1.to_sonolus(background_version:)
}
},
{
title: I18n.t("sonolus.levels.sections.backgrounds"),
Expand Down
19 changes: 19 additions & 0 deletions backend/app/controllers/sonolus_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class SonolusController < ApplicationController
end
end

before_action do
params.permit(:c_background)
background_version = params[:c_background]
if background_version
self.background_version = [1, 3][background_version.to_i]
else
self.background_version = 3
end
end

around_action do |_, action|
unless request.headers["Sonolus-Session"]
action.call
Expand Down Expand Up @@ -68,6 +78,15 @@ def current_user=(value)
RequestLocals.store[:sonolus_auth_user] = value
end

def background_version
warn RequestLocals.store.inspect
RequestLocals.store[:sonolus_background_version]
end

def background_version=(value)
RequestLocals.store[:sonolus_background_version] = value
end

def dummy_level(key, name, cover: nil, **)
if cover.nil?
cover_data = { type: "LevelCover", url: "" }
Expand Down
4 changes: 2 additions & 2 deletions backend/app/models/chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def to_frontend(user: nil, with_resources: true, with_variants: false)
}
end

def to_sonolus
def to_sonolus(background_version: 3)
resources = self.resources
{
name: "chcy-#{name}",
Expand Down Expand Up @@ -136,7 +136,7 @@ def to_sonolus
},
useBackground: {
useDefault: false,
item: to_sonolus_background(resources)
item: to_sonolus_background(resources, version: background_version)
},
useEffect: {
useDefault: true
Expand Down
6 changes: 6 additions & 0 deletions backend/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ en:
sonolus:
title: "Chart Cyanvas"

configuration:
background:
title: "Background"
options:
- "v1"
- "v3"
auth:
external_done: "Successfully signed in! Now please go back to the website."
info:
Expand Down
9 changes: 8 additions & 1 deletion backend/config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ ja:
sonolus:
title: "Chart Cyanvas"

configuration:
background:
title: "背景"
options:
- "v1"
- "v3"

auth:
external_done: "ログインに成功しました!Webページに戻って下さい。"
info:
info:
description: "Chart Cyanvas は Sonolus 用の某セカイ創作譜面プラットフォームです。"
logged_in: "%{name}#%{handle} としてログインしています。"
backgrounds:
Expand Down
2 changes: 1 addition & 1 deletion sub-audio/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ COPY sub-audio/* .

EXPOSE 3203

CMD python main.py
CMD rye run start
2 changes: 2 additions & 0 deletions sub-audio/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dev-dependencies = [
[tool.rye.scripts]
test = "pytest"
lint = "ruff check ."
start = "gunicorn -w 2 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:3202 main:app"
dev = "uvicorn main:app --reload --port 3202"

[tool.hatch.metadata]
allow-direct-references = true
Expand Down

0 comments on commit 211143d

Please sign in to comment.