@workadventure/scripting-api-extra
Advanced tools
Comparing version
@@ -13,8 +13,8 @@ "use strict"; | ||
if (WA.state[variable.name]) { | ||
let layers = variable.properties.getMany("openLayer"); | ||
for (const layer of layers) { | ||
let layers = variable.properties.mustGetString("openLayer"); | ||
for (const layer of layers.split("\n")) { | ||
WA.room.showLayer(layer); | ||
} | ||
layers = variable.properties.getMany("closeLayer"); | ||
for (const layer of layers) { | ||
layers = variable.properties.mustGetString("closeLayer"); | ||
for (const layer of layers.split("\n")) { | ||
WA.room.hideLayer(layer); | ||
@@ -24,8 +24,8 @@ } | ||
else { | ||
let layers = variable.properties.getMany("openLayer"); | ||
for (const layer of layers) { | ||
let layers = variable.properties.mustGetString("openLayer"); | ||
for (const layer of layers.split("\n")) { | ||
WA.room.hideLayer(layer); | ||
} | ||
layers = variable.properties.getMany("closeLayer"); | ||
for (const layer of layers) { | ||
layers = variable.properties.mustGetString("closeLayer"); | ||
for (const layer of layers.split("\n")) { | ||
WA.room.showLayer(layer); | ||
@@ -36,7 +36,7 @@ } | ||
function playOpenSound(variable) { | ||
const url = variable.properties.getOneString("openSound"); | ||
const radius = variable.properties.getOneNumber("soundRadius"); | ||
const url = variable.properties.getString("openSound"); | ||
const radius = variable.properties.getNumber("soundRadius"); | ||
let volume = 1; | ||
if (radius) { | ||
const distance = getDistance(variable.properties.getMany("openLayer")); | ||
const distance = getDistance(variable.properties.mustGetString("openLayer").split("\n")); | ||
if (distance > radius) { | ||
@@ -54,7 +54,7 @@ return; | ||
function playCloseSound(variable) { | ||
const url = variable.properties.getOneString("closeSound"); | ||
const radius = variable.properties.getOneNumber("soundRadius"); | ||
const url = variable.properties.getString("closeSound"); | ||
const radius = variable.properties.getNumber("soundRadius"); | ||
let volume = 1; | ||
if (radius) { | ||
const distance = getDistance(variable.properties.getMany("closeLayer")); | ||
const distance = getDistance(variable.properties.mustGetString("closeLayer").split("\n")); | ||
if (distance > radius) { | ||
@@ -97,7 +97,7 @@ return; | ||
let inZone = false; | ||
const zoneName = properties.getOneString("zone"); | ||
const zoneName = properties.getString("zone"); | ||
if (!zoneName) { | ||
throw new Error('Missing "zone" property on doorstep layer "' + name + '"'); | ||
} | ||
const tag = properties.getOneString("tag"); | ||
const tag = properties.getString("tag"); | ||
let allowed = true; | ||
@@ -114,3 +114,3 @@ if (tag && !WA.player.tags.includes(tag)) { | ||
actionMessage = WA.ui.displayActionMessage({ | ||
message: (_a = properties.getOneString("closeTriggerMessage")) !== null && _a !== void 0 ? _a : "Press SPACE to close the door", | ||
message: (_a = properties.getString("closeTriggerMessage")) !== null && _a !== void 0 ? _a : "Press SPACE to close the door", | ||
callback: () => { | ||
@@ -128,3 +128,3 @@ WA.state[doorVariable] = false; | ||
actionMessage = WA.ui.displayActionMessage({ | ||
message: (_a = properties.getOneString("openTriggerMessage")) !== null && _a !== void 0 ? _a : "Press SPACE to open the door", | ||
message: (_a = properties.getString("openTriggerMessage")) !== null && _a !== void 0 ? _a : "Press SPACE to open the door", | ||
callback: () => { | ||
@@ -158,3 +158,3 @@ WA.state[doorVariable] = true; | ||
inZone = true; | ||
if (properties.getOneBoolean("autoOpen") && allowed) { | ||
if (properties.getBoolean("autoOpen") && allowed) { | ||
WA.state[doorVariable] = true; | ||
@@ -165,3 +165,3 @@ return; | ||
((accessRestricted && !allowed) || !accessRestricted) && | ||
(properties.getOneString("code") || properties.getOneString("codeVariable"))) { | ||
(properties.getString("code") || properties.getString("codeVariable"))) { | ||
openKeypad(name); | ||
@@ -182,3 +182,3 @@ return; | ||
inZone = false; | ||
if (properties.getOneBoolean("autoClose")) { | ||
if (properties.getBoolean("autoClose")) { | ||
WA.state[doorVariable] = false; | ||
@@ -193,3 +193,3 @@ } | ||
if (inZone) { | ||
if (!properties.getOneBoolean("autoClose") && WA.state[doorVariable] === true) { | ||
if (!properties.getBoolean("autoClose") && WA.state[doorVariable] === true) { | ||
displayCloseDoorMessage(); | ||
@@ -200,3 +200,3 @@ } | ||
} | ||
if (!properties.getOneBoolean("autoOpen") && WA.state[doorVariable] === false) { | ||
if (!properties.getBoolean("autoOpen") && WA.state[doorVariable] === false) { | ||
displayOpenDoorMessage(); | ||
@@ -208,4 +208,4 @@ } | ||
function playBellSound(variable) { | ||
const url = variable.properties.mustGetOneString("bellSound"); | ||
const radius = variable.properties.getOneNumber("soundRadius"); | ||
const url = variable.properties.mustGetString("bellSound"); | ||
const radius = variable.properties.getNumber("soundRadius"); | ||
let volume = 1; | ||
@@ -235,4 +235,4 @@ if (radius) { | ||
let popup = undefined; | ||
const zoneName = properties.mustGetOneString("zone"); | ||
const bellPopupName = properties.getOneString("bellPopup"); | ||
const zoneName = properties.mustGetString("zone"); | ||
const bellPopupName = properties.getString("bellPopup"); | ||
WA.room.onEnterZone(zoneName, () => { | ||
@@ -246,3 +246,3 @@ var _a; | ||
{ | ||
label: (_a = properties.getOneString("bellButtonText")) !== null && _a !== void 0 ? _a : "Ring", | ||
label: (_a = properties.getString("bellButtonText")) !== null && _a !== void 0 ? _a : "Ring", | ||
callback: () => { | ||
@@ -266,6 +266,6 @@ WA.state[bellVariable] = WA.state[bellVariable] + 1; | ||
for (const variable of variables.values()) { | ||
if (variable.properties.getOne("door")) { | ||
if (variable.properties.get("door")) { | ||
initDoor(variable); | ||
} | ||
if (variable.properties.getOne("bell")) { | ||
if (variable.properties.get("bell")) { | ||
initBell(variable); | ||
@@ -276,7 +276,7 @@ } | ||
const properties = new Properties_1.Properties(layer.properties); | ||
const doorVariable = properties.getOneString("doorVariable"); | ||
const doorVariable = properties.getString("doorVariable"); | ||
if (doorVariable && layer.type === "tilelayer") { | ||
initDoorstep(layer, doorVariable, properties); | ||
} | ||
const bellVariable = properties.getOneString("bellVariable"); | ||
const bellVariable = properties.getString("bellVariable"); | ||
if (bellVariable) { | ||
@@ -283,0 +283,0 @@ initBellLayer(bellVariable, properties); |
@@ -10,12 +10,12 @@ "use strict"; | ||
const properties = new Properties_1.Properties(layer.properties); | ||
const variableName = properties.getOneString("bindVariable"); | ||
const variableName = properties.getString("bindVariable"); | ||
if (variableName) { | ||
const zone = properties.getOneString("zone"); | ||
const zone = properties.getString("zone"); | ||
if (!zone) { | ||
throw new Error('A layer with a "bindVariable" property must ALSO have a "zone" property.'); | ||
} | ||
const enterValue = properties.getOne("enterValue"); | ||
const leaveValue = properties.getOne("leaveValue"); | ||
const triggerMessage = properties.getOneString("triggerMessage"); | ||
const tag = properties.getOneString("tag"); | ||
const enterValue = properties.get("enterValue"); | ||
const leaveValue = properties.get("leaveValue"); | ||
const triggerMessage = properties.getString("triggerMessage"); | ||
const tag = properties.getString("tag"); | ||
initVariableActionLayer(variableName, zone, enterValue, leaveValue, triggerMessage, tag); | ||
@@ -22,0 +22,0 @@ } |
@@ -22,4 +22,4 @@ "use strict"; | ||
const properties = new Properties_1.Properties(layer.properties); | ||
const tmpCode = properties.getOneString("code"); | ||
const codeVariable = properties.getOneString("codeVariable"); | ||
const tmpCode = properties.getString("code"); | ||
const codeVariable = properties.getString("codeVariable"); | ||
if (tmpCode === undefined && codeVariable === undefined) { | ||
@@ -37,3 +37,3 @@ throw new Error('Missing "code" or "codeVariable" for layer "' + layerName + '".'); | ||
} | ||
const doorVariableVal = properties.getOneString("doorVariable"); | ||
const doorVariableVal = properties.getString("doorVariable"); | ||
if (doorVariableVal === undefined) { | ||
@@ -40,0 +40,0 @@ throw new Error('Missing "doorVariable" for layer "' + layerName + '".'); |
@@ -5,12 +5,11 @@ import { ITiledMapProperty } from "@workadventure/tiled-map-type-guard/dist"; | ||
constructor(properties: ITiledMapProperty[] | undefined); | ||
getMany(name: string): (string | boolean | number | undefined)[]; | ||
getOne(name: string): string | boolean | number | undefined; | ||
getOneString(name: string): string | undefined; | ||
getOneNumber(name: string): number | undefined; | ||
getOneBoolean(name: string): boolean | undefined; | ||
private getOneByType; | ||
mustGetOneString(name: string): string; | ||
mustGetOneNumber(name: string): number; | ||
mustGetOneBoolean(name: string): boolean; | ||
private mustGetOneByType; | ||
get(name: string): string | boolean | number | undefined; | ||
getString(name: string): string | undefined; | ||
getNumber(name: string): number | undefined; | ||
getBoolean(name: string): boolean | undefined; | ||
private getByType; | ||
mustGetString(name: string): string; | ||
mustGetNumber(name: string): number; | ||
mustGetBoolean(name: string): boolean; | ||
private mustGetByType; | ||
} |
@@ -8,9 +8,6 @@ "use strict"; | ||
} | ||
getMany(name) { | ||
return this.properties | ||
get(name) { | ||
const values = this.properties | ||
.filter((property) => property.name === name) | ||
.map((property) => property.value); | ||
} | ||
getOne(name) { | ||
const values = this.getMany(name); | ||
if (values.length > 1) { | ||
@@ -24,13 +21,13 @@ throw new Error('Expected only one property to be named "' + name + '"'); | ||
} | ||
getOneString(name) { | ||
return this.getOneByType(name, "string"); | ||
getString(name) { | ||
return this.getByType(name, "string"); | ||
} | ||
getOneNumber(name) { | ||
return this.getOneByType(name, "number"); | ||
getNumber(name) { | ||
return this.getByType(name, "number"); | ||
} | ||
getOneBoolean(name) { | ||
return this.getOneByType(name, "boolean"); | ||
getBoolean(name) { | ||
return this.getByType(name, "boolean"); | ||
} | ||
getOneByType(name, type) { | ||
const value = this.getOne(name); | ||
getByType(name, type) { | ||
const value = this.get(name); | ||
if (value === undefined) { | ||
@@ -44,13 +41,13 @@ return undefined; | ||
} | ||
mustGetOneString(name) { | ||
return this.mustGetOneByType(name, "string"); | ||
mustGetString(name) { | ||
return this.mustGetByType(name, "string"); | ||
} | ||
mustGetOneNumber(name) { | ||
return this.mustGetOneByType(name, "number"); | ||
mustGetNumber(name) { | ||
return this.mustGetByType(name, "number"); | ||
} | ||
mustGetOneBoolean(name) { | ||
return this.mustGetOneByType(name, "boolean"); | ||
mustGetBoolean(name) { | ||
return this.mustGetByType(name, "boolean"); | ||
} | ||
mustGetOneByType(name, type) { | ||
const value = this.getOne(name); | ||
mustGetByType(name, type) { | ||
const value = this.get(name); | ||
if (value === undefined) { | ||
@@ -57,0 +54,0 @@ throw new Error('Property "' + name + '" is missing'); |
{ | ||
"name": "@workadventure/scripting-api-extra", | ||
"version": "1.0.0-alpha.3", | ||
"version": "1.0.0-alpha.4", | ||
"description": "A set of utility functions / features to improve WorkAdventure maps", | ||
@@ -57,2 +57,3 @@ "main": "dist/index.js", | ||
"@tsconfig/svelte": "^1.0.10", | ||
"@types/copy-webpack-plugin": "^8.0.1", | ||
"@types/jest": "^26.0.22", | ||
@@ -59,0 +60,0 @@ "@types/mini-css-extract-plugin": "^1.4.3", |
@@ -127,2 +127,4 @@ # WorkAdventure Scripting API Extra features | ||
Note: for both `openLayer` and `closeLayer`, you can input several layer names separated by a new line character. | ||
Whenever the value of the variable switches from true to false (or the opposite), the door will open or close. | ||
@@ -129,0 +131,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
219
0.92%808857
-0.08%42
2.44%975
-0.51%