mirror of
https://github.com/unanmed/ginka-generator.git
synced 2026-05-14 04:41:12 +08:00
feat: app init & new ginka data process
This commit is contained in:
parent
5be9decf95
commit
f8d6160e5f
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ minamo-dataset.json
|
||||
minamo-eval.json
|
||||
datasets
|
||||
*.log
|
||||
app/model/*
|
||||
!app/model/.gitkeep
|
||||
25
README.md
25
README.md
@ -11,12 +11,9 @@ GINKA Model 内部集成了 Minamo Model 用做判别器,与 Ginka Model 对
|
||||
1. 选择楼层,可以是剧情层、战斗层等,但是需要满足下述条件
|
||||
2. 楼层中不应该有闲置怪,不应该在直线上有无间隔连续 3 个以上的怪物,不应该有无法到达的区域,不宜有过多的入口
|
||||
3. 最外面一层围上一圈墙壁(箭头楼层切换除外)
|
||||
4. 将所有的墙壁换成黄墙(数字 1)
|
||||
5. 将所有的血瓶换成红血瓶(数字 31),所有红宝石换成最基础的红宝石(数字 27),蓝宝石换成最基础的蓝宝石(数字 28),绿宝石换成最基础的绿宝石(数字 29),道具全部换为幸运金币(数字 53),剑盾可以当成红蓝宝石看待,删除除此之外的资源(或者换成允许的资源)
|
||||
6. 所有钥匙换成黄钥匙(数字 21),所有门换成黄门(数字 81)
|
||||
7. 所有箭头换成样板原版箭头(数字 91 至 94),所有上下楼梯换成样板原版楼梯(数字 87 和 88)
|
||||
8. 怪物分为三个强度,弱怪,中怪,强怪,弱怪换为绿头怪(数字 201),中怪换成红头怪(数字 202),强怪换成青头怪(数字 203)
|
||||
9. 在 `project` 文件夹下创建 `ginka-config.json` 文件,双击进入编辑,粘贴如下模板:
|
||||
4. 所有箭头换成样板原版箭头(数字 91 至 94),所有上下楼梯换成样板原版楼梯(数字 87 和 88)
|
||||
5. (可选,不改的话会自动按攻防和计算)怪物分为三个强度,弱怪,中怪,强怪,弱怪换为绿头怪(数字 201),中怪换成红头怪(数字 202),强怪换成青头怪(数字 203)
|
||||
6. 在 `project` 文件夹下创建 `ginka-config.json` 文件,双击进入编辑,粘贴如下模板:
|
||||
|
||||
```json
|
||||
{
|
||||
@ -26,11 +23,23 @@ GINKA Model 内部集成了 Minamo Model 用做判别器,与 Ginka Model 对
|
||||
"MT11": [3, 3, 7, 7]
|
||||
}
|
||||
},
|
||||
"mapping": {
|
||||
"redGem": [27],
|
||||
"blueGem": [28],
|
||||
"greenGem": [29],
|
||||
"item": [47, 49, 50, 53],
|
||||
"potion": [31, 32, 33, 34],
|
||||
"key": [21, 22, 23],
|
||||
"door": [81, 82, 83, 85],
|
||||
"wall": [1]
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
```
|
||||
|
||||
其中,`clip` 属性表示你的每张地图的那一部分会被当成数据集,例如填写 `[0, 0, 13, 13]` 就会让坐标为 `(0, 0)`,长宽为 `(13, 13)` 的矩形内容作为数据集。`special` 属性允许你针对单独的某几层设置不同的裁剪方式,例如设置 `MT11` 为 `[3, 3, 7, 7]` 等,如果没有设置默认使用 `defaults` 的裁剪方式。最好保证每个楼层大小一致,不然我还要手动分类。
|
||||
|
||||
10. 在全塔属性中的楼层列表中去除不在数据集内的楼层
|
||||
11. 将 `project` 文件夹打包发给我即可
|
||||
`mapping` 中表示每种图块的图块数字,如果自己添加了一些新的宝石、门、道具等,需要在里面填写
|
||||
|
||||
7. 在全塔属性中的楼层列表中去除不在数据集内的楼层
|
||||
8. 将 `project` 文件夹打包发给我即可
|
||||
|
||||
63
app/backend/app.py
Normal file
63
app/backend/app.py
Normal file
@ -0,0 +1,63 @@
|
||||
import os
|
||||
import torch
|
||||
from flask import Flask, request, jsonify, send_from_directory
|
||||
|
||||
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
||||
|
||||
generator = None
|
||||
|
||||
# ====== Flask部分 ======
|
||||
app = Flask(__name__, static_folder='../frontend/dist', static_url_path='')
|
||||
|
||||
@app.route('/')
|
||||
def serve_index():
|
||||
# 返回 Vue 打包后的 index.html
|
||||
return send_from_directory(app.static_folder, 'index.html')
|
||||
|
||||
@app.route('/generate', methods=['POST'])
|
||||
def generate_map():
|
||||
"""
|
||||
接收请求,调用模型生成地图,返回JSON
|
||||
"""
|
||||
try:
|
||||
# 你可以根据需要从request.json里读取参数
|
||||
params = request.json or {}
|
||||
|
||||
# 假设你的模型输入是随机噪声或固定向量
|
||||
# 下面是示例代码,根据你真实情况修改
|
||||
noise = torch.randn(1, 1024, device=device)
|
||||
with torch.no_grad():
|
||||
output = generator(noise)
|
||||
|
||||
# 假设output是 [B, H, W] 分类结果
|
||||
# 转为CPU,转成Python list
|
||||
map_data = output.argmax(dim=1).squeeze(0).cpu().tolist()
|
||||
|
||||
return jsonify({
|
||||
'status': 'success',
|
||||
'map': map_data
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
'status': 'error',
|
||||
'message': str(e)
|
||||
}), 500
|
||||
|
||||
@app.errorhandler(404)
|
||||
def not_found(e):
|
||||
# 如果找不到文件,返回前端index.html(前端路由支持)
|
||||
return send_from_directory(app.static_folder, 'index.html')
|
||||
|
||||
# ====== 启动 ======
|
||||
if __name__ == '__main__':
|
||||
# 检查模型
|
||||
if os.path.exists("../model/ginka"):
|
||||
from ..model.ginka.model import GinkaModel
|
||||
generator = GinkaModel()
|
||||
generator.to(device)
|
||||
generator.eval()
|
||||
state = torch.load("../model/ginka.pth", map_location=device)
|
||||
generator.load_state_dict(state["model_state"])
|
||||
app.run(host='0.0.0.0', port=3444, debug=True)
|
||||
else:
|
||||
print("未找到模型定义,请先下载模型并命名为 ginka,放置在 model 文件夹中!")
|
||||
24
app/frontend/.gitignore
vendored
Normal file
24
app/frontend/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
3
app/frontend/.vscode/extensions.json
vendored
Normal file
3
app/frontend/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["Vue.volar"]
|
||||
}
|
||||
5
app/frontend/README.md
Normal file
5
app/frontend/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Vue 3 + TypeScript + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
|
||||
13
app/frontend/index.html
Normal file
13
app/frontend/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Vue + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
25
app/frontend/package.json
Normal file
25
app/frontend/package.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc -b && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ant-design/icons-vue": "^7.0.1",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"ant-design-vue": "^4.2.6",
|
||||
"lodash-es": "^4.17.21",
|
||||
"vue": "^3.5.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.2",
|
||||
"@vue/tsconfig": "^0.7.0",
|
||||
"typescript": "~5.7.2",
|
||||
"vite": "^6.3.1",
|
||||
"vue-tsc": "^2.2.8"
|
||||
}
|
||||
}
|
||||
1150
app/frontend/pnpm-lock.yaml
Normal file
1150
app/frontend/pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load Diff
2
app/frontend/pnpm-workspace.yaml
Normal file
2
app/frontend/pnpm-workspace.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
onlyBuiltDependencies:
|
||||
- core-js
|
||||
1
app/frontend/public/vite.svg
Normal file
1
app/frontend/public/vite.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
30
app/frontend/src/App.vue
Normal file
30
app/frontend/src/App.vue
Normal file
@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import HelloWorld from './components/HelloWorld.vue'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<a href="https://vite.dev" target="_blank">
|
||||
<img src="/vite.svg" class="logo" alt="Vite logo" />
|
||||
</a>
|
||||
<a href="https://vuejs.org/" target="_blank">
|
||||
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
|
||||
</a>
|
||||
</div>
|
||||
<HelloWorld msg="Vite + Vue" />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.vue:hover {
|
||||
filter: drop-shadow(0 0 2em #42b883aa);
|
||||
}
|
||||
</style>
|
||||
1
app/frontend/src/assets/vue.svg
Normal file
1
app/frontend/src/assets/vue.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 496 B |
41
app/frontend/src/components/HelloWorld.vue
Normal file
41
app/frontend/src/components/HelloWorld.vue
Normal file
@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineProps<{ msg: string }>()
|
||||
|
||||
const count = ref(0)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>{{ msg }}</h1>
|
||||
|
||||
<div class="card">
|
||||
<button type="button" @click="count++">count is {{ count }}</button>
|
||||
<p>
|
||||
Edit
|
||||
<code>components/HelloWorld.vue</code> to test HMR
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Check out
|
||||
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
|
||||
>create-vue</a
|
||||
>, the official Vue + Vite starter
|
||||
</p>
|
||||
<p>
|
||||
Learn more about IDE Support for Vue in the
|
||||
<a
|
||||
href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support"
|
||||
target="_blank"
|
||||
>Vue Docs Scaling up Guide</a
|
||||
>.
|
||||
</p>
|
||||
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
||||
</style>
|
||||
5
app/frontend/src/main.ts
Normal file
5
app/frontend/src/main.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { createApp } from 'vue'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
79
app/frontend/src/style.css
Normal file
79
app/frontend/src/style.css
Normal file
@ -0,0 +1,79 @@
|
||||
:root {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
1
app/frontend/src/vite-env.d.ts
vendored
Normal file
1
app/frontend/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
14
app/frontend/tsconfig.app.json
Normal file
14
app/frontend/tsconfig.app.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
|
||||
}
|
||||
7
app/frontend/tsconfig.json
Normal file
7
app/frontend/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
24
app/frontend/tsconfig.node.json
Normal file
24
app/frontend/tsconfig.node.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
12
app/frontend/vite.config.ts
Normal file
12
app/frontend/vite.config.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/generate': 'http://localhost:3444'
|
||||
}
|
||||
}
|
||||
});
|
||||
0
app/model/.gitkeep
Normal file
0
app/model/.gitkeep
Normal file
@ -1,3 +1,5 @@
|
||||
import { GinkaConfig } from './types';
|
||||
|
||||
const numMap: Record<number, number> = {
|
||||
0: 0, // 空地
|
||||
1: 1, // 墙壁
|
||||
@ -16,40 +18,10 @@ const numMap: Record<number, number> = {
|
||||
93: 11, // 箭头
|
||||
94: 11, // 箭头
|
||||
53: 12, // 道具
|
||||
29: 13, // 绿宝石
|
||||
29: 13 // 绿宝石
|
||||
};
|
||||
|
||||
const apeiriaMap: Record<number, number> = {
|
||||
0: 0, // 空地
|
||||
1: 1, // 墙壁
|
||||
224: 1, // 吸血鬼,视为墙壁
|
||||
21: 2, // 黄钥匙
|
||||
22: 2, // 蓝钥匙
|
||||
23: 2, // 红钥匙
|
||||
27: 3, // 红宝石
|
||||
28: 4, // 蓝宝石
|
||||
29: 13, // 绿宝石
|
||||
31: 5, // 红血瓶
|
||||
32: 5, // 蓝血瓶
|
||||
33: 5, // 绿血瓶
|
||||
34: 5, // 黄血瓶
|
||||
81: 6, // 门
|
||||
201: 7, // 弱怪
|
||||
202: 8, // 中怪
|
||||
203: 9, // 强怪
|
||||
87: 10, // 楼梯
|
||||
88: 10, // 楼梯
|
||||
161: 11, // 箭头
|
||||
162: 11, // 箭头
|
||||
163: 11, // 箭头
|
||||
164: 11, // 箭头
|
||||
53: 12, // 幸运金币
|
||||
50: 12, // 飞
|
||||
49: 12, // 炸
|
||||
47: 12 // 破
|
||||
};
|
||||
|
||||
export interface ApeiriaEnemy {
|
||||
export interface Enemy {
|
||||
hp: number;
|
||||
atk: number;
|
||||
def: number;
|
||||
@ -58,95 +30,81 @@ export interface ApeiriaEnemy {
|
||||
function convert(
|
||||
map: number[][],
|
||||
[x, y, w, h]: [number, number, number, number],
|
||||
name: string,
|
||||
floorId: string,
|
||||
numMap: Record<number, number>
|
||||
config: GinkaConfig,
|
||||
enemyMap: Record<number, Enemy>
|
||||
) {
|
||||
const clipped: number[][] = [];
|
||||
|
||||
// 1. 裁剪
|
||||
for (let nx = x; nx < x + w; nx++) {
|
||||
const row: number[] = [];
|
||||
for (let ny = y; ny < y + h; ny++) {
|
||||
const num = numMap[map[nx][ny]];
|
||||
if (num === void 0) {
|
||||
console.log(
|
||||
`⚠️ 魔塔 ${name} 的楼层 ${floorId} 中出现未知图块类型:${map[nx][ny]}`
|
||||
);
|
||||
}
|
||||
row.push(num ?? 0);
|
||||
row.push(map[ny][nx]);
|
||||
}
|
||||
clipped.push(row);
|
||||
}
|
||||
|
||||
// 2. 转换怪物
|
||||
const enemySet = new Set<Enemy>();
|
||||
for (let nx = 0; nx < w; nx++) {
|
||||
for (let ny = 0; ny < h; ny++) {
|
||||
const tile = clipped[ny][nx];
|
||||
if (tile === 201 || tile === 202 || tile === 203) continue;
|
||||
const enemy = enemyMap[tile];
|
||||
if (!enemy) continue;
|
||||
enemySet.add(enemy);
|
||||
}
|
||||
}
|
||||
const attrs = [...enemySet].map(v => (v.atk + v.def) * v.hp);
|
||||
const maxAttr = Math.max(...attrs);
|
||||
const minAttr = Math.min(...attrs);
|
||||
const delta = maxAttr - minAttr;
|
||||
for (let ny = 0; ny < w; ny++) {
|
||||
for (let nx = 0; nx < h; nx++) {
|
||||
const tile = clipped[ny][nx];
|
||||
if (tile === 201 || tile === 202 || tile === 203) continue;
|
||||
const enemy = enemyMap[tile];
|
||||
if (!enemy) continue;
|
||||
// 替换为弱怪/中怪/强怪
|
||||
const attr = (enemy.atk + enemy.def) * enemy.hp;
|
||||
const ad = attr - minAttr;
|
||||
if (ad < delta / 3) {
|
||||
clipped[ny][nx] = 7;
|
||||
} else if (ad < (delta * 2) / 3) {
|
||||
clipped[ny][nx] = 8;
|
||||
} else {
|
||||
clipped[ny][nx] = 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 转换一般图块
|
||||
const mapping: Record<number, number> = {};
|
||||
config.mapping.wall.forEach(v => (mapping[v] = 1));
|
||||
config.mapping.key.forEach(v => (mapping[v] = 2));
|
||||
config.mapping.redGem.forEach(v => (mapping[v] = 3));
|
||||
config.mapping.blueGem.forEach(v => (mapping[v] = 4));
|
||||
config.mapping.potion.forEach(v => (mapping[v] = 5));
|
||||
config.mapping.door.forEach(v => (mapping[v] = 6));
|
||||
config.mapping.item.forEach(v => (mapping[v] = 12));
|
||||
config.mapping.greenGem.forEach(v => (mapping[v] = 13));
|
||||
for (let nx = 0; nx < w; nx++) {
|
||||
for (let ny = 0; ny < h; ny++) {
|
||||
const tile = clipped[ny][nx];
|
||||
if (mapping[tile]) clipped[ny][nx] = mapping[tile];
|
||||
else if (numMap[tile]) clipped[ny][nx] = numMap[tile];
|
||||
else clipped[ny][nx] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return clipped;
|
||||
}
|
||||
|
||||
function convertApeiriaEnemy(
|
||||
map: number[][],
|
||||
enemyMap: Record<number, ApeiriaEnemy>
|
||||
) {
|
||||
const width = map[0].length;
|
||||
const height = map.length;
|
||||
const enemy = new Set<ApeiriaEnemy>();
|
||||
for (let ny = 0; ny < height; ny++) {
|
||||
for (let nx = 0; nx < width; nx++) {
|
||||
const tile = map[ny][nx];
|
||||
if (tile > 200 && tile <= 280 && tile !== 224) {
|
||||
// 这些是怪物
|
||||
if (enemyMap[tile]) enemy.add(enemyMap[tile]);
|
||||
}
|
||||
}
|
||||
}
|
||||
const attrs = [...enemy].map(v => (v.atk + v.def) * v.hp);
|
||||
const maxAttr = Math.max(...attrs);
|
||||
const minAttr = Math.min(...attrs);
|
||||
const delta = maxAttr - minAttr;
|
||||
for (let ny = 0; ny < height; ny++) {
|
||||
for (let nx = 0; nx < width; nx++) {
|
||||
const tile = map[ny][nx];
|
||||
if (tile > 200 && tile <= 280 && tile !== 224) {
|
||||
// 这些是怪物
|
||||
if (enemyMap[tile]) {
|
||||
// 替换为弱怪/中怪/强怪
|
||||
const enemy = enemyMap[tile];
|
||||
const attr = (enemy.atk + enemy.def) * enemy.hp;
|
||||
const ad = attr - minAttr;
|
||||
if (ad < delta / 3) {
|
||||
map[ny][nx] = 201;
|
||||
} else if (ad < (delta * 2) / 3) {
|
||||
map[ny][nx] = 202;
|
||||
} else {
|
||||
map[ny][nx] = 203;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
export function convertFloor(
|
||||
map: number[][],
|
||||
clip: [number, number, number, number],
|
||||
name: string,
|
||||
floorId: string
|
||||
config: GinkaConfig,
|
||||
enemyMap: Record<number, Enemy>
|
||||
) {
|
||||
return convert(map, clip, name, floorId, numMap);
|
||||
}
|
||||
|
||||
export function convertApeiriaMap(
|
||||
map: number[][],
|
||||
clip: [number, number, number, number],
|
||||
name: string,
|
||||
floorId: string,
|
||||
enemyMap: Record<number, ApeiriaEnemy>
|
||||
) {
|
||||
return convert(
|
||||
convertApeiriaEnemy(map, enemyMap),
|
||||
clip,
|
||||
name,
|
||||
floorId,
|
||||
apeiriaMap
|
||||
);
|
||||
return convert(map, clip, config, enemyMap);
|
||||
}
|
||||
|
||||
@ -14,6 +14,16 @@ export interface TowerInfo {
|
||||
|
||||
export interface GinkaConfig extends BaseConfig {
|
||||
data: Record<string, string[]>;
|
||||
mapping: {
|
||||
redGem: number[];
|
||||
blueGem: number[];
|
||||
greenGem: number[];
|
||||
item: number[];
|
||||
potion: number[];
|
||||
key: number[];
|
||||
door: number[];
|
||||
wall: number[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface GinkaTrainData {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { readFile } from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
import { BaseConfig, TowerInfo } from './types';
|
||||
import { convertApeiriaMap, convertFloor } from './floor';
|
||||
import { BaseConfig, GinkaConfig, TowerInfo } from './types';
|
||||
import { convertFloor } from './floor';
|
||||
|
||||
export interface DatasetMergable<T> {
|
||||
datasetId: number;
|
||||
@ -118,17 +118,13 @@ export async function getAllFloors(...info: TowerInfo[]) {
|
||||
// 裁剪地图
|
||||
const { clip } = tower.config;
|
||||
const area = clip.special[id] ?? clip.defaults;
|
||||
if (tower.name === 'Apeiria') {
|
||||
return convertApeiriaMap(
|
||||
|
||||
return convertFloor(
|
||||
map,
|
||||
area,
|
||||
tower.name,
|
||||
id,
|
||||
tower.config as GinkaConfig,
|
||||
enemyNumMap
|
||||
);
|
||||
} else {
|
||||
return convertFloor(map, area, tower.name, id);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user