diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-08-31 17:59:51 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:50 +0200 |
| commit | 3f736cd3db63f106eac02f220477b4a0f3b0eceb (patch) | |
| tree | 80afa73f8c4d281b2fccba8ad2baa7c10f7e7e84 /src/actions/topology.js | |
| parent | b17f1d8cb4815f57a4b7043cc91b867ec3cbc867 (diff) | |
Implement room creation
Diffstat (limited to 'src/actions/topology.js')
| -rw-r--r-- | src/actions/topology.js | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/actions/topology.js b/src/actions/topology.js index de742bb1..76b1ef27 100644 --- a/src/actions/topology.js +++ b/src/actions/topology.js @@ -1,7 +1,18 @@ +import {addIdToStoreObjectListProp, removeIdFromStoreObjectListProp} from "./objects"; + export const FETCH_TOPOLOGY_OF_DATACENTER = "FETCH_TOPOLOGY_OF_DATACENTER"; export const FETCH_TOPOLOGY_OF_DATACENTER_SUCCEEDED = "FETCH_TOPOLOGY_OF_DATACENTER_SUCCEEDED"; export const FETCH_LATEST_DATACENTER = "FETCH_LATEST_DATACENTER"; export const FETCH_LATEST_DATACENTER_SUCCEEDED = "FETCH_LATEST_DATACENTER_SUCCEEDED"; +export const START_NEW_ROOM_CONSTRUCTION = "START_NEW_ROOM_CONSTRUCTION"; +export const START_NEW_ROOM_CONSTRUCTION_SUCCEEDED = "START_NEW_ROOM_CONSTRUCTION_SUCCEEDED"; +export const FINISH_NEW_ROOM_CONSTRUCTION = "FINISH_NEW_ROOM_CONSTRUCTION"; +export const CANCEL_NEW_ROOM_CONSTRUCTION = "CANCEL_NEW_ROOM_CONSTRUCTION"; +export const CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED = "CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED"; +export const ADD_TILE = "ADD_TILE"; +export const ADD_TILE_SUCCEEDED = "ADD_TILE_SUCCEEDED"; +export const DELETE_TILE = "DELETE_TILE"; +export const DELETE_TILE_SUCCEEDED = "DELETE_TILE_SUCCEEDED"; export function fetchLatestDatacenter() { return (dispatch, getState) => { @@ -19,3 +30,104 @@ export function fetchLatestDatacenterSucceeded(datacenterId) { datacenterId }; } + +export function startNewRoomConstruction() { + return { + type: START_NEW_ROOM_CONSTRUCTION + }; +} + +export function startNewRoomConstructionSucceeded(roomId) { + return (dispatch, getState) => { + const {currentDatacenterId} = getState(); + dispatch(addIdToStoreObjectListProp("datacenter", currentDatacenterId, "roomIds", roomId)); + dispatch({ + type: START_NEW_ROOM_CONSTRUCTION_SUCCEEDED, + roomId + }); + }; +} + +export function finishNewRoomConstruction() { + return (dispatch, getState) => { + const {objects, currentRoomInConstruction} = getState(); + if (objects.room[currentRoomInConstruction].tileIds.length === 0) { + dispatch(cancelNewRoomConstruction()); + return; + } + + dispatch({ + type: FINISH_NEW_ROOM_CONSTRUCTION + }); + }; +} + +export function cancelNewRoomConstruction() { + return { + type: CANCEL_NEW_ROOM_CONSTRUCTION + }; +} + +export function cancelNewRoomConstructionSucceeded() { + return (dispatch, getState) => { + const {currentDatacenterId, currentRoomInConstruction} = getState(); + dispatch(removeIdFromStoreObjectListProp("datacenter", currentDatacenterId, "roomIds", + currentRoomInConstruction)); + dispatch({ + type: CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED + }); + }; +} + +export function toggleTileAtLocation(positionX, positionY) { + return (dispatch, getState) => { + const {objects, currentRoomInConstruction} = getState(); + + const tileIds = objects.room[currentRoomInConstruction].tileIds; + for (let index in tileIds) { + if (objects.tile[tileIds[index]].positionX === positionX + && objects.tile[tileIds[index]].positionY === positionY) { + dispatch(deleteTile(tileIds[index])); + return; + } + } + dispatch(addTile(positionX, positionY)); + }; +} + +export function addTile(positionX, positionY) { + return { + type: ADD_TILE, + positionX, + positionY + }; +} + +export function addTileSucceeded(tileId) { + return (dispatch, getState) => { + const {currentRoomInConstruction} = getState(); + dispatch(addIdToStoreObjectListProp("room", currentRoomInConstruction, "tileIds", tileId)); + dispatch({ + type: ADD_TILE_SUCCEEDED, + tileId + }); + }; +} + +export function deleteTile(tileId) { + return { + type: DELETE_TILE, + tileId + } +} + +export function deleteTileSucceeded(tileId) { + return (dispatch, getState) => { + const {currentRoomInConstruction} = getState(); + dispatch(removeIdFromStoreObjectListProp("room", currentRoomInConstruction, "tileIds", tileId)); + dispatch({ + type: DELETE_TILE_SUCCEEDED, + tileId + }); + }; +} |
