Allowing variables nested in group layers
Up until this commit, variables nested in object layers inside group layers where not found by the front nor the back. This PR changes analysis so that variables can be detected.
This commit is contained in:
parent
1d5ad96646
commit
68a4772627
@ -40,7 +40,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/thecodingmachine/workadventure#readme",
|
"homepage": "https://github.com/thecodingmachine/workadventure#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@workadventure/tiled-map-type-guard": "^1.0.0",
|
"@workadventure/tiled-map-type-guard": "^1.0.2",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"busboy": "^0.3.1",
|
"busboy": "^0.3.1",
|
||||||
"circular-json": "^0.5.9",
|
"circular-json": "^0.5.9",
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
/**
|
/**
|
||||||
* Handles variables shared between the scripting API and the server.
|
* Handles variables shared between the scripting API and the server.
|
||||||
*/
|
*/
|
||||||
import { ITiledMap, ITiledMapObject, ITiledMapObjectLayer } from "@workadventure/tiled-map-type-guard/dist";
|
import {
|
||||||
|
ITiledMap,
|
||||||
|
ITiledMapLayer,
|
||||||
|
ITiledMapObject,
|
||||||
|
ITiledMapObjectLayer,
|
||||||
|
} from "@workadventure/tiled-map-type-guard/dist";
|
||||||
import { User } from "_Model/User";
|
import { User } from "_Model/User";
|
||||||
import { variablesRepository } from "./Repository/VariablesRepository";
|
import { variablesRepository } from "./Repository/VariablesRepository";
|
||||||
import { redisClient } from "./RedisClient";
|
import { redisClient } from "./RedisClient";
|
||||||
@ -83,8 +88,14 @@ export class VariablesManager {
|
|||||||
private static findVariablesInMap(map: ITiledMap): Map<string, Variable> {
|
private static findVariablesInMap(map: ITiledMap): Map<string, Variable> {
|
||||||
const objects = new Map<string, Variable>();
|
const objects = new Map<string, Variable>();
|
||||||
for (const layer of map.layers) {
|
for (const layer of map.layers) {
|
||||||
|
this.recursiveFindVariablesInLayer(layer, objects);
|
||||||
|
}
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static recursiveFindVariablesInLayer(layer: ITiledMapLayer, objects: Map<string, Variable>): void {
|
||||||
if (layer.type === "objectgroup") {
|
if (layer.type === "objectgroup") {
|
||||||
for (const object of (layer as ITiledMapObjectLayer).objects) {
|
for (const object of layer.objects) {
|
||||||
if (object.type === "variable") {
|
if (object.type === "variable") {
|
||||||
if (object.template) {
|
if (object.template) {
|
||||||
console.warn(
|
console.warn(
|
||||||
@ -97,9 +108,11 @@ export class VariablesManager {
|
|||||||
objects.set(object.name, this.iTiledObjectToVariable(object));
|
objects.set(object.name, this.iTiledObjectToVariable(object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (layer.type === "group") {
|
||||||
|
for (const innerLayer of layer.layers) {
|
||||||
|
this.recursiveFindVariablesInLayer(innerLayer, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return objects;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static iTiledObjectToVariable(object: ITiledMapObject): Variable {
|
private static iTiledObjectToVariable(object: ITiledMapObject): Variable {
|
||||||
|
@ -194,10 +194,10 @@
|
|||||||
semver "^7.3.2"
|
semver "^7.3.2"
|
||||||
tsutils "^3.17.1"
|
tsutils "^3.17.1"
|
||||||
|
|
||||||
"@workadventure/tiled-map-type-guard@^1.0.0":
|
"@workadventure/tiled-map-type-guard@^1.0.2":
|
||||||
version "1.0.0"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/@workadventure/tiled-map-type-guard/-/tiled-map-type-guard-1.0.0.tgz#02524602ee8b2688429a1f56df1d04da3fc171ba"
|
resolved "https://registry.yarnpkg.com/@workadventure/tiled-map-type-guard/-/tiled-map-type-guard-1.0.2.tgz#4171550f6cd71be19791faef48360d65d698bcb0"
|
||||||
integrity sha512-Mc0SE128otQnYlScQWVaQVyu1+CkailU/FTBh09UTrVnBAhyMO+jIn9vT9+Dv244xq+uzgQDpXmiVdjgrYFQ+A==
|
integrity sha512-RCtygGV5y9cb7QoyGMINBE9arM5pyXjkxvXgA5uXEv4GDbXKorhFim/rHgwbVR+eFnVF3rDgWbRnk3DIaHt+lQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
generic-type-guard "^3.4.1"
|
generic-type-guard "^3.4.1"
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import type { RoomConnection } from "../../Connexion/RoomConnection";
|
import type { RoomConnection } from "../../Connexion/RoomConnection";
|
||||||
import { iframeListener } from "../../Api/IframeListener";
|
import { iframeListener } from "../../Api/IframeListener";
|
||||||
import type { Subscription } from "rxjs";
|
|
||||||
import type { GameMap } from "./GameMap";
|
import type { GameMap } from "./GameMap";
|
||||||
import type { ITile, ITiledMapObject } from "../Map/ITiledMap";
|
import type {ITiledMapLayer, ITiledMapObject, ITiledMapObjectLayer} from "../Map/ITiledMap";
|
||||||
import type { Var } from "svelte/types/compiler/interfaces";
|
|
||||||
import { init } from "svelte/internal";
|
|
||||||
|
|
||||||
interface Variable {
|
interface Variable {
|
||||||
defaultValue: unknown;
|
defaultValue: unknown;
|
||||||
@ -100,6 +97,12 @@ export class SharedVariablesManager {
|
|||||||
private static findVariablesInMap(gameMap: GameMap): Map<string, Variable> {
|
private static findVariablesInMap(gameMap: GameMap): Map<string, Variable> {
|
||||||
const objects = new Map<string, Variable>();
|
const objects = new Map<string, Variable>();
|
||||||
for (const layer of gameMap.getMap().layers) {
|
for (const layer of gameMap.getMap().layers) {
|
||||||
|
this.recursiveFindVariablesInLayer(layer, objects);
|
||||||
|
}
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static recursiveFindVariablesInLayer(layer: ITiledMapLayer, objects: Map<string, Variable>): void {
|
||||||
if (layer.type === "objectgroup") {
|
if (layer.type === "objectgroup") {
|
||||||
for (const object of layer.objects) {
|
for (const object of layer.objects) {
|
||||||
if (object.type === "variable") {
|
if (object.type === "variable") {
|
||||||
@ -107,15 +110,18 @@ export class SharedVariablesManager {
|
|||||||
console.warn(
|
console.warn(
|
||||||
'Warning, a variable object is using a Tiled "template". WorkAdventure does not support objects generated from Tiled templates.'
|
'Warning, a variable object is using a Tiled "template". WorkAdventure does not support objects generated from Tiled templates.'
|
||||||
);
|
);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We store a copy of the object (to make it immutable)
|
// We store a copy of the object (to make it immutable)
|
||||||
objects.set(object.name, this.iTiledObjectToVariable(object));
|
objects.set(object.name, this.iTiledObjectToVariable(object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (layer.type === "group") {
|
||||||
|
for (const innerLayer of layer.layers) {
|
||||||
|
this.recursiveFindVariablesInLayer(innerLayer, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return objects;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static iTiledObjectToVariable(object: ITiledMapObject): Variable {
|
private static iTiledObjectToVariable(object: ITiledMapObject): Variable {
|
||||||
|
Loading…
Reference in New Issue
Block a user