diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-08 21:15:03 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:59 +0200 |
| commit | 0c15fdab70d433b6f5338176c3359e7a6ff0ff57 (patch) | |
| tree | b98a15e9ac65586a606bb31e3bce2dc131d60976 /src | |
| parent | 8db9161553ece681a0c9a6f50b710ce6cbd3c8dc (diff) | |
Implement unit count limit per machine
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/map/MapConstants.js | 4 | ||||
| -rw-r--r-- | 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 @@ -22,6 +22,11 @@ import { 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, fetchAndStoreAllMemories, @@ -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]}); |
