/
Mativ
/
solo-master
Обзор
Документация
Войти
/
Mativ
/
solo-master
Код
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/shared/Model.ts
161 строка
4 KB
mativ
control
14 май 2026, 08:41
14 май 2026, 08:41
a3c5022
Код
Авторство
О чём код?
import { TokenInstanceModificator } from "./TokenInstanceModificator"; import { TokenInstanceStatus } from "./TokenInstanceStatus"; export type { TokenInstanceModificator } from "./TokenInstanceModificator"; export type { TokenInstanceStatus } from "./TokenInstanceStatus"; export type OnModelChange = (type: string) => void; export type OnLoadChange = () => void; export interface AppImage { uid: string, base64: string, } export type EntityType = "label" | "token" | "sound"; export interface Entity { uid: string; type: EntityType; name: string; tag: string; image?: AppImage; notes?: string; } export interface LabelEntity extends Entity { readonly type: "label"; wallpaperId?: string; } export interface SoundEntity extends Entity { readonly type: "sound"; tracklist: string[]; volume: number; repeat: boolean; shuffle: boolean; ambient: boolean; } export const TOKEN_SIZES = [ { name: "Крошечный", value: 0.5 }, { name: "Маленький", value: 0.75 }, { name: "Средний", value: 1 }, { name: "Большой", value: 2 }, { name: "Огромный", value: 3 }, { name: "Гигантский", value: 4 }, ] as const; export function getTokenSizeValue(size: string | undefined): number { return TOKEN_SIZES.find(s => s.name === size)?.value ?? 1; } export interface TokenEntity extends Entity { readonly type: "token"; hp: string, ac: number, initiative: number, size?: string, } export type AnyEntity = LabelEntity | TokenEntity | SoundEntity; export type AnyInstance = LabelInstance | TokenInstance | SoundInstance; interface EntityInstance<T extends "label" | "token" | "sound"> { readonly type: T, instanceUid: string, entityUid: string, view: { x: number, y: number, width: number, height: number, } } export type LabelInstance = EntityInstance<"label">; export type SoundInstance = EntityInstance<"sound">; export interface TokenInstance extends EntityInstance<"token"> { hp: { max: number, val: number, }, postfix: string, isdead: boolean, modificator: TokenInstanceModificator, statuses: TokenInstanceStatus[], } export interface TrackerGroup { groupUid: string, collapsed: boolean, entityUid: string, initiative: number, } export interface Wallpaper { image: AppImage, name?: string, } export const defaultModelData = { name: "Новый проект", workspace: { map: { image: { uid: "", base64: "", }, scale: 1, opacity: 1, }, camera: { x: 0, y: 0, zoom: 1, }, instances: { labels: [] as LabelInstance[], tokens: [] as TokenInstance[], sounds: [] as SoundInstance[], }, }, entities: [] as AnyEntity[], wallpapers: [] as Wallpaper[], service: { instances: { hoveredUid: undefined as string | undefined, selectedUid: undefined as string | undefined, }, settings: { noteFontSize: 12, showGrid: false, showLabelsText: true, showTokensText: true, tokensAutoBloody: true, viewTransform: { fit: 'contain' as 'contain' | 'fill', rotation: 0 as 0 | 90 | 180 | 270, flipH: false, flipV: false, }, }, selectedWallpaperUid: undefined as string | undefined, }, tracker: { config: { hideDead: false, }, groups: [] as TrackerGroup[], instanceUidList: [] as string[], currentInstanceUid: undefined as string | undefined, }, }; export type ModelData = typeof defaultModelData; export interface ViewSettings { title: string }