adofai-lib 1.2.6 → 1.2.7
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.
- package/package.json +6 -3
- package/dist/Level.d.ts +0 -17
- package/dist/Level.js +0 -175
- package/dist/__tests__/LocalFileTest.test.d.ts +0 -2
- package/dist/__tests__/LocalFileTest.test.d.ts.map +0 -1
- package/dist/__tests__/LocalFileTest.test.js +0 -25
- package/dist/__tests__/LocalFileTest.test.js.map +0 -1
- package/dist/types/level.d.ts +0 -18
- package/dist/types/level.d.ts.map +0 -1
- package/dist/types/level.js +0 -2
- package/dist/types/level.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adofai-lib",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "A TypeScript library for advanced manipulation and analysis of ADOFAI level files.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,13 +27,16 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/jest": "^29.5.12",
|
|
29
29
|
"@types/node": "^20.11.24",
|
|
30
|
+
"gts": "^6.0.2",
|
|
30
31
|
"jest": "^29.7.0",
|
|
31
32
|
"rimraf": "^5.0.5",
|
|
32
33
|
"ts-jest": "^29.1.2",
|
|
33
34
|
"typescript": "^5.3.3"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"gts": "^6.0.2",
|
|
37
37
|
"json5": "^2.2.3"
|
|
38
|
+
},
|
|
39
|
+
"overrides": {
|
|
40
|
+
"tmp": "^0.2.4"
|
|
38
41
|
}
|
|
39
|
-
}
|
|
42
|
+
}
|
package/dist/Level.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Action, Decoration } from './types';
|
|
2
|
-
export declare class Level {
|
|
3
|
-
private filename;
|
|
4
|
-
private encoding;
|
|
5
|
-
private tiles;
|
|
6
|
-
private nonFloorDecos;
|
|
7
|
-
private settings;
|
|
8
|
-
constructor(filename?: string, encoding?: BufferEncoding);
|
|
9
|
-
private getFileString;
|
|
10
|
-
private getFileDict;
|
|
11
|
-
getAngles(): number[];
|
|
12
|
-
setAngles(angles: number[]): void;
|
|
13
|
-
getAnglesRelative(ignoreTwirls?: boolean, padMidspins?: boolean): number[];
|
|
14
|
-
getActions(condition?: (action: Action) => boolean): Action[];
|
|
15
|
-
getDecorations(condition?: (decoration: Decoration) => boolean): Decoration[];
|
|
16
|
-
writeToFile(filename?: string): void;
|
|
17
|
-
}
|
package/dist/Level.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Level = void 0;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const types_1 = require("./types");
|
|
39
|
-
class Level {
|
|
40
|
-
constructor(filename = '', encoding = 'utf-8') {
|
|
41
|
-
this.filename = filename;
|
|
42
|
-
this.encoding = encoding;
|
|
43
|
-
this.tiles = [];
|
|
44
|
-
this.nonFloorDecos = [];
|
|
45
|
-
this.settings = {};
|
|
46
|
-
const leveldict = this.getFileDict();
|
|
47
|
-
if (!leveldict.actions || !leveldict.settings || (!leveldict.angleData && !leveldict.pathData)) {
|
|
48
|
-
throw new types_1.InvalidLevelException(`The provided .adofai file is invalid. (missing: ${!leveldict.actions ? 'actions' : ''} ${!leveldict.settings ? 'settings' : ''} ${!leveldict.angleData && !leveldict.pathData ? 'angleData or pathData' : ''})`);
|
|
49
|
-
}
|
|
50
|
-
let angleData;
|
|
51
|
-
if ('angleData' in leveldict) {
|
|
52
|
-
angleData = leveldict.angleData;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
const pathchars = {
|
|
56
|
-
'R': 0, 'p': 15, 'J': 30, 'E': 45, 'T': 60, 'o': 75, 'U': 90,
|
|
57
|
-
'q': 105, 'G': 120, 'Q': 135, 'H': 150, 'W': 165, 'L': 180,
|
|
58
|
-
'x': 195, 'N': 210, 'Z': 225, 'F': 240, 'V': 255, 'D': 270,
|
|
59
|
-
'Y': 285, 'B': 300, 'C': 315, 'M': 330, 'A': 345, '!': 999
|
|
60
|
-
};
|
|
61
|
-
angleData = Array.from(leveldict.pathData).map(char => pathchars[char]);
|
|
62
|
-
}
|
|
63
|
-
angleData.push(angleData[angleData.length - 1] !== 999 ? angleData[angleData.length - 1] : (angleData[angleData.length - 2] + 180) % 360);
|
|
64
|
-
const actions = leveldict.actions;
|
|
65
|
-
const decorations = leveldict.decorations || [];
|
|
66
|
-
this.nonFloorDecos = decorations.filter((j) => !('floor' in j)).map((j) => ({ ...j }));
|
|
67
|
-
this.settings = filename !== '' ? { ...leveldict.settings } : {};
|
|
68
|
-
// Initialize tiles
|
|
69
|
-
this.tiles = angleData.map(angle => ({
|
|
70
|
-
angle,
|
|
71
|
-
actions: [],
|
|
72
|
-
decorations: []
|
|
73
|
-
}));
|
|
74
|
-
// Add actions
|
|
75
|
-
actions.forEach((action) => {
|
|
76
|
-
if (action.floor !== undefined && action.floor < this.tiles.length) {
|
|
77
|
-
this.tiles[action.floor].actions.push({ ...action });
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
// Add decorations
|
|
81
|
-
decorations.forEach((deco) => {
|
|
82
|
-
if ('floor' in deco) {
|
|
83
|
-
if (deco.floor >= this.tiles.length) {
|
|
84
|
-
this.tiles[this.tiles.length - 1].decorations.push({ ...deco });
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
this.tiles[deco.floor].decorations.push({ ...deco });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
getFileString() {
|
|
93
|
-
if (!this.filename)
|
|
94
|
-
return '';
|
|
95
|
-
return fs.readFileSync(this.filename, { encoding: this.encoding });
|
|
96
|
-
}
|
|
97
|
-
getFileDict() {
|
|
98
|
-
if (!this.filename) {
|
|
99
|
-
return {
|
|
100
|
-
angleData: [0],
|
|
101
|
-
settings: {},
|
|
102
|
-
actions: [],
|
|
103
|
-
decorations: []
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
const content = this.getFileString();
|
|
107
|
-
return JSON.parse(content);
|
|
108
|
-
}
|
|
109
|
-
getAngles() {
|
|
110
|
-
return this.tiles.map(tile => tile.angle);
|
|
111
|
-
}
|
|
112
|
-
setAngles(angles) {
|
|
113
|
-
if (angles.length > this.tiles.length) {
|
|
114
|
-
this.tiles.push({
|
|
115
|
-
angle: angles[angles.length - 1],
|
|
116
|
-
actions: [],
|
|
117
|
-
decorations: []
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
this.tiles = this.tiles.slice(0, angles.length);
|
|
121
|
-
this.tiles.forEach((tile, i) => {
|
|
122
|
-
tile.angle = angles[i];
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
getAnglesRelative(ignoreTwirls = false, padMidspins = false) {
|
|
126
|
-
const absangles = this.getAngles().slice(0, -1);
|
|
127
|
-
if (!ignoreTwirls) {
|
|
128
|
-
const twirls = this.getActions(action => action.eventType === 'Twirl')
|
|
129
|
-
.map(event => event.floor);
|
|
130
|
-
for (const twirl of twirls.reverse()) {
|
|
131
|
-
absangles.splice(twirl, absangles.length - twirl, ...absangles.slice(twirl).map(angle => angle !== 999 ? (2 * absangles[twirl - 1] - angle) % 360 : 999));
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
const midspins = absangles.map((angle, idx) => angle === 999 ? idx : -1).filter(idx => idx !== -1);
|
|
135
|
-
for (const midspin of midspins.reverse()) {
|
|
136
|
-
absangles.splice(midspin + 1, absangles.length - (midspin + 1), ...absangles.slice(midspin + 1).map(angle => angle !== 999 ? (angle + 180) % 360 : 999));
|
|
137
|
-
}
|
|
138
|
-
if (!padMidspins) {
|
|
139
|
-
absangles.splice(0, absangles.length, ...absangles.filter(angle => angle !== 999));
|
|
140
|
-
}
|
|
141
|
-
return absangles.map((angle, idx) => {
|
|
142
|
-
if (angle === 999)
|
|
143
|
-
return 0;
|
|
144
|
-
if (idx === 0)
|
|
145
|
-
return ((0 - angle + 180 - 1) % 360) + 1;
|
|
146
|
-
if (absangles[idx - 1] === 999) {
|
|
147
|
-
return ((absangles[idx - 2] - angle + 180 - 1) % 360) + 1;
|
|
148
|
-
}
|
|
149
|
-
return ((absangles[idx - 1] - angle + 180 - 1) % 360) + 1;
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
getActions(condition = () => true) {
|
|
153
|
-
return this.tiles.flatMap(tile => tile.actions.filter(condition));
|
|
154
|
-
}
|
|
155
|
-
getDecorations(condition = () => true) {
|
|
156
|
-
return [
|
|
157
|
-
...this.tiles.flatMap(tile => tile.decorations.filter(condition)),
|
|
158
|
-
...this.nonFloorDecos.filter(condition)
|
|
159
|
-
];
|
|
160
|
-
}
|
|
161
|
-
writeToFile(filename) {
|
|
162
|
-
const final = {
|
|
163
|
-
angleData: this.tiles.map(tile => tile.angle),
|
|
164
|
-
settings: { ...this.settings },
|
|
165
|
-
actions: this.tiles.flatMap(tile => tile.actions),
|
|
166
|
-
decorations: [
|
|
167
|
-
...this.tiles.flatMap(tile => tile.decorations),
|
|
168
|
-
...this.nonFloorDecos
|
|
169
|
-
]
|
|
170
|
-
};
|
|
171
|
-
const outputFile = filename || this.filename;
|
|
172
|
-
fs.writeFileSync(outputFile, JSON.stringify(final, null, 4), { encoding: this.encoding });
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
exports.Level = Level;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalFileTest.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/LocalFileTest.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import LevelDict from '../LevelDict.js';
|
|
2
|
-
import { getLevelLengthInMs } from '../utils/analysisUtils.js';
|
|
3
|
-
it('tests timing calculation', () => {
|
|
4
|
-
const level = new LevelDict('C:/Users/Acer_Nitro/Downloads/Misohagi 1/2 The heir who glistens in dark blue.adofai');
|
|
5
|
-
const tiles = level.getTiles();
|
|
6
|
-
const batchSize = 50;
|
|
7
|
-
const durations = [];
|
|
8
|
-
let cumulativeDuration = 0;
|
|
9
|
-
for (let start = 0; start < tiles.length; start += batchSize) {
|
|
10
|
-
const end = Math.min(start + batchSize, tiles.length);
|
|
11
|
-
const segmentTiles = tiles.slice(start, end);
|
|
12
|
-
const sum = segmentTiles.reduce((acc, tile) => acc + (typeof tile.durationMs === 'number' ? tile.durationMs : 0), 0);
|
|
13
|
-
durations.push(`${start + 1}-${end}: ${(sum / 1000).toFixed(2)}s (segment starts at ${(() => {
|
|
14
|
-
const totalSeconds = Math.floor(cumulativeDuration / 1000);
|
|
15
|
-
const minutes = Math.floor(totalSeconds / 60);
|
|
16
|
-
const seconds = totalSeconds % 60;
|
|
17
|
-
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
|
|
18
|
-
})()}) - rotation: ${segmentTiles[0].rotationFlipped ? 'ACW' : 'CW'}`);
|
|
19
|
-
cumulativeDuration += sum;
|
|
20
|
-
}
|
|
21
|
-
console.log(durations.join('\n'));
|
|
22
|
-
console.log("getLevelLengthInMs(level): " + getLevelLengthInMs(level) / 1000 + "s");
|
|
23
|
-
expect(durations).toBeDefined();
|
|
24
|
-
});
|
|
25
|
-
//# sourceMappingURL=LocalFileTest.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalFileTest.test.js","sourceRoot":"","sources":["../../src/__tests__/LocalFileTest.test.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;IAClC,MAAM,KAAK,GAAG,IAAI,SAAS,CACzB,sFAAsF,CACzF,CAAC;IACA,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,MAAM,SAAS,GAAG,EAAE,CAAC;IACrB,MAAM,SAAS,GAAG,EAAE,CAAC;IACrB,IAAI,kBAAkB,GAAG,CAAC,C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,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,6BAA6B,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAC,IAAI,GAAG,GAAG,CAAC,CAAC;IAClF,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC,CAAC,CAAC"}
|
package/dist/types/level.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Settings } from ".";
|
|
2
|
-
export interface LevelJSON {
|
|
3
|
-
actions?: Array<Record<string, any>>;
|
|
4
|
-
decorations?: Array<Record<string, any>>;
|
|
5
|
-
settings?: Settings;
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}
|
|
8
|
-
export interface TransformOptions {
|
|
9
|
-
keepEventTypes?: Set<string>;
|
|
10
|
-
dropEventTypes?: Set<string>;
|
|
11
|
-
baseCameraZoom?: number;
|
|
12
|
-
extraProtectedEventTypes?: Set<string>;
|
|
13
|
-
additionalPatterns?: Set<RegExp>;
|
|
14
|
-
constantBackgroundColor?: string;
|
|
15
|
-
removeForegroundFlash?: boolean;
|
|
16
|
-
dropFilters?: Set<string>;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=level.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"level.d.ts","sourceRoot":"","sources":["../../src/types/level.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;AAE7B,MAAM,WAAW,SAAS;IACtB,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACzC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC7B,cAAc,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wBAAwB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACvC,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC7B"}
|
package/dist/types/level.js
DELETED
package/dist/types/level.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"level.js","sourceRoot":"","sources":["../../src/types/level.ts"],"names":[],"mappings":""}
|