You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.1 KiB
79 lines
2.1 KiB
import * as THREE from 'three'
|
|
import BaseRenderer from '@/core/base/BaseRenderer'
|
|
import BaseInteraction from '@/core/base/BaseInteraction'
|
|
import BaseEntity from '@/core/base/BaseItemEntity'
|
|
import type { PropertySetter } from "@/core/base/PropertyTypes.ts";
|
|
|
|
// Define the ModuleDefineOption interface
|
|
export interface ModuleDefineOption {
|
|
/**
|
|
* 物流单元类型名称
|
|
*/
|
|
name: string;
|
|
renderer: BaseRenderer;
|
|
interaction: BaseInteraction;
|
|
setter: PropertySetter;
|
|
entity: new () => BaseEntity;
|
|
}
|
|
|
|
// Internal storage for module definitions
|
|
const modules = new Map<string, ModuleDefineOption>()
|
|
window['modules'] = modules
|
|
|
|
/**
|
|
* 模块管理器
|
|
*/
|
|
export function defineModule(option: ModuleDefineOption): Promise<any> {
|
|
if (modules.has(option.name)) {
|
|
throw new Error(`Module with name "${option.name}" is already defined.`)
|
|
}
|
|
modules.set(option.name, option)
|
|
return option.renderer.init()
|
|
}
|
|
|
|
/**
|
|
* 获取模块
|
|
* 如果获取不了 直接抛异常
|
|
*/
|
|
export function getModuleOption(name: string): ModuleDefineOption {
|
|
const module = modules.get(name)
|
|
if (!module) {
|
|
throw new Error(`Module with name "${name}" is not defined.`)
|
|
}
|
|
return module
|
|
}
|
|
|
|
/**
|
|
* 根据物料类型名称, 获取其渲染器
|
|
* 如果获取不了 直接抛异常
|
|
*/
|
|
export function getRenderer<T extends BaseRenderer>(name: string): T {
|
|
const module = getModuleOption(name)
|
|
return module.renderer as T
|
|
}
|
|
|
|
/**
|
|
* 根据物料类型名称, 获取交互控制器
|
|
* 如果获取不了 直接抛异常
|
|
*/
|
|
export function getInteraction<T extends BaseInteraction>(name: string): T {
|
|
const module = getModuleOption(name)
|
|
return module.interaction as T
|
|
}
|
|
|
|
export function getSetter(name: string) {
|
|
const module = getModuleOption(name)
|
|
return module.setter;
|
|
}
|
|
|
|
/**
|
|
* 根据物料类型名称, 获取实体类
|
|
* 如果获取不了 直接抛异常
|
|
*/
|
|
export function createEntity<T extends BaseEntity>(name: string, itemjson: ItemJson, objects: THREE.Object3D[]): T {
|
|
const module = getModuleOption(name)
|
|
const v = new module.entity() as T
|
|
v.setItem(itemjson)
|
|
v.setObjects(objects)
|
|
return v
|
|
}
|