From 0c15fdab70d433b6f5338176c3359e7a6ff0ff57 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Fri, 8 Sep 2017 21:15:03 +0200 Subject: Implement unit count limit per machine --- src/components/map/MapConstants.js | 4 ++++ src/sagas/topology.js | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/map/MapConstants.js b/src/components/map/MapConstants.js index f6f47564..d776901e 100644 --- a/src/components/map/MapConstants.js +++ b/src/components/map/MapConstants.js @@ -15,3 +15,7 @@ export const RACK_FILL_ICON_WIDTH = OBJECT_SIZE_IN_PIXELS / 3; export const RACK_FILL_ICON_OPACITY = 0.8; export const MAP_MOVE_PIXELS_PER_EVENT = 20; + +export const MAX_NUM_UNITS_PER_MACHINE = 4; +export const DEFAULT_RACK_SLOT_CAPACITY = 42; +export const DEFAULT_RACK_POWER_CAPACITY = 10000; diff --git a/src/sagas/topology.js b/src/sagas/topology.js index d674c695..9c5087cc 100644 --- a/src/sagas/topology.js +++ b/src/sagas/topology.js @@ -21,6 +21,11 @@ import { updateMachineInRackOnTile, updateRackOnTile } from "../api/routes/tiles"; +import { + DEFAULT_RACK_POWER_CAPACITY, + DEFAULT_RACK_SLOT_CAPACITY, + MAX_NUM_UNITS_PER_MACHINE +} from "../components/map/MapConstants"; import { fetchAndStoreAllCPUs, fetchAndStoreAllGPUs, @@ -236,8 +241,8 @@ export function* onAddRackToTile(action) { const rack = yield call(addRackToTile, action.tileId, { id: -1, name: "Rack", - capacity: 42, - powerCapacityW: 100 + capacity: DEFAULT_RACK_SLOT_CAPACITY, + powerCapacityW: DEFAULT_RACK_POWER_CAPACITY }); rack.machineIds = new Array(rack.capacity).fill(null); yield put(addToStore("rack", rack)); @@ -286,6 +291,11 @@ export function* onAddUnit(action) { const position = yield select(state => state.interactionLevel.position); const machine = yield select(state => state.objects.machine[state.objects.rack[ state.objects.tile[tileId].objectId].machineIds[position - 1]]); + + if (machine[action.unitType + "Ids"].length >= MAX_NUM_UNITS_PER_MACHINE) { + return; + } + const updatedMachine = Object.assign({}, machine, {[action.unitType + "Ids"]: [...machine[action.unitType + "Ids"], action.id]}); -- cgit v1.2.3