-
Notifications
You must be signed in to change notification settings - Fork 0
/
reducer.js
executable file
·158 lines (153 loc) · 5.46 KB
/
reducer.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import concatenateReducers from 'redux-concatenate-reducers'
import { handleAction, handleActions } from 'redux-actions'
import {
game_modes,
pages,
roles,
states,
} from '../util/index.js'
import {
changeChartRound,
fallChartButton,
submitAlloTemp,
finishAllocating,
finishJudging,
responseOK,
redoAllcating,
responseNG,
fallSnackBarFlags,
fallSnackBarFlags2,
fallSnackBarFlags3,
} from './actions.js'
const initialState = {
point: 0,
role: "visitor",
pair_id: null,
chart_round: 1,
chart_button: false,
now_round: 1,
redo_count: 0,
allo_temp: 100 * Math.round(10 * Math.random()),
change_count: 0,
ultimatum_results: {},
dictator_results: {},
state: "allocating",
responsedOK: false,
responseOK: false,
responsedNG: false,
responseNG: false,
changeRole: false,
redo_flag: false,
participants_length: 0,
}
const reducer = concatenateReducers([
handleActions({
'update contents': (_, { payload }) => payload,
'sync game progress': (_, { payload }) => ({
game_progress: payload
}),
'reseted': () => ({
page: "waiting",
game_mode: "ultimatum",
game_round: 1,
game_redo: 0,
role: "visitor",
point: 0,
pair_id: null,
}),
'sync participants length': (_, { payload }) => ({
participants_length: payload
}),
'show results': (_ , { payload: {ultimatum_results, dictator_results} }) => ({
ultimatum_results: ultimatum_results,
dictator_results: dictator_results
}),
'join': ({ participants }, { payload: { id, participant } }) => ({
participants: Object.assign({}, participants, {
[id]: participant
})
}),
'matched': (_, { payload: {
allo_temp, members, now_round, pair_id,
point, results, role, state
} }) => ({
allo_temp, members, now_round, pair_id,
point, results, role, state
}),
[submitAlloTemp]: ({ change_count }, { payload }) => ({ allo_temp: payload, change_count: change_count + 1}),
'change allo_temp': ({ change_count }, { payload })=> ({ allo_temp: payload, change_count: change_count + 1}),
[finishAllocating]: (_, { payload }) => ({ state: "judging", allo_temp: payload}),
'finish allocating': (_, { payload }) => ({ state: "judging", allo_temp: payload}),
[responseOK]: ( {now_round, game_mode,
game_round, state, point,
role, allo_temp }, { payload: { value: value } }) => ({
state: (now_round < game_round)? "allocating" : "finished",
now_round: (now_round < game_round)? now_round+1 : now_round,
role: (role == "responder")? ((game_mode == "ultimatum")? "proposer": "dictator") : "responder",
point: point + 1000 - value,
allo_result: allo_temp,
allo_temp: 100 * Math.round(10* Math.random()),
responseOK: true,
change_count: 0,
}),
'response ok': ({now_round, game_mode,
game_round, state, point,
role, allo_temp}, { payload }) => ({
state: (now_round < game_round)? "allocating" : "finished",
now_round: (now_round < game_round)? now_round+1 : now_round,
role: (role == "responder")? ((game_mode == "ultimatum")? "proposer": "dictator") : "responder",
point: point + payload,
allo_result: allo_temp,
allo_temp: 100 * Math.round(10* Math.random()),
responsedOK: true,
change_count: 0,
}),
[responseNG]: ({state, now_round, game_round, role, game_mode, game_redo, redo_count}, {}) => ({
state: (now_round < game_round)? "allocating" : "finished",
now_round: (now_round < game_round)? now_round+1 : now_round,
role: (role == "responder")? ((game_mode == "ultimatum")? "proposer": "dictator") : "responder",
allo_temp: 100 * Math.round(10* Math.random()),
responseNG: true,
change_count: 0,
redo_count: 0,
}),
[redoAllcating]: ({redo_count}, {}) => ({
state: "allocating",
redo_count: redo_count + 1,
redo_flag: true,
}),
'redo allocating': ({redo_count}, {}) => ({
state: "allocating",
redo_count: redo_count + 1,
redo_flag: true,
}),
'response ng': ({state, now_round, game_round, role, game_mode}, {}) => ({
redo_count: 0,
state: (now_round < game_round)? "allocating" : "finished",
now_round: (now_round < game_round)? now_round+1 : now_round,
role: (role == "responder")? ((game_mode == "ultimatum")? "proposer": "dictator") : "responder",
allo_temp: 100 * Math.round(10* Math.random()),
responsedNG: true,
change_count: 0,
}),
[fallSnackBarFlags]: ({ state }) => ({
responsedOK: false,
responseOK: false,
responsedNG: false,
responseNG: false,
changeRole: state == "allocating",
}),
[fallSnackBarFlags2]: ({}) => ({changeRole: false}),
[fallSnackBarFlags3]: ({}) => ({redo_flag: false}),
[changeChartRound]: (_, { payload }) => ({ chart_round: payload, chart_button: true }),
[fallChartButton]: () => ({ chart_button: false}),
'change page': (_, { payload }) => ({ page: payload }),
'change inf_redo': (_, { payload }) => ({ inf_redo: payload }),
'change game_redo': (_, { payload }) => ({ game_redo: payload }),
'change game_round': (_, { payload }) => ({ game_round: payload }),
'change game_redo': (_, { payload }) => ({ game_redo: payload }),
'change game_mode': (_, { payload }) => ({ game_mode: payload }),
}, initialState),
handleAction('update contents', () => ({ loading: false }), { loading: true })
])
export default reducer