From f0bf3cda75a886ecad4631eb3a0a2abbfbd85555 Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Mon, 25 May 2026 14:33:22 +0900 Subject: [PATCH] wip i18n separation --- .../frontend/src/world/room/defineObjectUi.ts | 15 +++++++++ packages/frontend/src/world/room/object.ts | 30 +++++++++--------- .../src/world/room/objects/allInOnePc.ts | 7 ----- .../src/world/room/objects/allInOnePc.ui.ts | 31 +++++++++++++++++++ 4 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 packages/frontend/src/world/room/defineObjectUi.ts create mode 100644 packages/frontend/src/world/room/objects/allInOnePc.ui.ts diff --git a/packages/frontend/src/world/room/defineObjectUi.ts b/packages/frontend/src/world/room/defineObjectUi.ts new file mode 100644 index 0000000000..026a6e2ad2 --- /dev/null +++ b/packages/frontend/src/world/room/defineObjectUi.ts @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import type { GetOptionsSchemaUiDef, OptionsSchema } from './object.js'; + +type UiDef = { + name: string; + options: GetOptionsSchemaUiDef; +}; + +export function defineObjectUi(def: UiDef): UiDef { + return def; +} diff --git a/packages/frontend/src/world/room/object.ts b/packages/frontend/src/world/room/object.ts index dd82341bef..1cc613ac79 100644 --- a/packages/frontend/src/world/room/object.ts +++ b/packages/frontend/src/world/room/object.ts @@ -26,7 +26,6 @@ export type RoomObjectInstance = { onInited?: () => void; onOptionsUpdated?: (kv: [K, V]) => void; interactions: Record void; }>; primaryInteraction?: string | null; @@ -36,7 +35,6 @@ export type RoomObjectInstance = { type NumberOptionSchema = { type: 'number'; - label: string; min?: number; max?: number; step?: number; @@ -44,41 +42,33 @@ type NumberOptionSchema = { type BooleanOptionSchema = { type: 'boolean'; - label: string; }; type StringOptionSchema = { type: 'string'; - label: string; }; type ColorOptionSchema = { type: 'color'; - label: string; }; type MaterialOptionSchema = { type: 'material'; - label: string; }; type LightOptionSchema = { type: 'light'; - label: string; }; type EnumOptionSchema = { type: 'enum'; - label: string; enum: { - label: string; value: string | number; }[]; }; type RangeOptionSchema = { type: 'range'; - label: string; min: number; max: number; step?: number; @@ -86,19 +76,16 @@ type RangeOptionSchema = { type ImageOptionSchema = { type: 'image'; - label: string; presets: { - label: string; value: string; }[]; }; type SeedOptionSchema = { type: 'seed'; - label: string; }; -type OptionsSchema = Record; +export type OptionsSchema = Record; export type RawOptions = Record & { readonly __brand: unique symbol; @@ -138,6 +125,20 @@ type GetConvertedOptionsSchemaValues = { T[K] extends SeedOptionSchema ? number : never; }; +export type GetOptionsSchemaUiDef = { + [K in keyof T]: + T[K] extends NumberOptionSchema ? { label: string; } : + T[K] extends BooleanOptionSchema ? { label: string; } : + T[K] extends StringOptionSchema ? { label: string; } : + T[K] extends ColorOptionSchema ? { label: string; } : + T[K] extends MaterialOptionSchema ? { label: string; } : + T[K] extends LightOptionSchema ? { label: string; } : + T[K] extends EnumOptionSchema ? { label: string; enum: Record; } : + T[K] extends RangeOptionSchema ? { label: string; } : + T[K] extends ImageOptionSchema ? { label: string; presets: Record; } : + T[K] extends SeedOptionSchema ? { label: string; } : + never; +}; export type SnapshotRenderingHelperWrapper = { updateMesh: (meshes: BABYLON.Mesh[]) => void; @@ -147,7 +148,6 @@ export type SnapshotRenderingHelperWrapper = { export type ObjectDef = { id: string; - name: string; options: { schema: string extends keyof OpSc ? OptionsSchema : OpSc; default: string extends keyof OpSc ? RawOptions : GetRawOptionsSchemaValues; // 関数にした方が使用側でdeepCloneの必要がなくて綺麗かもしれない diff --git a/packages/frontend/src/world/room/objects/allInOnePc.ts b/packages/frontend/src/world/room/objects/allInOnePc.ts index 3c53f6eff4..0eff4ab974 100644 --- a/packages/frontend/src/world/room/objects/allInOnePc.ts +++ b/packages/frontend/src/world/room/objects/allInOnePc.ts @@ -7,33 +7,26 @@ import * as BABYLON from '@babylonjs/core'; import { createTextureManager, defineObject } from '../object.js'; import { cm, WORLD_SCALE } from '../../utility.js'; import { getLightRangeFactorByGraphicsQuality } from '../utility.js'; -import { i18n } from '@/i18n.js'; export const allInOnePc = defineObject({ id: 'allInOnePc', - name: i18n.ts._miRoom._objects.allInOnePc, options: { schema: { bodyMat: { type: 'material', - label: i18n.ts._miRoom._objects._allInOnePc.bodyMat, }, bezelMat: { type: 'material', - label: i18n.ts._miRoom._objects._allInOnePc.bezelMat, }, screenBrightness: { type: 'range', - label: i18n.ts._miRoom._objects._allInOnePc.screenBrightness, min: 0, max: 1, step: 0.01, }, image: { type: 'image', - label: i18n.ts._miRoom._objects._allInOnePc.image, presets: [{ - label: i18n.ts._miRoom._objects._allInOnePc.image_desktop, value: 'desktop', }], }, diff --git a/packages/frontend/src/world/room/objects/allInOnePc.ui.ts b/packages/frontend/src/world/room/objects/allInOnePc.ui.ts new file mode 100644 index 0000000000..ef80152113 --- /dev/null +++ b/packages/frontend/src/world/room/objects/allInOnePc.ui.ts @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { defineObjectUi } from '../defineObjectUi.js'; +import type { allInOnePc } from './allInOnePc.js'; +import { i18n } from '@/i18n.js'; + +export const allInOnePc_ui = defineObjectUi({ + name: i18n.ts._miRoom._objects.allInOnePc, + options: { + bodyMat: { + label: i18n.ts._miRoom._objects._allInOnePc.bodyMat, + }, + bezelMat: { + label: i18n.ts._miRoom._objects._allInOnePc.bezelMat, + }, + screenBrightness: { + label: i18n.ts._miRoom._objects._allInOnePc.screenBrightness, + }, + image: { + label: i18n.ts._miRoom._objects._allInOnePc.image, + presets: { + 'desktop': { + label: i18n.ts._miRoom._objects._allInOnePc.image_desktop, + }, + }, + }, + }, +});