@logic-pad/core 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2086,6 +2086,7 @@ declare global {
|
|
|
2086
2086
|
parseTile(_str: string): TileData;
|
|
2087
2087
|
stringifyControlLine(line: ControlLine): string;
|
|
2088
2088
|
parseControlLine(_str: string): ControlLine;
|
|
2089
|
+
stringifyConfig(instruction: Instruction, config: AnyConfig): string;
|
|
2089
2090
|
parseConfig(
|
|
2090
2091
|
_configs: readonly AnyConfig[],
|
|
2091
2092
|
_entry: string
|
|
@@ -8,11 +8,13 @@ import { Puzzle, PuzzleData } from '../puzzle.js';
|
|
|
8
8
|
import { ControlLine } from '../rules/musicControlLine.js';
|
|
9
9
|
import GridZones from '../gridZones.js';
|
|
10
10
|
import SerializerV0 from './serializer_v0.js';
|
|
11
|
+
import Instruction from '../instruction.js';
|
|
11
12
|
export default class SerializerChecksum extends SerializerV0 {
|
|
12
13
|
readonly version: number;
|
|
13
14
|
parseTile(_str: string): TileData;
|
|
14
15
|
stringifyControlLine(line: ControlLine): string;
|
|
15
16
|
parseControlLine(_str: string): ControlLine;
|
|
17
|
+
stringifyConfig(instruction: Instruction, config: AnyConfig): string;
|
|
16
18
|
parseConfig(_configs: readonly AnyConfig[], _entry: string): [string, unknown];
|
|
17
19
|
parseRule(_str: string): Rule;
|
|
18
20
|
parseSymbol(_str: string): Symbol;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ConfigType, } from '../config.js';
|
|
2
|
+
import SerializerV0, { orientationChars } from './serializer_v0.js';
|
|
3
|
+
import { DIRECTIONS, ORIENTATIONS, } from '../primitives.js';
|
|
4
|
+
import { escape } from '../dataHelper.js';
|
|
2
5
|
export default class SerializerChecksum extends SerializerV0 {
|
|
3
6
|
constructor() {
|
|
4
7
|
super(...arguments);
|
|
@@ -21,6 +24,93 @@ export default class SerializerChecksum extends SerializerV0 {
|
|
|
21
24
|
parseControlLine(_str) {
|
|
22
25
|
throw new Error('Checksum serializer does not support parsing');
|
|
23
26
|
}
|
|
27
|
+
stringifyConfig(instruction, config) {
|
|
28
|
+
switch (config.type) {
|
|
29
|
+
case ConfigType.Boolean:
|
|
30
|
+
return (config.field +
|
|
31
|
+
'=' +
|
|
32
|
+
(instruction[config.field] ? '1' : '0'));
|
|
33
|
+
case ConfigType.Number:
|
|
34
|
+
case ConfigType.Color:
|
|
35
|
+
case ConfigType.Comparison:
|
|
36
|
+
case ConfigType.Wrapping:
|
|
37
|
+
case ConfigType.Direction:
|
|
38
|
+
case ConfigType.Orientation:
|
|
39
|
+
return (config.field +
|
|
40
|
+
'=' +
|
|
41
|
+
instruction[config.field]
|
|
42
|
+
.toLowerCase()
|
|
43
|
+
.trim());
|
|
44
|
+
case ConfigType.NullableBoolean:
|
|
45
|
+
return (config.field +
|
|
46
|
+
'=' +
|
|
47
|
+
(instruction[config.field] === null
|
|
48
|
+
? ''
|
|
49
|
+
: instruction[config.field]
|
|
50
|
+
? '1'
|
|
51
|
+
: '0'));
|
|
52
|
+
case ConfigType.NullableNumber:
|
|
53
|
+
return (config.field +
|
|
54
|
+
'=' +
|
|
55
|
+
(instruction[config.field] === null
|
|
56
|
+
? ''
|
|
57
|
+
: String(instruction[config.field])));
|
|
58
|
+
case ConfigType.DirectionToggle:
|
|
59
|
+
return (config.field +
|
|
60
|
+
'=' +
|
|
61
|
+
DIRECTIONS.filter(dir => instruction[config.field][dir])
|
|
62
|
+
.map(x => orientationChars[x])
|
|
63
|
+
.join('')
|
|
64
|
+
.toLowerCase()
|
|
65
|
+
.trim());
|
|
66
|
+
case ConfigType.OrientationToggle:
|
|
67
|
+
return (config.field +
|
|
68
|
+
'=' +
|
|
69
|
+
ORIENTATIONS.filter(dir => instruction[config.field][dir])
|
|
70
|
+
.map(x => orientationChars[x])
|
|
71
|
+
.join('')
|
|
72
|
+
.toLowerCase()
|
|
73
|
+
.trim());
|
|
74
|
+
case ConfigType.String:
|
|
75
|
+
case ConfigType.Icon:
|
|
76
|
+
return (config.field +
|
|
77
|
+
'=' +
|
|
78
|
+
escape(instruction[config.field]
|
|
79
|
+
.toLowerCase()
|
|
80
|
+
.trim()));
|
|
81
|
+
case ConfigType.NullableNote:
|
|
82
|
+
return (config.field +
|
|
83
|
+
'=' +
|
|
84
|
+
escape(instruction[config.field] === null
|
|
85
|
+
? ''
|
|
86
|
+
: escape(String(instruction[config.field])
|
|
87
|
+
.toLowerCase()
|
|
88
|
+
.trim())));
|
|
89
|
+
case ConfigType.Tile:
|
|
90
|
+
case ConfigType.Grid:
|
|
91
|
+
return (config.field +
|
|
92
|
+
'=' +
|
|
93
|
+
escape(this.stringifyGrid(instruction[config.field])));
|
|
94
|
+
case ConfigType.NullableGrid:
|
|
95
|
+
return (config.field +
|
|
96
|
+
'=' +
|
|
97
|
+
escape(instruction[config.field] === null
|
|
98
|
+
? ''
|
|
99
|
+
: this.stringifyGrid(instruction[config.field])));
|
|
100
|
+
case ConfigType.ControlLines:
|
|
101
|
+
return (config.field +
|
|
102
|
+
'=' +
|
|
103
|
+
escape(instruction[config.field]
|
|
104
|
+
.map(line => this.stringifyControlLine(line))
|
|
105
|
+
.join(':')));
|
|
106
|
+
case ConfigType.SolvePath:
|
|
107
|
+
return (config.field +
|
|
108
|
+
'=' +
|
|
109
|
+
escape(instruction[config.field]
|
|
110
|
+
?.map(pos => `${pos.x}_${pos.y}`)
|
|
111
|
+
.join('/') ?? ''));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
24
114
|
parseConfig(_configs, _entry) {
|
|
25
115
|
throw new Error('Checksum serializer does not support parsing');
|
|
26
116
|
}
|