kipphi 2.0.1 → 2.1.0

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.
@@ -0,0 +1,304 @@
1
+ import { Chart, JudgeLineGroup, BasicEventName, UIName } from "../chart";
2
+ import { ExtendedEventTypeName, RGB } from "../chartTypes";
3
+ import { EventNodeSequence } from "../event";
4
+ import { JudgeLine, ExtendedLayer } from "../judgeline";
5
+ import { ComplexOperation, LazyOperation, Operation } from "./basic";
6
+ import { EventNodeSequenceRenameOperation } from "./event";
7
+
8
+
9
+
10
+ // 有点怪异,感觉破坏了纯净性。不管了(
11
+ enum JudgeLinesEditorLayoutType {
12
+ ordered = 0b001,
13
+ tree = 0b010,
14
+ grouped = 0b100
15
+ }
16
+
17
+
18
+ export class JudgeLineInheritanceChangeOperation extends Operation {
19
+ originalValue: JudgeLine | null;
20
+ updatesEditor = true;
21
+ static REFLOWS = JudgeLinesEditorLayoutType.tree;
22
+ reflows = JudgeLineInheritanceChangeOperation.REFLOWS;
23
+ constructor(public chart: Chart, public judgeLine: JudgeLine, public value: JudgeLine | null) {
24
+ super();
25
+ this.originalValue = judgeLine.father;
26
+ // 这里只会让它静默失败,外面调用的时候能够在判断一次并抛错误才是最好的
27
+ if (JudgeLine.checkinterdependency(judgeLine, value)) {
28
+ this.ineffective = true;
29
+ }
30
+ }
31
+ do() {
32
+ const line = this.judgeLine;
33
+ line.father = this.value;
34
+ if (this.originalValue) {
35
+ this.originalValue.children.delete(line);
36
+ } else {
37
+ const index = this.chart.orphanLines.indexOf(line);
38
+ if (index >= 0) // Impossible to be false, theoretically
39
+ this.chart.orphanLines.splice(index, 1)
40
+ }
41
+ if (this.value) {
42
+ this.value.children.add(line);
43
+ } else {
44
+ this.chart.orphanLines.push(line);
45
+ }
46
+ }
47
+ undo() {
48
+ const line = this.judgeLine;
49
+ line.father = this.originalValue;
50
+ if (this.originalValue) {
51
+ this.originalValue.children.add(line);
52
+ } else {
53
+ this.chart.orphanLines.push(line);
54
+ }
55
+ if (this.value) {
56
+ this.value.children.delete(line);
57
+ } else {
58
+ const index = this.chart.orphanLines.indexOf(line);
59
+ if (index >= 0) // Impossible to be false, theoretically
60
+ this.chart.orphanLines.splice(index, 1)
61
+ }
62
+ }
63
+ }
64
+
65
+ export class JudgeLineRenameOperation extends Operation {
66
+ updatesEditor = true;
67
+ originalValue: string;
68
+ constructor(public judgeLine: JudgeLine, public value: string) {
69
+ super();
70
+ this.originalValue = judgeLine.name;
71
+ }
72
+ do() {
73
+ this.judgeLine.name = this.value;
74
+ }
75
+ undo() {
76
+ this.judgeLine.name = this.originalValue;
77
+ }
78
+ }
79
+
80
+ type JudgeLinePropName = "name" | "rotatesWithFather" | "anchor" | "texture" | "cover" | "zOrder";
81
+
82
+ export class JudgeLinePropChangeOperation<T extends JudgeLinePropName> extends Operation {
83
+ updatesEditor = true;
84
+ originalValue: JudgeLine[T];
85
+ constructor(public judgeLine: JudgeLine, public field: T, public value: JudgeLine[T]) {
86
+ super();
87
+ this.originalValue = judgeLine[field];
88
+ }
89
+ do() {
90
+ this.judgeLine[this.field] = this.value;
91
+ }
92
+ undo() {
93
+ this.judgeLine[this.field] = this.originalValue;
94
+ }
95
+ }
96
+
97
+ export class JudgeLineRegroupOperation extends Operation {
98
+ updatesEditor = true;
99
+ reflows = JudgeLinesEditorLayoutType.grouped;
100
+ originalValue: JudgeLineGroup;
101
+ constructor(public judgeLine: JudgeLine, public value: JudgeLineGroup) {
102
+ super();
103
+ this.originalValue = judgeLine.group;
104
+ }
105
+ do() {
106
+ this.judgeLine.group = this.value;
107
+ this.value.add(this.judgeLine);
108
+ this.originalValue.remove(this.judgeLine);
109
+ }
110
+ undo() {
111
+ this.judgeLine.group = this.originalValue;
112
+ this.originalValue.add(this.judgeLine);
113
+ this.value.remove(this.judgeLine);
114
+ }
115
+ }
116
+
117
+ export class JudgeLineCreateOperation extends Operation {
118
+ reflows = JudgeLinesEditorLayoutType.grouped | JudgeLinesEditorLayoutType.tree | JudgeLinesEditorLayoutType.ordered;
119
+ // 之前把=写成了:半天不知道咋错了
120
+ constructor(public chart: Chart, public judgeLine: JudgeLine) {
121
+ super();
122
+ }
123
+ do() {
124
+ const id = this.chart.judgeLines.length;
125
+ this.judgeLine.id = id;
126
+ this.chart.judgeLines.push(this.judgeLine);
127
+ this.chart.orphanLines.push(this.judgeLine);
128
+ this.chart.judgeLineGroups[0].add(this.judgeLine);
129
+ }
130
+ undo() {
131
+ this.chart.judgeLineGroups[0].remove(this.judgeLine);
132
+ this.chart.judgeLines.splice(this.chart.judgeLines.indexOf(this.judgeLine), 1);
133
+ this.chart.orphanLines.splice(this.chart.orphanLines.indexOf(this.judgeLine), 1);
134
+ }
135
+ }
136
+
137
+ class JudgeLineRemoveOperation extends Operation {
138
+ readonly originalGroup: JudgeLineGroup;
139
+ constructor(public chart: Chart, public judgeLine: JudgeLine) {
140
+ super();
141
+ if (!this.chart.judgeLines.includes(this.judgeLine)) {
142
+ this.ineffective = true;
143
+ }
144
+ this.originalGroup = judgeLine.group;
145
+ }
146
+ do() {
147
+ this.chart.judgeLines.splice(this.chart.judgeLines.indexOf(this.judgeLine), 1);
148
+ if (this.chart.orphanLines.includes(this.judgeLine)) {
149
+ this.chart.orphanLines.splice(this.chart.orphanLines.indexOf(this.judgeLine), 1);
150
+ }
151
+ this.originalGroup.remove(this.judgeLine);
152
+ }
153
+ undo() {
154
+ this.chart.judgeLines.splice(this.judgeLine.id, 0, this.judgeLine);
155
+ this.chart.orphanLines.push(this.judgeLine);
156
+ this.originalGroup.add(this.judgeLine);
157
+ }
158
+ }
159
+
160
+ export class JudgeLineDeleteOperation extends ComplexOperation<[JudgeLineRemoveOperation, ...LazyOperation<typeof JudgeLineIdChangeOperation>[]]> {
161
+ constructor(public chart: Chart, public judgeLine: JudgeLine) {
162
+ super(new JudgeLineRemoveOperation(chart, judgeLine), ...chart.judgeLines.slice(judgeLine.id + 1).map(line => JudgeLineIdChangeOperation.lazy(line)));
163
+ }
164
+ }
165
+
166
+
167
+ export class JudgeLineENSChangeOperation extends Operation {
168
+ originalValue: EventNodeSequence;
169
+ constructor(public judgeLine: JudgeLine, public layerId: number, public typeStr: BasicEventName, public value: EventNodeSequence) {
170
+ super();
171
+ this.originalValue = judgeLine.eventLayers[layerId][typeStr];
172
+ }
173
+ do() {
174
+ this.judgeLine.eventLayers[this.layerId][this.typeStr] = this.value;
175
+ }
176
+ undo() {
177
+ this.judgeLine.eventLayers[this.layerId][this.typeStr] = this.originalValue;
178
+ }
179
+ }
180
+
181
+
182
+ export type ENSOfTypeName<T extends ExtendedEventTypeName> = {
183
+ "scaleX": EventNodeSequence<number>,
184
+ "scaleY": EventNodeSequence<number>
185
+ "text": EventNodeSequence<string>,
186
+ "color": EventNodeSequence<RGB>
187
+ }[T]
188
+ export class JudgeLineExtendENSChangeOperation<T extends ExtendedEventTypeName> extends Operation {
189
+ originalValue: ENSOfTypeName<T>;
190
+ constructor(public judgeLine: JudgeLine, public typeStr: T, public value: ENSOfTypeName<T> | null) {
191
+ super();
192
+ this.originalValue = judgeLine.extendedLayer[typeStr satisfies keyof ExtendedLayer] as ENSOfTypeName<T>;
193
+ }
194
+ do() {
195
+ this.judgeLine.extendedLayer[this.typeStr] = this.value
196
+ }
197
+ undo() {
198
+ this.judgeLine.extendedLayer[this.typeStr] = this.originalValue
199
+ }
200
+
201
+ }
202
+
203
+ export class UIAttachOperation extends Operation {
204
+ updatesEditor = true;
205
+ constructor(public chart: Chart, public judgeLine: JudgeLine, public ui: UIName) {
206
+ super();
207
+ }
208
+ do() {
209
+ this.chart.attachUIToLine(this.ui, this.judgeLine);
210
+ }
211
+ undo() {
212
+ this.chart.detachUI(this.ui);
213
+ }
214
+ }
215
+
216
+ export class UIDetachOperation extends Operation {
217
+ updatesEditor = true;
218
+ judgeLine: JudgeLine;
219
+ constructor(public chart: Chart, public ui: UIName) {
220
+ super();
221
+ if (chart[`${ui}Attach` satisfies keyof Chart]) {
222
+ this.judgeLine = chart[`${ui}Attach` satisfies keyof Chart];
223
+ } else {
224
+ this.ineffective = true;
225
+ }
226
+ }
227
+ do() {
228
+ this.chart.detachUI(this.ui);
229
+ }
230
+ undo() {
231
+ this.chart.attachUIToLine(this.ui, this.judgeLine);
232
+ }
233
+ }
234
+
235
+ export class JudgeLineDetachAllUIOperation extends Operation {
236
+ updatesEditor = true;
237
+ uinames: UIName[];
238
+ constructor(public chart: Chart, public judgeLine: JudgeLine) {
239
+ super();
240
+ this.uinames = chart.queryJudgeLineUI(this.judgeLine);
241
+ }
242
+ do() {
243
+ for (const ui of this.uinames) {
244
+ this.chart.detachUI(ui);
245
+ }
246
+ }
247
+ undo() {
248
+ for (const ui of this.uinames) {
249
+ this.chart.attachUIToLine(ui, this.judgeLine);
250
+ }
251
+ }
252
+ }
253
+
254
+ /**
255
+ * 修改判定线id
256
+ * 不需要自己传入ID
257
+ */
258
+ export class JudgeLineIdChangeOperation extends ComplexOperation<EventNodeSequenceRenameOperation[]> {
259
+ originalValue: number;
260
+ public value: number;
261
+ public judgeLine: JudgeLine;
262
+ /**
263
+ *
264
+ * @param judgeLine
265
+ * @param renamesENS 是否对事件序列进行重命名
266
+ */
267
+ constructor(judgeLine: JudgeLine, renamesENS: boolean = true) {
268
+ const value = judgeLine.chart.judgeLines.indexOf(judgeLine);
269
+ const extendedLayer = judgeLine.extendedLayer;
270
+ const ineffective = value === judgeLine.id;
271
+ if (renamesENS && !ineffective) {
272
+ super(
273
+ ...judgeLine.eventLayers
274
+ .flatMap((layer) => [layer.alpha, layer.moveX, layer.moveY, layer.rotate])
275
+ .filter(seq => seq && seq.id.match(/^#\d+\./))
276
+ .map(seq => new EventNodeSequenceRenameOperation(
277
+ seq,
278
+ `#${value}.${seq.id.substring(seq.id.indexOf(".") + 1)}`
279
+ )),
280
+ ...[extendedLayer.scaleX, extendedLayer.scaleY, extendedLayer.text, extendedLayer.color,
281
+ judgeLine.speedSequence]
282
+ .filter(seq => seq && seq.id.match(/^#\d+\./))
283
+ .map(seq => new EventNodeSequenceRenameOperation(
284
+ seq,
285
+ `#${value}.${seq.id.substring(seq.id.indexOf(".") + 1)}`
286
+ ))
287
+ );
288
+ } else {
289
+ super();
290
+ }
291
+ this.ineffective = ineffective;
292
+ this.judgeLine = judgeLine;
293
+ this.originalValue = judgeLine.id;
294
+ this.value = value;
295
+ }
296
+ do(chart: Chart) {
297
+ this.judgeLine.id = this.value;
298
+ super.do(chart);
299
+ }
300
+ undo(chart: Chart) {
301
+ this.judgeLine.id = this.originalValue;
302
+ super.do(chart);
303
+ }
304
+ }
@@ -0,0 +1,60 @@
1
+ import { Operation, ComplexOperation } from "./basic";
2
+ import { EventMacroTime, EventMacroValue} from "../macro"
3
+ import { EventStartNode } from "../event";
4
+ import { TimeT } from "../chartTypes";
5
+ import { Chart } from "../chart";
6
+ import { EventNodeTimeChangeOperation } from "./event";
7
+
8
+
9
+
10
+ export class EventNodeMacroTimeReevaluateOperation extends EventNodeTimeChangeOperation {
11
+ constructor(node: EventStartNode<any>, chart: Chart) {
12
+ let time: TimeT = node.macroTime?.eval?.(node, chart);
13
+ if (!(Array.isArray(time) && time.length === 3)) {
14
+ time = node.time;
15
+ }
16
+ super(node, time);
17
+ }
18
+ }
19
+
20
+ export class MacroTimeAssignOperation extends Operation {
21
+ public originalMacroTime: EventMacroTime;
22
+ private timeChangeOperation: EventNodeMacroTimeReevaluateOperation;
23
+ constructor(public macroTime: EventMacroTime, public node: EventStartNode<any>) {
24
+ super();
25
+ this.originalMacroTime = node.macroTime;
26
+ }
27
+ do(chart: Chart) {
28
+ this.node.macroTime = this.macroTime;
29
+ // 宏是可以有随机性的,理论上重做指令可能会产生不同结果
30
+ this.timeChangeOperation = new EventNodeMacroTimeReevaluateOperation(this.node, chart)
31
+ }
32
+ undo(_chart: Chart) {
33
+ this.node.macroTime = this.originalMacroTime;
34
+ this.timeChangeOperation.undo();
35
+ }
36
+ }
37
+
38
+ export class MacroTimeDeassginOperation extends Operation {
39
+ public originalMacroTime: EventMacroTime;
40
+ constructor(public node: EventStartNode<any>) {
41
+ super();
42
+ this.originalMacroTime = node.macroTime;
43
+ }
44
+ do(chart: Chart) {
45
+ this.node.macroTime = null;
46
+ }
47
+ undo(_chart: Chart) {
48
+ this.node.macroTime = this.originalMacroTime;
49
+ }
50
+ }
51
+
52
+ export class MacroTimeReevaluateOperation extends ComplexOperation<EventNodeMacroTimeReevaluateOperation[]> {
53
+ constructor(macroTime: EventMacroTime, chart: Chart) {
54
+ const ops: EventNodeMacroTimeReevaluateOperation[] = [];
55
+ for (const [node, _] of macroTime.consumers) {
56
+ ops.push(new EventNodeMacroTimeReevaluateOperation(node, chart));
57
+ }
58
+ super(...ops);
59
+ }
60
+ }