Commit f41e7189 authored by nanahira's avatar nanahira

add normalize yrp

parent 4f68b25f
......@@ -41,3 +41,4 @@ lerna-debug.log*
/test-release.cdb
/bin
/ygopro
/tests/yrp-patched
......@@ -14,7 +14,8 @@
"sql.js": "^1.13.0",
"ygopro-cdb-encode": "^1.0.5",
"ygopro-jstest": "^1.1.3",
"ygopro-msg-encode": "^1.1.31"
"ygopro-msg-encode": "^1.1.31",
"ygopro-yrp-encode": "^1.0.1"
},
"devDependencies": {
"@types/jest": "^30.0.0",
......
......@@ -16,7 +16,7 @@ describe("No Red Text", () => {
const buf = await fs.promises.readFile(path.resolve(process.cwd(), file));
const db = new SQL.Database(buf);
const cdb = new YGOProCdb(db);
for (const data of cdb.find(
for (const data of cdb.step(
`datas.type != ${OcgcoreScriptConstants.TYPE_MONSTER | OcgcoreScriptConstants.TYPE_NORMAL} and datas.type & ${OcgcoreScriptConstants.TYPE_TOKEN} = 0 and not (datas.alias > 0 and datas.alias - datas.id < 20)`,
)) {
const id = data.code;
......
......@@ -3,6 +3,7 @@ import fs from "node:fs";
import { createTest } from "../utility/create-test";
import { toYrpInfo } from "../utility/yrp-info";
import yaml from "js-yaml";
import { normalizeYrpSingle } from "../utility/normalize-yrp-single";
async function main() {
const yrpFilenames = process.argv.slice(2);
......@@ -26,7 +27,8 @@ async function main() {
);
await fs.promises.mkdir(path.dirname(destPath), { recursive: true });
console.log(`Will save YRP info from ${fullPath} to ${destPath}`);
await createTest({ yrp: fullPath }, async (test) => {
const yrp = await normalizeYrpSingle(fullPath);
await createTest({ yrp }, async (test) => {
const info = toYrpInfo(test);
console.log(info.snapshotText);
const yamlStr = yaml.dump(info);
......
import path from "path";
import { YGOProYrp } from "ygopro-yrp-encode";
import fs from "node:fs"
export const normalizeYrpSingle = async (yrpPath: string) => {
const yrpFilename = path.basename(yrpPath);
const yrp = new YGOProYrp().fromYrp(await fs.promises.readFile(yrpPath));
if (
yrp.isSingleMode &&
!fs.existsSync(
path.resolve(process.cwd(), "tests", "single", yrp.singleScript),
)
) {
// patch yrp filename here
const patchedYrpFilename = `${path.basename(yrpPath, ".yrp")}.lua`;
const patchedYrpPath = path.resolve(
process.cwd(),
"tests",
"single",
patchedYrpFilename,
);
if (fs.existsSync(patchedYrpPath)) {
yrp.singleScript = patchedYrpFilename;
const patchedYrpDir = path.resolve(process.cwd(), "tests", "yrp-patched");
await fs.promises.mkdir(patchedYrpDir, { recursive: true });
const newYrpPath = path.resolve(patchedYrpDir, yrpFilename);
await fs.promises.writeFile(newYrpPath, yrp.toYrp());
} else {
throw new Error(
`YRP ${yrpFilename} references singleScript ${yrp.singleScript} which does not exist, and no patched script found at ${patchedYrpPath}`,
);
}
}
return yrp;
};
messages:
- identifier: 5
msg: Win
player: 1
type: 2
- identifier: 5
msg: Win
player: 0
type: 2
- identifier: 40
msg: NewTurn
- identifier: 33
msg: ShuffleHand
player: 0
count: 2
cards:
- 28985331
- 10000000
- identifier: 33
msg: ShuffleHand
player: 1
count: 1
cards:
- 14558127
- identifier: 41
msg: NewPhase
phase: 1
......@@ -27,23 +29,196 @@ messages:
- identifier: 11
msg: SelectIdleCmd
player: 0
summonableCount: 0
summonableCards: []
summonableCount: 1
summonableCards:
- code: 28985331
controller: 0
location: 2
sequence: 0
spSummonableCount: 0
spSummonableCards: []
reposableCount: 0
reposableCards: []
msetableCount: 0
msetableCards: []
msetableCount: 1
msetableCards:
- code: 28985331
controller: 0
location: 2
sequence: 0
ssetableCount: 0
ssetableCards: []
activatableCount: 0
activatableCards: []
canBp: 0
canBp: 1
canEp: 1
canShuffle: 0
canShuffle: 1
snapshot:
cards: []
cards:
- flags: 15712255
controller: 0
location: 1
sequence: 0
empty: false
code: 5560911
position: 10
alias: 5560911
type: 4129
level: 7
rank: 0
attribute: 32
race: 8192
attack: 1000
defense: 3000
baseAttack: 1000
baseDefense: 3000
reason: 0
reasonCard:
controller: 0
location: 0
sequence: 0
position: 0
targetCards: []
overlayCards: []
counters: []
owner: 0
status: 0
lscale: 0
rscale: 0
link: 0
linkMarker: 0
name: 亡龙之战栗-死欲龙
- flags: 15712255
controller: 0
location: 2
sequence: 0
empty: false
code: 28985331
position: 10
alias: 28985331
type: 33
level: 4
rank: 0
attribute: 32
race: 1
attack: 1400
defense: 1200
baseAttack: 1400
baseDefense: 1200
reason: 0
reasonCard:
controller: 0
location: 0
sequence: 0
position: 0
targetCards: []
overlayCards: []
counters: []
owner: 0
status: 0
lscale: 0
rscale: 0
link: 0
linkMarker: 0
name: 终末之骑士
- flags: 15712255
controller: 0
location: 2
sequence: 1
empty: false
code: 10000000
position: 10
alias: 10000000
type: 33
level: 10
rank: 0
attribute: 64
race: 2097152
attack: 4000
defense: 4000
baseAttack: 4000
baseDefense: 4000
reason: 0
reasonCard:
controller: 0
location: 0
sequence: 0
position: 0
targetCards: []
overlayCards: []
counters: []
owner: 0
status: 0
lscale: 0
rscale: 0
link: 0
linkMarker: 0
name: 欧贝利斯克之巨神兵
- flags: 15712255
controller: 0
location: 64
sequence: 0
empty: false
code: 73580471
position: 10
alias: 73580471
type: 8225
level: 7
rank: 0
attribute: 4
race: 8192
attack: 2400
defense: 1800
baseAttack: 2400
baseDefense: 1800
reason: 0
reasonCard:
controller: 0
location: 0
sequence: 0
position: 0
targetCards: []
overlayCards: []
counters: []
owner: 0
status: 0
lscale: 0
rscale: 0
link: 0
linkMarker: 0
name: 黑蔷薇龙
- flags: 15712255
controller: 1
location: 2
sequence: 0
empty: false
code: 14558127
position: 10
alias: 14558127
type: 4129
level: 3
rank: 0
attribute: 4
race: 16
attack: 0
defense: 1800
baseAttack: 0
baseDefense: 1800
reason: 0
reasonCard:
controller: 0
location: 0
sequence: 0
position: 0
targetCards: []
overlayCards: []
counters: []
owner: 1
status: 0
lscale: 0
rscale: 0
link: 0
linkMarker: 0
name: 灰流丽
lp:
- 8000
- 8000
......@@ -52,5 +227,8 @@ snapshotText: |-
********* Field Snapshot *********
LP: P0 8000 | P1 8000
********* Player 0 *********
Hand: 终末之骑士
欧贝利斯克之巨神兵
********* Player 1 *********
Hand: 灰流丽
********* Finish *********
......@@ -2,8 +2,10 @@ import { existsSync, readdirSync } from "node:fs";
import { createTest } from "./utility/create-test";
import { MsgSnapshot, toYrpInfo, YrpInfo } from "./utility/yrp-info";
import yaml from "js-yaml";
import path from "node:path";
import path, { normalize } from "node:path";
import fs from "node:fs";
import { YGOProYrp } from "ygopro-yrp-encode";
import { normalizeYrpSingle } from "./utility/normalize-yrp-single";
describe("YRP", () => {
const yrpDirPath = path.resolve(process.cwd(), "tests", "yrp");
......@@ -28,7 +30,8 @@ describe("YRP", () => {
const testName = `YRP: ${yrpRelativePath}`;
it(testName, async () => {
const yrpPath = path.resolve(yrpDirPath, yrpRelativePath);
await createTest({ yrp: yrpPath }, async (test) => {
const yrp = await normalizeYrpSingle(yrpPath);
await createTest({ yrp }, async (test) => {
const yrpInfoPath = path.resolve(
process.cwd(),
"tests",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment