summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-07-28 20:40:48 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:48:45 +0200
commit488d9ae5df13dcea208fc5cb3d609e0a9472bf53 (patch)
tree6276481e3fa6953985cc21cc956d50ad7ea06343
parent40e15a1a21edf5229c6ea8ec6655c56bfc1cc25b (diff)
More stuff for review
-rw-r--r--frontend/src/sagas/objects.js37
-rw-r--r--frontend/src/sagas/prefabs.js3
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