ds4/src/documents/actor/proxy.js

29 lines
861 B
JavaScript

// SPDX-FileCopyrightText: 2022 Johannes Loher
//
// SPDX-License-Identifier: MIT
import { getGame } from "../../utils/utils";
import { DS4Actor } from "./actor";
import { DS4Character } from "./character/character";
import { DS4Creature } from "./creature/creature";
const handler = {
/**
* @param {typeof import("./actor").DS4Actor}
* @param {unknown[]} args
*/
construct(_, args) {
switch (args[0]?.type) {
case "character":
return new DS4Character(...args);
case "creature":
return new DS4Creature(...args);
default:
throw new Error(getGame().i18n.format("DS4.ErrorInvalidActorType", { type: args[0]?.type }));
}
},
};
/** @type {typeof import("./actor").DS4Actor} */
export const DS4ActorProxy = new Proxy(DS4Actor, handler);