added javascript for setting commands
This commit is contained in:
parent
fd5b598b63
commit
9e6fb755d9
@ -43,13 +43,10 @@ type SubObjectTypes = {
|
|||||||
[importCl in WorkadventureCommandClasses as importCl["subObjectIdentifier"]]: JustMethods<importCl>;
|
[importCl in WorkadventureCommandClasses as importCl["subObjectIdentifier"]]: JustMethods<importCl>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type WorkAdventureApiFiles = {
|
type WorkAdventureApi = {
|
||||||
[Key in WorkadventureFunctionsFilteredByRoot]: ShouldAddAttribute<Key>
|
[Key in WorkadventureFunctionsFilteredByRoot]: ShouldAddAttribute<Key>
|
||||||
} & SubObjectTypes
|
} & SubObjectTypes
|
||||||
|
|
||||||
export interface WorkAdventureApi extends WorkAdventureApiFiles {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|
||||||
@ -59,11 +56,31 @@ declare global {
|
|||||||
let WA: WorkAdventureApi
|
let WA: WorkAdventureApi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function populateWa(): Promise<void> {
|
||||||
|
const wa: Partial<WorkAdventureApi> = {}
|
||||||
|
for (const apiImport of await importType) {
|
||||||
|
const classInstance = apiImport.default
|
||||||
|
const commandPrototype = Object.getPrototypeOf(classInstance);
|
||||||
|
const commandClassPropertyNames = Object.getOwnPropertyNames(commandPrototype).filter(name => name !== "constructor");
|
||||||
|
const importObject: Partial<WorkAdventureApi> = {}
|
||||||
|
for (const prop of commandClassPropertyNames) {
|
||||||
|
const apiImportKey = prop as keyof typeof classInstance;
|
||||||
|
if (typeof classInstance[apiImportKey] === "function") {
|
||||||
|
importObject[apiImportKey as keyof WorkAdventureApi] = commandPrototype[apiImportKey] as never
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wa[classInstance.subObjectIdentifier] = importObject as never
|
||||||
|
if (classInstance.addMethodsAtRoot) {
|
||||||
|
Object.assign(wa, importObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.WA = {
|
window.WA = Object.assign({}, wa) as WorkAdventureApi
|
||||||
...({} as WorkAdventureApiFiles),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
populateWa()
|
||||||
|
|
||||||
window.addEventListener('message', message => {
|
window.addEventListener('message', message => {
|
||||||
if (message.source !== window.parent) {
|
if (message.source !== window.parent) {
|
||||||
return; // Skip message in this event listener
|
return; // Skip message in this event listener
|
||||||
|
Loading…
Reference in New Issue
Block a user