summaryrefslogtreecommitdiff
path: root/src/actions/topology/building.js
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-07 22:15:17 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:58 +0200
commit1b5d2658f9ec06308b2a5ed062f6f5b4798ed733 (patch)
tree84d35684a50f897fc4c5f460bed595adf22c9e66 /src/actions/topology/building.js
parent8218c3d3c21bfa7c4f3ee4872722b9b1261576fb (diff)
Reorganize actions and state tree
Diffstat (limited to 'src/actions/topology/building.js')
-rw-r--r--src/actions/topology/building.js130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/actions/topology/building.js b/src/actions/topology/building.js
new file mode 100644
index 00000000..87abbf5b
--- /dev/null
+++ b/src/actions/topology/building.js
@@ -0,0 +1,130 @@
+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 RESET_CURRENT_DATACENTER = "RESET_CURRENT_DATACENTER";
+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 DELETE_TILE = "DELETE_TILE";
+
+export function fetchLatestDatacenter() {
+ return (dispatch, getState) => {
+ const {currentSimulationId} = getState();
+ dispatch({
+ type: FETCH_LATEST_DATACENTER,
+ currentSimulationId
+ });
+ };
+}
+
+export function fetchLatestDatacenterSucceeded(datacenterId) {
+ return {
+ type: FETCH_LATEST_DATACENTER_SUCCEEDED,
+ datacenterId
+ };
+}
+
+export function resetCurrentDatacenter() {
+ return {
+ type: RESET_CURRENT_DATACENTER
+ };
+}
+
+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, construction} = getState();
+ if (objects.room[construction.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, construction} = getState();
+ dispatch(removeIdFromStoreObjectListProp("datacenter", currentDatacenterId, "roomIds",
+ construction.currentRoomInConstruction));
+ dispatch({
+ type: CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED
+ });
+ };
+}
+
+export function toggleTileAtLocation(positionX, positionY) {
+ return (dispatch, getState) => {
+ const {objects, construction} = getState();
+
+ const tileIds = objects.room[construction.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 {construction} = getState();
+ dispatch(addIdToStoreObjectListProp("room", construction.currentRoomInConstruction, "tileIds", tileId));
+ };
+}
+
+export function deleteTile(tileId) {
+ return {
+ type: DELETE_TILE,
+ tileId
+ }
+}
+
+export function deleteTileSucceeded(tileId) {
+ return (dispatch, getState) => {
+ const {construction} = getState();
+ dispatch(removeIdFromStoreObjectListProp("room", construction.currentRoomInConstruction, "tileIds", tileId));
+ };
+}