mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-06-25 17:10:43 +00:00
wip i18n separation
This commit is contained in:
parent
bf28b303d7
commit
f0bf3cda75
4 changed files with 61 additions and 22 deletions
15
packages/frontend/src/world/room/defineObjectUi.ts
Normal file
15
packages/frontend/src/world/room/defineObjectUi.ts
Normal file
|
|
@ -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<OpSc extends OptionsSchema = OptionsSchema> = {
|
||||
name: string;
|
||||
options: GetOptionsSchemaUiDef<OpSc>;
|
||||
};
|
||||
|
||||
export function defineObjectUi<const Def extends { options: { schema: OptionsSchema } }>(def: UiDef<Def['options']['schema']>): UiDef<Def['options']['schema']> {
|
||||
return def;
|
||||
}
|
||||
|
|
@ -26,7 +26,6 @@ export type RoomObjectInstance<Options = any> = {
|
|||
onInited?: () => void;
|
||||
onOptionsUpdated?: <K extends keyof Options, V extends Options[K]>(kv: [K, V]) => void;
|
||||
interactions: Record<string, {
|
||||
label: string;
|
||||
fn: () => void;
|
||||
}>;
|
||||
primaryInteraction?: string | null;
|
||||
|
|
@ -36,7 +35,6 @@ export type RoomObjectInstance<Options = any> = {
|
|||
|
||||
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<string, NumberOptionSchema | BooleanOptionSchema | StringOptionSchema | ColorOptionSchema | MaterialOptionSchema | LightOptionSchema | EnumOptionSchema | RangeOptionSchema | ImageOptionSchema | SeedOptionSchema>;
|
||||
export type OptionsSchema = Record<string, NumberOptionSchema | BooleanOptionSchema | StringOptionSchema | ColorOptionSchema | MaterialOptionSchema | LightOptionSchema | EnumOptionSchema | RangeOptionSchema | ImageOptionSchema | SeedOptionSchema>;
|
||||
|
||||
export type RawOptions = Record<string, unknown> & {
|
||||
readonly __brand: unique symbol;
|
||||
|
|
@ -138,6 +125,20 @@ type GetConvertedOptionsSchemaValues<T extends OptionsSchema> = {
|
|||
T[K] extends SeedOptionSchema ? number :
|
||||
never;
|
||||
};
|
||||
export type GetOptionsSchemaUiDef<T extends OptionsSchema> = {
|
||||
[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]['enum'][number]['value'], { label: string; }>; } :
|
||||
T[K] extends RangeOptionSchema ? { label: string; } :
|
||||
T[K] extends ImageOptionSchema ? { label: string; presets: Record<T[K]['presets'][number]['value'], { label: string; }>; } :
|
||||
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<OpSc extends OptionsSchema = OptionsSchema> = {
|
||||
id: string;
|
||||
name: string;
|
||||
options: {
|
||||
schema: string extends keyof OpSc ? OptionsSchema : OpSc;
|
||||
default: string extends keyof OpSc ? RawOptions : GetRawOptionsSchemaValues<OpSc>; // 関数にした方が使用側でdeepCloneの必要がなくて綺麗かもしれない
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
}],
|
||||
},
|
||||
|
|
|
|||
31
packages/frontend/src/world/room/objects/allInOnePc.ui.ts
Normal file
31
packages/frontend/src/world/room/objects/allInOnePc.ui.ts
Normal file
|
|
@ -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<typeof allInOnePc>({
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue