From 211143d45b5429a0a89ac66606fbda1586941504 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sun, 29 Sep 2024 08:56:12 +0900 Subject: [PATCH] Add: Add setting to switch background --- Procfile | 2 +- .../controllers/sonolus/info_controller.rb | 11 +++++++++- .../controllers/sonolus/levels_controller.rb | 21 ++++++++++++------- backend/app/controllers/sonolus_controller.rb | 19 +++++++++++++++++ backend/app/models/chart.rb | 4 ++-- backend/config/locales/en.yml | 6 ++++++ backend/config/locales/ja.yml | 9 +++++++- sub-audio/Dockerfile | 2 +- sub-audio/pyproject.toml | 2 ++ 9 files changed, 62 insertions(+), 14 deletions(-) diff --git a/Procfile b/Procfile index f383a09..b5e5f14 100644 --- a/Procfile +++ b/Procfile @@ -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 diff --git a/backend/app/controllers/sonolus/info_controller.rb b/backend/app/controllers/sonolus/info_controller.rb index b07a06c..b9ec281 100644 --- a/backend/app/controllers/sonolus/info_controller.rb +++ b/backend/app/controllers/sonolus/info_controller.rb @@ -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: } diff --git a/backend/app/controllers/sonolus/levels_controller.rb b/backend/app/controllers/sonolus/levels_controller.rb index e5e143b..52b5866 100644 --- a/backend/app/controllers/sonolus/levels_controller.rb +++ b/backend/app/controllers/sonolus/levels_controller.rb @@ -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 = { @@ -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", @@ -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:, @@ -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 } @@ -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: [ ( @@ -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"), diff --git a/backend/app/controllers/sonolus_controller.rb b/backend/app/controllers/sonolus_controller.rb index 4d6f75d..155bf52 100644 --- a/backend/app/controllers/sonolus_controller.rb +++ b/backend/app/controllers/sonolus_controller.rb @@ -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 @@ -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: "" } diff --git a/backend/app/models/chart.rb b/backend/app/models/chart.rb index 418f1e2..44b295c 100644 --- a/backend/app/models/chart.rb +++ b/backend/app/models/chart.rb @@ -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}", @@ -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 diff --git a/backend/config/locales/en.yml b/backend/config/locales/en.yml index fd35971..fa0a893 100644 --- a/backend/config/locales/en.yml +++ b/backend/config/locales/en.yml @@ -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: diff --git a/backend/config/locales/ja.yml b/backend/config/locales/ja.yml index e79ea69..dce4eaf 100644 --- a/backend/config/locales/ja.yml +++ b/backend/config/locales/ja.yml @@ -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: diff --git a/sub-audio/Dockerfile b/sub-audio/Dockerfile index e73f2aa..cb919a1 100644 --- a/sub-audio/Dockerfile +++ b/sub-audio/Dockerfile @@ -17,4 +17,4 @@ COPY sub-audio/* . EXPOSE 3203 -CMD python main.py +CMD rye run start diff --git a/sub-audio/pyproject.toml b/sub-audio/pyproject.toml index 86b5461..418b11f 100644 --- a/sub-audio/pyproject.toml +++ b/sub-audio/pyproject.toml @@ -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