diff options
Diffstat (limited to 'frontend/src/sagas')
| -rw-r--r-- | frontend/src/sagas/objects.js | 37 | ||||
| -rw-r--r-- | frontend/src/sagas/prefabs.js | 3 |
2 files changed, 31 insertions, 9 deletions
diff --git a/frontend/src/sagas/objects.js b/frontend/src/sagas/objects.js index a561e4b4..a10fdcbe 100644 --- a/frontend/src/sagas/objects.js +++ b/frontend/src/sagas/objects.js @@ -146,30 +146,51 @@ export const updateTopologyOnServer = function* (id) { yield call(updateTopology, topology) } +export const getAllRooms = function* (roomIds, keepIds) { + const roomStore = yield select(OBJECT_SELECTORS['room']) + let rooms = [] + + for(let i in roomIds){ + let tiles = yield call(getAllRoomTiles, roomStore[i].tileIds, keepIds) + rooms.push({ + _id: keepIds ? i : undefined, + name: roomStore[i].name, + tiles: tiles, + } + ) + } + return rooms +} + export const getTopologyAsObject = function* (id, keepIds) { const topologyStore = yield select(OBJECT_SELECTORS['topology']) - const roomStore = yield select(OBJECT_SELECTORS['room']) + const rooms = yield call(getAllRooms, topologyStore[id].roomIds, keepIds) return { _id: keepIds ? id : undefined, name: topologyStore[id].name, - rooms: topologyStore[id].roomIds.map((roomId) => ({ - _id: keepIds ? roomId : undefined, - name: roomStore[roomId].name, - tiles: roomStore[roomId].tileIds.map((tileId) => (call(getTileById, tileId, keepIds))), - })), + rooms: rooms, + } +} + +export const getAllRoomTiles = function* (room, keepIds) { + let tiles = [] + + for(let i in room.tileIds){ + tiles.push(yield call(getTileById, i, keepIds)) } + return tiles } export const getTileById = function* (id, keepIds) { const tileStore = yield select(OBJECT_SELECTORS['tile']) return { _id: keepIds ? id : undefined, - positionX: tileStore[id].positionX, + positionX: tileStore[id].positionX, positionY: tileStore[id].positionY, rack: !tileStore[id].rackId ? undefined - : call(getRackById, tileStore[id].rackId, keepIds), + : yield call(getRackById, tileStore[id].rackId, keepIds), } } diff --git a/frontend/src/sagas/prefabs.js b/frontend/src/sagas/prefabs.js index 1756095c..80ba2f80 100644 --- a/frontend/src/sagas/prefabs.js +++ b/frontend/src/sagas/prefabs.js @@ -5,7 +5,8 @@ import {getTopologyAsObject} from "./objects"; export function* onAddPrefab(action) { try { - //console.log("DEBUG: " + state.objects.tile[state.interactionLevel.tileId].rack._id) + const state = yield select((state) => state) + console.log("DEBUG: " + state.objects.tile[state.interactionLevel.tileId].rack._id) const currentRackId = yield select((state) => state.objects.tile[state.interactionLevel.tileId].rack._id) const currentRackJson = yield call(getTopologyAsObject, currentRackId) //TODO: yield call the function in saga to export the specific part of the topology |
