Skip to content

Commit f634321

Browse files
Custom Controls
1 parent b934376 commit f634321

File tree

7 files changed

+247
-85
lines changed

7 files changed

+247
-85
lines changed

assets/controls.json

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
{
2+
"categories": [
3+
{
4+
"name": "notes",
5+
"options": [
6+
{
7+
"variable": "left",
8+
"initialValue": [
9+
"A",
10+
"LEFT"
11+
]
12+
},
13+
{
14+
"variable": "down",
15+
"initialValue": [
16+
"S",
17+
"DOWN"
18+
]
19+
},
20+
{
21+
"variable": "up",
22+
"initialValue": [
23+
"W",
24+
"UP"
25+
]
26+
},
27+
{
28+
"variable": "right",
29+
"initialValue": [
30+
"D",
31+
"RIGHT"
32+
]
33+
}
34+
]
35+
},
36+
{
37+
"name": "ui",
38+
"options": [
39+
{
40+
"variable": "left",
41+
"initialValue": [
42+
"A",
43+
"LEFT"
44+
]
45+
},
46+
{
47+
"variable": "down",
48+
"initialValue": [
49+
"S",
50+
"DOWN"
51+
]
52+
},
53+
{
54+
"variable": "up",
55+
"initialValue": [
56+
"W",
57+
"UP"
58+
]
59+
},
60+
{
61+
"variable": "right",
62+
"initialValue": [
63+
"D",
64+
"RIGHT"
65+
]
66+
},
67+
{
68+
"variable": "accept",
69+
"initialValue": [
70+
"ENTER",
71+
"SPACE"
72+
]
73+
},
74+
{
75+
"variable": "back",
76+
"initialValue": [
77+
"ESCAPE",
78+
null
79+
]
80+
},
81+
{
82+
"variable": "pause",
83+
"initialValue": [
84+
"ENTER",
85+
"ESCAPE"
86+
]
87+
},
88+
{
89+
"variable": "reset",
90+
"initialValue": [
91+
"R",
92+
"F5"
93+
]
94+
}
95+
]
96+
},
97+
{
98+
"name": "engine",
99+
"options": [
100+
{
101+
"variable": "character",
102+
"initialValue": [
103+
"EIGHT",
104+
null
105+
]
106+
},
107+
{
108+
"variable": "chart",
109+
"initialValue": [
110+
"SEVEN",
111+
null
112+
]
113+
},
114+
{
115+
"variable": "fps_counter",
116+
"initialValue": [
117+
"F3",
118+
null
119+
]
120+
},
121+
{
122+
"variable": "master_menu",
123+
"initialValue": [
124+
"SEVEN",
125+
null
126+
]
127+
},
128+
{
129+
"variable": "reset_game",
130+
"initialValue": [
131+
"N",
132+
null
133+
]
134+
},
135+
{
136+
"variable": "switch_mod",
137+
"initialValue": [
138+
"M",
139+
null
140+
]
141+
}
142+
]
143+
}
144+
]
145+
}

assets/scripts/classes/options/ControlsOption.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ControlsOption extends ScriptSpriteGroup
5454
this.variable = variable;
5555
this.groupIndex = groupIndex;
5656

57-
keys = Reflect.field(Reflect.field(ClientPrefs.controls, group), variable);
57+
keys = CoolUtil.getControl(group, variable);
5858

5959
bg = new FlxSprite().makeGraphic(FlxG.width * 0.8, 50, FlxColor.fromRGB(35, 35, 50));
6060
add(bg);

assets/scripts/substates/ControlsSubState.hx

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,16 @@ import funkin.visuals.objects.Alphabet;
44

55
using StringTools;
66

7-
inline function multiProp(obj:Dynamic, path:String)
8-
{
9-
for (field in path.split('.'))
10-
if (field != '')
11-
obj = Reflect.field(obj, field);
12-
13-
return obj;
14-
}
15-
16-
17-
function priorSort(priorities:Array<String>, ?field:String)
18-
{
19-
return function(a, b)
20-
{
21-
var an = multiProp(a, field ?? '');
22-
var bn = multiProp(b, field ?? '');
23-
24-
var ai = priorities.indexOf(an);
25-
var bi = priorities.indexOf(bn);
26-
27-
if (ai == -1 && bi == -1)
28-
return Reflect.compare(an, bn);
29-
30-
if (ai == -1)
31-
return 1;
32-
33-
if (bi == -1)
34-
return -1;
35-
36-
return Reflect.compare(ai, bi);
37-
}
38-
}
39-
407
var options:Array<Dynamic> = [
41-
for (group in Reflect.fields(ClientPrefs.controls))
8+
for (group in Paths.json('controls').categories)
429
{
4310
{
44-
name: group,
45-
options: [
46-
for (id in Reflect.fields(Reflect.field(ClientPrefs.controls, group)))
47-
id
48-
]
11+
name: group.name,
12+
options: [for (option in group.options) option.variable]
4913
}
5014
}
5115
];
5216

53-
options.sort(priorSort(['notes', 'ui'], 'name'));
54-
55-
for (group in options)
56-
group.options.sort(priorSort(['left', 'down', 'up', 'right']));
57-
5817
FlxG.camera.bgColor = FlxColor.WHITE;
5918

6019
var subCamera:FlxCamera = new ALECamera();

source/core/config/ClientPrefs.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class ClientPrefs
3434
}
3535
};
3636

37+
public static var customControls:Dynamic = {};
38+
3739
public static var data:SaveData = {};
3840

3941
public static var custom:Dynamic = {};

0 commit comments

Comments
 (0)