@@ -64,6 +64,21 @@ static int computeStrokeWidth(float widthInPercent, float width, float height) {
6464 return (int ) ((maxSize / 2 ) * (widthInPercent / 100 ));
6565}
6666
67+ // Normalize the layout to v8 from v6/7
68+ void convertV6_7Layout (NSMutableDictionary * dict) {
69+ for (NSMutableDictionary *data in (NSMutableArray *)dict[@" mJoystickDataList" ]) {
70+ if ([data[@" height" ] floatValue ] > [data[@" width" ] floatValue ]) {
71+ // Make the size square, adjust the dynamic position related to height
72+ CGFloat ratio = [data[@" height" ] floatValue ] / [data[@" width" ] floatValue ];
73+ data[@" dynamicX" ] = [data[@" dynamicX" ] stringByReplacingOccurrencesOfString: @" ${height}" withString: [NSString stringWithFormat: @" (%f * ${height})" , ratio]];
74+ data[@" dynamicY" ] = [data[@" dynamicY" ] stringByReplacingOccurrencesOfString: @" ${height}" withString: [NSString stringWithFormat: @" (%f * ${height})" , ratio]];
75+ data[@" height" ] = data[@" width" ];
76+ }
77+ }
78+
79+ dict[@" version" ] = @(8 );
80+ }
81+
6782void convertV3_4Layout (NSMutableDictionary * dict) {
6883 // Convert the layout stroke width to the V5 form
6984 for (NSMutableDictionary *button in (NSMutableArray *)dict[@" mControlDataList" ]) {
@@ -185,6 +200,8 @@ BOOL convertLayoutIfNecessary(NSMutableDictionary* dict) {
185200 break ;
186201 case 6 :
187202 case 7 :
203+ convertV6_7Layout (dict);
204+ case 8 :
188205 break ;
189206 default :
190207 showDialog (localize (@" custom_controls.control_menu.save.error.json" , nil ), [NSString stringWithFormat: localize (@" custom_controls.error.incompatible" , nil ), version]);
@@ -199,6 +216,13 @@ void generateAndSaveDefaultControl() {
199216 return ;
200217 }
201218
219+ // New layout is expected to be placed in the app bundle. If not found, use fallback layout
220+ NSString *builtinPath = [NSBundle .mainBundle pathForResource: @" default" ofType: @" json" ];
221+ if (builtinPath) {
222+ [NSFileManager .defaultManager copyItemAtPath: builtinPath toPath: defaultPath error: nil ];
223+ return ;
224+ }
225+
202226 // Generate a v2.7 control
203227 NSMutableDictionary *dict = [[NSMutableDictionary alloc ] init ];
204228 dict[@" version" ] = @(5 );
0 commit comments