Commit e7976819 authored by nanahira's avatar nanahira

first

parent b2546969
Pipeline #23982 passed with stages
in 3 minutes and 39 seconds
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
.git*
Dockerfile
.dockerignore
/tests
webpack.config.js
dist/*
build/*
*.js
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir : __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
.build-image:
stage: build
script:
- docker build --pull -t $TARGET_IMAGE .
- docker push $TARGET_IMAGE
build-x86:
extends: .build-image
tags:
- docker
variables:
TARGET_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
build-arm:
extends: .build-image
tags:
- docker-arm
variables:
TARGET_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
.deploy:
stage: deploy
tags:
- docker
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
- docker manifest create $TARGET_IMAGE --amend $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86 --amend
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
- docker manifest push $TARGET_IMAGE
deploy_latest:
extends: .deploy
variables:
TARGET_IMAGE: $CI_REGISTRY_IMAGE:latest
only:
- master
deploy_branch:
extends: .deploy
variables:
TARGET_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
/install-npm.sh
.git*
/data
/output
/config.yaml
.idea
.dockerignore
Dockerfile
/src
/coverage
/tests
/dist/tests
{
"singleQuote": true,
"trailingComma": "all"
}
\ No newline at end of file
FROM node:lts-bookworm-slim as base
LABEL Author="Nanahira <nanahira@momobako.com>"
RUN apt update && apt -y install python3 build-essential && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/log/*
WORKDIR /usr/src/app
COPY ./package*.json ./
FROM base as builder
RUN npm ci && npm cache clean --force
COPY . ./
RUN npm run build
FROM base
ENV NODE_ENV production
RUN npm ci && npm cache clean --force
COPY --from=builder /usr/src/app/dist ./dist
CMD [ "npm", "start" ]
The MIT License (MIT)
Copyright (c) 2021 Nanahira
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
import fs from 'fs';
import initSqlJs from 'sql.js';
import SQL from 'sql.js';
const systemStrings = new Map<number, string>();
const setcodeStrings = new Map<number, string>();
const stringsMap = {
system: systemStrings,
setname: setcodeStrings,
} as const;
const attrOffset = 1010;
const raceOffset = 1020;
const typeOffset = 1050;
function getStringValueByMysticalNumber(offset: number, num: number) {
const stringInfos: string[] = [];
for (let i = 0; i < 32; i++) {
if (num & (1 << i)) {
const index = offset + i;
const entry = systemStrings.get(index);
if (entry) {
stringInfos.push(entry);
}
}
}
return stringInfos;
}
function getSets(num: number) {
const possibleSetValues = [
num & 0xffff,
(num >>> 16) & 0xffff,
// (num >>> 32) & 0xffff,
// (num >>> 48) & 0xffff,
].filter(x => x !== 0);
// console.error(possibleSetValues)
return possibleSetValues.flatMap((set) => {
const baseCode = set & 0xfff;
if (!baseCode) return [];
const baseSet = setcodeStrings.get(baseCode);
if (!baseSet) return [];
const extraCode = set & 0xf000;
if (!extraCode) return [baseSet];
// every bit combination of extra code is a possible extra set
const possibleExtraCodes: number[] = [];
for (let i = 1; i < 16; i++) {
const extraCode = baseCode | (i << 12);
if ((extraCode & set) === extraCode) {
possibleExtraCodes.push(extraCode);
}
}
// console.error(possibleExtraCodes);
return [
baseSet,
...possibleExtraCodes.map((extraCode) => {
const extraSet = setcodeStrings.get(extraCode);
if (!extraSet) return;
return extraSet;
}).filter((s) => s)
]
})
}
async function loadString(path: string) {
const stringsFile = await fs.promises.readFile(path, 'utf8');
const stringsLines = stringsFile.split('\n');
for(const line of stringsLines) {
const [type, idStr, string] = line.split(' ');
if (!type.startsWith('!')) continue;
const map = stringsMap[type.slice(1)];
if (!map) continue;
const id = parseInt(idStr);
map.set(id, string.split('\t')[0]);
}
}
async function querySQL<T = any>(db: SQL.Database, sql: string, params: any = {}) {
const statement = db.prepare(sql);
statement.bind(params);
const results: T[] = [];
while (statement.step()) {
results.push(statement.getAsObject() as any);
}
statement.free();
return results;
}
interface YGOProCardLike {
id: number;
name: string;
desc: string;
ot: number;
alias: number;
setcode: number;
type: number;
atk: number;
def: number;
level: number;
race: number;
attribute: number;
category: number;
}
interface YGOProCard extends YGOProCardLike {
displayLevel: number;
cardLScale: number;
cardRScale: number;
displayAtk: string;
displayDef: string;
displayRace: string[];
displayAttribute: string[];
displayType: string[];
linkMarkers: string[];
sets: string[];
overallString: string;
}
const ygoproConstants = {
TYPES: {
TYPE_MONSTER: 1,
TYPE_SPELL: 2,
TYPE_TRAP: 4,
TYPE_NORMAL: 16,
TYPE_EFFECT: 32,
TYPE_FUSION: 64,
TYPE_RITUAL: 128,
TYPE_TRAPMONSTER: 256,
TYPE_SPIRIT: 512,
TYPE_UNION: 1024,
TYPE_DUAL: 2048,
TYPE_TUNER: 4096,
TYPE_SYNCHRO: 8192,
TYPE_TOKEN: 16384,
TYPE_QUICKPLAY: 65536,
TYPE_CONTINUOUS: 131072,
TYPE_EQUIP: 262144,
TYPE_FIELD: 524288,
TYPE_COUNTER: 1048576,
TYPE_FLIP: 2097152,
TYPE_TOON: 4194304,
TYPE_XYZ: 8388608,
TYPE_PENDULUM: 16777216,
TYPE_SPSUMMON: 33554432,
TYPE_LINK: 67108864,
},
LINK_MARKERS: {
LINK_MARKER_BOTTOM_LEFT: 1,
LINK_MARKER_BOTTOM: 2,
LINK_MARKER_BOTTOM_RIGHT: 4,
LINK_MARKER_LEFT: 8,
LINK_MARKER_RIGHT: 32,
LINK_MARKER_TOP_LEFT: 64,
LINK_MARKER_TOP: 128,
LINK_MARKER_TOP_RIGHT: 256,
},
};
function isType(value: number, type: keyof typeof ygoproConstants.TYPES) {
return !!(value & ygoproConstants.TYPES[type]);
}
function toDisplayAdValue(value: number) {
if (value < 0) {
return '?';
}
return value.toString();
}
function getMetaText(data: Partial<YGOProCard>) {
const lines: string[] = [];
const isMonster = isType(data.type, 'TYPE_MONSTER');
let typeString = `[${data.displayType.join('|')}]`;
if (isMonster) {
typeString += ` ${data.displayRace[0]}/${data.displayAttribute[0]}`;
}
lines.push(typeString);
if (isMonster) {
const starString = isType(data.type, 'TYPE_XYZ')
? '\u2606'
: isType(data.type, 'TYPE_LINK')
? 'LINK-'
: '\u2605';
let monsterStatus = `[${starString}${data.displayLevel}] ${data.displayAtk}/${data.displayDef}`;
if (isType(data.type, 'TYPE_PENDULUM')) {
monsterStatus += ` ${data.cardLScale}/${data.cardRScale}`;
}
if (isType(data.type, 'TYPE_LINK')) {
monsterStatus += ` ${data.linkMarkers.join('')}`;
}
lines.push(monsterStatus);
}
return lines.join(' ');
}
function formatCard(data: YGOProCardLike): YGOProCard {
const result: Partial<YGOProCard> = {
...data,
displayLevel: data.level & 0xff,
cardLScale: (data.level >>> 6) & 0xff,
cardRScale: (data.level >>> 4) & 0xff,
displayAtk: toDisplayAdValue(data.atk),
displayRace: getStringValueByMysticalNumber(raceOffset, data.race),
displayAttribute: getStringValueByMysticalNumber(attrOffset, data.attribute),
displayType: getStringValueByMysticalNumber(typeOffset, data.type),
sets: getSets(data.setcode),
}
if (!isType(data.type, 'TYPE_LINK')) {
result.displayDef = toDisplayAdValue(data.def);
} else {
// result.name+="[LINK-" + cardLevel + "]";
// result.name += " " + (result.atk < 0 ? "?" : result.atk) + "/- ";
result.linkMarkers = [];
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_TOP_LEFT)
result.linkMarkers.push('[↖]');
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_TOP)
result.linkMarkers.push('[↑]');
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_TOP_RIGHT)
result.linkMarkers.push('[↗]');
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_LEFT)
result.linkMarkers.push('[←]');
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_RIGHT)
result.linkMarkers.push('[→]');
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_BOTTOM_LEFT)
result.linkMarkers.push('[↙]');
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_BOTTOM)
result.linkMarkers.push('[↓]');
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_BOTTOM_RIGHT)
result.linkMarkers.push('[↘]');
result.displayDef = '-'
}
result.overallString = getMetaText(result);
return result as YGOProCard;
}
async function main() {
await Promise.all(
process.argv.slice(3).map((path) => loadString(path))
)
const SQL = await initSqlJs();
const dbBuffer = await fs.promises.readFile(process.argv[2]);
const db = new SQL.Database(dbBuffer);
const cards = await querySQL<YGOProCardLike>(db, 'select datas.*,texts.name,texts.desc from datas,texts where datas.id = texts.id and datas.type & 0x4000 = 0 and (datas.alias = 0 or datas.id - datas.alias > 10 or datas.id - datas.alias < -10)');
const formattedCards = cards.map(formatCard);
console.log(JSON.stringify(formattedCards, null, 2));
process.exit(0);
}
main()
#!/bin/bash
npm i --save-exact --save-dev eslint@8.22.0
npm install --save-dev \
@types/node \
typescript \
'@typescript-eslint/eslint-plugin@^5.0.0' \
'@typescript-eslint/parser@^5.0.0 '\
'eslint-config-prettier@^8.3.0' \
'eslint-plugin-prettier@^5.0.0' \
prettier \
jest \
@types/jest \
ts-jest \
rimraf
This diff is collapsed.
{
"name": "myproject",
"description": "myproject-desc",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"lint": "eslint --fix .",
"build": "rimraf dist && tsc",
"test": "jest --passWithNoTests",
"start": "node dist/index.js"
},
"repository": {
"type": "git",
"url": "https://code.mycard.moe/3rdeye/myproject.git"
},
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"keywords": [],
"bugs": {
"url": "https://code.mycard.moe/3rdeye/myproject/issues"
},
"homepage": "https://code.mycard.moe/3rdeye/myproject",
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "tests",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"dependencies": {
"sql.js": "^1.8.0"
},
"devDependencies": {
"@types/jest": "^29.5.8",
"@types/node": "^20.9.0",
"@types/sql.js": "^1.4.9",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "8.22.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
}
}
describe('Sample test.', () => {
it('should pass', () => {
expect(true).toBe(true);
});
});
{
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"target": "es2021",
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"sourceMap": true
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts",
"src/**/*.ts",
"test/**/*.ts",
"tests/**/*.ts"
]
}
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