Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ci
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup ni
run: npm add -g @antfu/ni
- name: Install Dependencies
run: nci
- name: Typecheck
run: nr typecheck && nr lint
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ node_modules/
.idea/
dist/
yarn-error.log
test-data/
test-data/
.eslintcache
*.NPK
.DS_Store
12 changes: 12 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

if [ "$SKIP_SIMPLE_GIT_HOOKS" = "1" ]; then
echo "[INFO] SKIP_SIMPLE_GIT_HOOKS is set to 1, skipping hook."
exit 0
fi

if [ -f "$SIMPLE_GIT_HOOKS_RC" ]; then
. "$SIMPLE_GIT_HOOKS_RC"
fi

npx lint-staged
14 changes: 0 additions & 14 deletions build.config.ts

This file was deleted.

5 changes: 5 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { curev } from "@curev/eslint-config";

export default curev({
unocss: false
});
28 changes: 28 additions & 0 deletions example/extract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Img } from "../src/model/img";
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
import { Extract } from "../src";

function getNumber(s: string) {
return Number.parseInt(s.replace(/[^\d+]/g, ""));
}
(async () => {
const createMatch = (code1: number) => {
return (item: Img) => {
const code0 = getNumber(item.path);
if (code0 === code1) {
return true;
}
return code0 % 100 === 0 && Math.floor(code0 / 100) === Math.floor(code1 / 100);
};
};
fs.createReadStream(path.resolve(process.cwd(), "sprite_character_swordman_equipment_avatar_pants.NPK"))
.pipe(new Extract({
match: createMatch(5603)
}))
.on("finish", (list: Img[]) => {
const sprite = list[0].sprites[0];
sprite.toPng(path.resolve(process.cwd(), "test-data/test.png"));
});
})();
25 changes: 10 additions & 15 deletions example/find.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
/***
@author kritsu
@date 2019/12/6 12:27
**/
import type { Img } from "../src/model/img";

import fs from "fs";
import fs from "node:fs";

import qs from "querystring";
import path from "node:path";
import qs from "node:querystring";

import path from "path";
import { Extract } from "../src";

import type { Img } from "../src/model/img";

export function find(outputPath: string, profession: string, code: string, excludes: string[] = []) {
const parts = qs.parse(code) as Record<string, string>;

excludes.forEach(e => delete parts[e]);
excludes.forEach((e) => delete parts[e]);

const entries = Object.entries(parts);

Expand All @@ -37,7 +32,7 @@ export function find(outputPath: string, profession: string, code: string, exclu
fs.createReadStream(path.resolve(outputPath, f))
.pipe(new Extract({ match }))
.on("finish", (list: Img[]) => {
list = list.map(e => {
list = list.map((e) => {
const index = code1 % 100;
e.path = replacePath(e.path, code1);
e.paletteIndex = index;
Expand All @@ -47,7 +42,8 @@ export function find(outputPath: string, profession: string, code: string, exclu
if (array.length === entries.length) {
resolve(Array.from(array.flat()));
}
}).on("error", e => {
})
.on("error", (e) => {
reject(e);
});
});
Expand All @@ -70,7 +66,6 @@ function getDressFileName(profession: string, part: string, type = "avatar") {
return `sprite_character_${profession}equipment_${type}_${part}.NPK`;
}

function getNumber(s) {
return parseInt(s.replace(/[^\d+]/ig, ""));
function getNumber(s: string) {
return Number.parseInt(s.replace(/[^\d+]/g, ""));
}

14 changes: 4 additions & 10 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/***
@author kritsu
@date 2020/2/7 14:40
**/

import { Merge } from "../src";
import type { Img } from "../src/model/img";
import { Merge } from "../src";
import { find } from "./find";

const outputPath = "E:\\WeGameApps\\地下城与勇士\\ImagePacks2";
const outputPath = "F:\\WeGameApps\\地下城与勇士:创新世纪\\ImagePacks2";

const code = "hair=11200&coat=17000&skin=0000&pants=5603&shoes=9900";
const code = "pants=5603";

const profession = "swordman";

Expand All @@ -20,9 +15,8 @@ const profession = "swordman";
img.path = "test.img";
const first = img.sprites[0];

first.toPng("D:/test.png");
first.toPng("./test-data/test.png");

// eslint-disable-next-line no-console
console.info(`${performance.now() - start}ms`);
})();

11 changes: 7 additions & 4 deletions example/test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import fs from "fs";
import path from "path";
import type { Img } from "../src";
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
import { Extract } from "../src";
const GAME_DIR = "E:\\WeGameApps\\地下城与勇士\\ImagePacks2";

const GAME_DIR = "F:\\WeGameApps\\地下城与勇士:创新世纪\\ImagePacks2";

fs.createReadStream(path.resolve(GAME_DIR, "sprite_character_gunblader_equipment_avatar_face.NPK"))
.pipe(new Extract({
match: (item) => {
return item.path.includes("sprite/character/gunblader/equipment/avatar/face/gb_face5402b.img");
}
})).on("finish", (list: Img[]) => {
}))
.on("finish", (list: Img[]) => {
const sprite = list[0].sprites[0];

sprite.toPng(path.resolve(process.cwd(), "./test-data/test.png"));
Expand Down
71 changes: 40 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
{
"name": "libimg",
"type": "module",
"version": "0.2.3",
"packageManager": "pnpm@10.12.1",
"description": "",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"scripts": {
"dev": "tsx ./example/index.ts",
"bump": "bumpp package.json",
"build": "unbuild",
"stub": "unbuild --stub",
"prepare": "simple-git-hooks"
},
"keywords": [],
"author": "Chizuki",
"license": "MIT",
"keywords": [],
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.cts",
"files": [
"dist/"
],
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix"
]
"scripts": {
"dev": "tsx ./example/index.ts",
"lint": "eslint --cache",
"bump": "bumpp package.json",
"build": "tsdown",
"prepare": "simple-git-hooks",
"typecheck": "tsc --noEmit"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
"dependencies": {
"maybe-types": "^0.2.0",
"pngjs": "^7.0.0"
},
"devDependencies": {
"@curev/eslint-config": "^0.0.7",
"@types/node": "^13.7.0",
"@types/pngjs": "^6.0.1",
"bumpp": "^9.0.0",
"eslint": "^8.36.0",
"husky": "^8.0.3",
"lint-staged": "^13.2.0",
"simple-git-hooks": "^2.8.1",
"tsx": "^3.12.5",
"typescript": "^4.9.5",
"unbuild": "^1.1.2"
"@curev/eslint-config": "^0.5.0",
"@types/node": "^24.0.3",
"@types/pngjs": "^6.0.5",
"bumpp": "^10.1.1",
"eslint": "^9.29.0",
"lint-staged": "^16.1.2",
"simple-git-hooks": "^2.13.0",
"tsdown": "^0.12.8",
"tsx": "^4.20.3",
"typescript": "^5.8.3"
},
"dependencies": {
"maybe-types": "^0.0.3",
"pngjs": "^7.0.0"
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix"
]
}
}
Loading