-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgamepadSlice.js
More file actions
64 lines (61 loc) · 2.02 KB
/
gamepadSlice.js
File metadata and controls
64 lines (61 loc) · 2.02 KB
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
import { createSlice } from "@reduxjs/toolkit";
import { RE_INITIALIZE_STORE } from "../../constants/actions";
export const gamepadSlice = createSlice({
name: "gamepadController",
initialState: {
crossIsPressed: {previous: false, current: false},
squareIsPressed: {previous: false, current: false},
circleIsPressed: {previous: false, current: false},
r1IsPressed: {previous: false, current: false},
l1IsPressed: {previous: false, current: false},
upIsPressed: {previous: false, current: false},
downIsPressed: {previous: false, current: false},
},
reducers: {
setCrossIsPressed: (state, action) => {
state.crossIsPressed = action.payload;
},
setSquareIsPressed: (state, action) => {
state.squareIsPressed = action.payload;
},
setCircleIsPressed: (state, action) => {
state.circleIsPressed = action.payload;
},
setR1IsPressed: (state, action) => {
state.r1IsPressed = action.payload;
},
setL1IsPressed: (state, action) => {
state.l1IsPressed = action.payload;
},
setUpIsPressed: (state, action) => {
state.upIsPressed = action.payload;
},
setDownIsPressed: (state, action) => {
state.downIsPressed = action.payload;
},
},
extraReducers: (builder) => {
builder.addCase(RE_INITIALIZE_STORE, () => {
return {
crossIsPressed: {previous: false, current: false},
squareIsPressed: {previous: false, current: false},
circleIsPressed: {previous: false, current: false},
r1IsPressed: {previous: false, current: false},
l1IsPressed: {previous: false, current: false},
upIsPressed: {previous: false, current: false},
downIsPressed: {previous: false, current: false},
};
});
},
});
// Action creators are generated for each case reducer function
export const {
setCrossIsPressed,
setSquareIsPressed,
setCircleIsPressed,
setR1IsPressed,
setL1IsPressed,
setUpIsPressed,
setDownIsPressed,
} = gamepadSlice.actions;
export default gamepadSlice.reducer;