1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import {goDownOneInteractionLevel} from "../interaction-level";
import {addPropToStoreObject} from "../objects";
export const DELETE_MACHINE = "DELETE_MACHINE";
export const ADD_UNIT = "ADD_UNIT";
export const DELETE_UNIT = "DELETE_UNIT";
export function deleteMachine() {
return {
type: DELETE_MACHINE
};
}
export function deleteMachineSucceeded() {
return (dispatch, getState) => {
const {interactionLevel, objects} = getState();
const rack = objects.rack[objects.tile[interactionLevel.tileId].objectId];
const machineIds = [...rack.machineIds];
machineIds[interactionLevel.position - 1] = null;
dispatch(goDownOneInteractionLevel());
dispatch(addPropToStoreObject("rack", rack.id, {machineIds}));
};
}
export function addUnit(unitType, id) {
return {
type: ADD_UNIT,
unitType,
id
};
}
export function addUnitSucceeded(unitType, id) {
return (dispatch, getState) => {
const {objects, interactionLevel} = getState();
const machine = objects.machine[objects.rack[objects.tile[interactionLevel.tileId].objectId]
.machineIds[interactionLevel.position - 1]];
const units = [...machine[unitType + "Ids"], id];
dispatch(addPropToStoreObject("machine", machine.id, {[unitType + "Ids"]: units}));
};
}
export function deleteUnit(unitType, index) {
return {
type: DELETE_UNIT,
unitType,
index
};
}
export function deleteUnitSucceeded(unitType, index) {
return (dispatch, getState) => {
const {objects, interactionLevel} = getState();
const machine = objects.machine[objects.rack[objects.tile[interactionLevel.tileId].objectId]
.machineIds[interactionLevel.position - 1]];
const unitIds = machine[unitType + "Ids"].slice();
unitIds.splice(index, 1);
dispatch(addPropToStoreObject("machine", machine.id, {[unitType + "Ids"]: unitIds}));
};
}
|