dsh-game-material-master 0.4.0 → 0.7.0
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/README.en.md +101 -12
- package/README.md +86 -11
- package/lib/ark.js +1 -1
- package/lib/{tilemedia.js → bitmap.js} +21 -3
- package/lib/client.js +3295 -158
- package/lib/config.js +70 -2
- package/lib/customimage.js +518 -0
- package/lib/imagegen.js +15 -15
- package/lib/imageprovider.js +151 -0
- package/lib/index.js +305 -9
- package/lib/jsonio.js +24 -3
- package/lib/links.js +11 -2
- package/lib/mapauto.js +126 -0
- package/lib/mapdoc.js +617 -0
- package/lib/mapexport.js +188 -0
- package/lib/mapgen.js +1591 -0
- package/lib/mapgeom.js +320 -0
- package/lib/maprender.js +484 -0
- package/lib/mapsample.js +36 -0
- package/lib/mapsamplegen.js +760 -0
- package/lib/maptiles.js +253 -0
- package/lib/media.js +34 -0
- package/lib/pipeline.js +197 -15
- package/lib/rigexport.js +29 -98
- package/lib/riggen.js +34 -30
- package/lib/rigpath.js +47 -10
- package/lib/rigpreview.js +91 -84
- package/lib/rigsemantics.js +4 -4
- package/lib/rigvalidate.js +72 -14
- package/lib/spine.js +147 -80
- package/lib/store.js +12 -3
- package/lib/tilegen.js +7 -11
- package/lib/tilegeom.js +1 -1
- package/lib/tools.js +253 -29
- package/lib/wire.js +198 -3
- package/lib/zip.js +127 -0
- package/package.json +10 -4
package/lib/client.js
CHANGED
|
@@ -98,6 +98,7 @@ window.__ModuleLoader__.load({
|
|
|
98
98
|
"已创建新项目": "New project created",
|
|
99
99
|
"确定删除项目「{n0}」?项目目录会被整个移除,无法撤销。": "Delete project \"{n0}\"? The whole project directory is removed, and this cannot be undone.",
|
|
100
100
|
"新的项目名": "New project name",
|
|
101
|
+
"新项目的名字": "Name for the new project",
|
|
101
102
|
"读取文件失败": "Failed to read file",
|
|
102
103
|
"已上传源图:{n0}": "Source image uploaded: {n0}",
|
|
103
104
|
"提示词已保存": "Prompt saved",
|
|
@@ -126,6 +127,23 @@ window.__ModuleLoader__.load({
|
|
|
126
127
|
"更换源图": "Replace source image",
|
|
127
128
|
"刷新状态": "Refresh status",
|
|
128
129
|
"在访达中打开项目目录": "Open the project directory in Finder",
|
|
130
|
+
"保存全部图片(zip)": "Save all images (zip)",
|
|
131
|
+
"正在打包全部图片…": "Packing all images…",
|
|
132
|
+
"已打包 {n0} 张图片": "Packed {n0} images",
|
|
133
|
+
"已打包 {n0} 张图片(另有 {n1} 张读不到,已跳过)": "Packed {n0} images ({n1} unreadable files were skipped)",
|
|
134
|
+
"选择本地视频": "Choose a local video",
|
|
135
|
+
"正在导入本地视频…": "Importing the local video…",
|
|
136
|
+
"已选用本地视频,正在抽候选帧并切出八个方向…": "Local video selected - extracting candidate frames and cutting the eight directions…",
|
|
137
|
+
"已选用本地视频(抽帧没有自动开始,点「抽取候选帧」即可)": "Local video selected (extraction did not start automatically - click \"Extract candidate frames\")",
|
|
138
|
+
"已选用「{n0}」的本地视频,接着到第 3 步抽取序列帧": "Local video selected for \"{n0}\" - extract the sequence frames in step 3",
|
|
139
|
+
"本地视频:{n0}(不花远程调用)": "Local video: {n0} (no remote call)",
|
|
140
|
+
"保存条带": "Save strip",
|
|
141
|
+
"保存视频": "Save video",
|
|
142
|
+
"保存预览带": "Save preview strip",
|
|
143
|
+
"手上已经有这样一段视频(自己电脑上的文件)时,点「选择本地视频」直接用它即可,不必走远程生成。": "If you already have such a video as a file on this computer, click \"Choose a local video\" and use it directly - no remote generation needed.",
|
|
144
|
+
"某一个方向已经有现成的行走视频(自己电脑上的文件)时,点那一格的「选择本地视频」直接用它,不必走远程生成。": "If you already have a walking video for a direction as a file on this computer, click \"Choose a local video\" in that cell and use it directly - no remote generation needed.",
|
|
145
|
+
"用自己电脑上的一段原地转圈视频(绿幕)顶替远程生成;导入后会自动抽候选帧并切出八个方向": "Use a chroma-key video of the character turning in place from this computer instead of remote generation; after the import the candidate frames are extracted and the eight directions are cut out automatically",
|
|
146
|
+
"用自己电脑上的一段「固定镜头 + 原地走」视频顶替这一方向的远程生成;之后照旧到第 3 步抽帧": "Use a fixed-camera walking-in-place video from this computer instead of remote generation for this direction; frames are still extracted in step 3",
|
|
129
147
|
"先生成一段「角色原地匀速转一整圈」的绿幕视频,再按时间截出八个方向的帧;下面时间轴上的八个圆圈就是各自的截帧位置,拖动即可改。": "First generate a chroma-key video of the character turning a full circle in place at a constant speed, then cut frames for the eight directions by time. The eight circles on the timeline below mark each direction's frame position; drag them to change it.",
|
|
130
148
|
"转圈截帧": "Turn-frame capture",
|
|
131
149
|
"先生成一段「原地匀速转一整圈」的视频,再按时间截出八个方向(默认,一致性最好)": "Generate one video of a full turn in place at a constant speed, then cut the eight directions from it by time (default, best consistency)",
|
|
@@ -373,6 +391,7 @@ window.__ModuleLoader__.load({
|
|
|
373
391
|
"已取消通过": "Approval removed",
|
|
374
392
|
"已标记通过": "Marked as approved",
|
|
375
393
|
"下载 PNG": "Download PNG",
|
|
394
|
+
"下载原图": "Download original",
|
|
376
395
|
"已重新生成": "Regenerated",
|
|
377
396
|
"正在重新生成第 {n0} 张…": "Regenerating image {n0}…",
|
|
378
397
|
"删除": "Delete",
|
|
@@ -497,6 +516,7 @@ window.__ModuleLoader__.load({
|
|
|
497
516
|
"取消隐藏": "Unhide",
|
|
498
517
|
"隐藏": "Hide",
|
|
499
518
|
"已更新「{n0}」的语义": "Updated semantics for \"{n0}\"",
|
|
519
|
+
"语义校验失败": "Semantics validation failed",
|
|
500
520
|
"{n0}{n1}": "{n0}{n1}",
|
|
501
521
|
"近端": "proximal",
|
|
502
522
|
"远端": "distal",
|
|
@@ -752,6 +772,9 @@ window.__ModuleLoader__.load({
|
|
|
752
772
|
"已新建骨骼动画任务": "Skeletal animation job created",
|
|
753
773
|
"删除任务「{n0}」?产物文件会一并删除。": "Delete job \"{n0}\"? Its output files will be deleted as well.",
|
|
754
774
|
"新的任务名": "New job name",
|
|
775
|
+
"新图片任务的名字": "Name for the new image job",
|
|
776
|
+
"新序列帧任务的名字": "Name for the new sequence job",
|
|
777
|
+
"新骨骼动画任务的名字": "Name for the new skeletal animation job",
|
|
755
778
|
"已重命名": "Renamed",
|
|
756
779
|
"已上传参考图:{n0}": "Reference image uploaded: {n0}",
|
|
757
780
|
"已上传 {n0} 个部件(文件名即部件名)": "Uploaded {n0} parts (the file name is used as the part name)",
|
|
@@ -851,7 +874,40 @@ window.__ModuleLoader__.load({
|
|
|
851
874
|
"导入 DragonBones:把 export/dragonbones/skeleton_ske.json 与 atlas/skeleton_tex.json、atlas/skeleton.png 放同一目录后加载 .json 数据与纹理。": "Importing into DragonBones: put export/dragonbones/skeleton_ske.json in the same folder as atlas/skeleton_tex.json and atlas/skeleton.png, then load the .json data and textures.",
|
|
852
875
|
"正在载入配置…": "Loading configuration…",
|
|
853
876
|
"配置已保存": "Configuration saved",
|
|
854
|
-
"
|
|
877
|
+
"配置生图 / 生视频的模型与整条流水线的默认参数。Key 只保存在本机 DSH 数据目录下的 game-material-master/config.json(真实路径见文末「数据位置」),界面里始终脱敏显示。": "Configure the image/video models and the default parameters for the whole pipeline. Keys are stored only in game-material-master/config.json under your local DSH data directory (see \"Data location\" at the end for the real path) and are always masked in the UI.",
|
|
878
|
+
"生图后端": "Image backend",
|
|
879
|
+
"八方向图、图片生成、骨骼动画、45°地图地块的生图都走这里选的后端;图生视频(MiniMax)不受影响。": "Sprite sheets, image generation, rigged animation and 45° map tiles all generate images through the backend selected here; image-to-video (MiniMax) is unaffected.",
|
|
880
|
+
"当前使用": "In use",
|
|
881
|
+
"火山方舟 Seedream(云端,开箱即用)": "Volcengine Ark Seedream (cloud, works out of the box)",
|
|
882
|
+
"自定义生图模型(OpenAI / ComfyUI / SD WebUI)": "Custom image model (OpenAI / ComfyUI / SD WebUI)",
|
|
883
|
+
"当前生效:{n0}": "Currently active: {n0}",
|
|
884
|
+
"还不能开跑:{n0}": "Not ready yet: {n0}",
|
|
885
|
+
"后端已就绪,可以开跑。": "The backend is ready to use.",
|
|
886
|
+
"自定义生图模型": "Custom image model",
|
|
887
|
+
"填「主机根地址」即可,具体端点由插件按协议拼;本地服务通常不需要 API Key。": "Just the host root URL — the plugin appends the protocol-specific endpoint. Local servers usually need no API key.",
|
|
888
|
+
"协议": "Protocol",
|
|
889
|
+
"模型名(SD WebUI 忽略,模型由服务端决定)": "Model name (ignored by SD WebUI; the server decides the model)",
|
|
890
|
+
"模型名": "Model name",
|
|
891
|
+
"可不填,由工作流决定": "Optional; the workflow decides",
|
|
892
|
+
"输出尺寸(宽x高)": "Output size (width x height)",
|
|
893
|
+
"请求端点:{n0}": "Endpoint: {n0}",
|
|
894
|
+
"(未配置,本地服务可以留空)": "(not configured; local servers can leave it blank)",
|
|
895
|
+
"粘贴 API Key(A1111 的 user:pass 也认)": "Paste the API key (A1111's user:pass is also accepted)",
|
|
896
|
+
"自定义后端 Key 已保存": "Custom backend key saved",
|
|
897
|
+
"已清除自定义后端 Key": "Custom backend key cleared",
|
|
898
|
+
"负面提示词": "Negative prompt",
|
|
899
|
+
"走 {{negative_prompt}} 占位符": "Filled via the {{negative_prompt}} placeholder",
|
|
900
|
+
"采样步数": "Sampling steps",
|
|
901
|
+
"CFG / 引导强度": "CFG / guidance scale",
|
|
902
|
+
"采样器": "Sampler",
|
|
903
|
+
"图生图重绘强度(0~1)": "Image-to-image denoising strength (0–1)",
|
|
904
|
+
"随机种子(-1 = 每次随机)": "Seed (-1 = random each time)",
|
|
905
|
+
"请求超时(毫秒,本地模型建议给足)": "Request timeout (ms; give local models plenty)",
|
|
906
|
+
"工作流(在 ComfyUI 里点「导出(API)」,把那份 JSON 整段粘贴)。可用占位符:{{prompt}} {{negative_prompt}} {{width}} {{height}} {{seed}} {{steps}} {{cfg}} {{sampler}} {{denoising}} {{model}} {{image}};一个都不写就原样跑你保存的工作流。": "Workflow (click \"Export (API)\" in ComfyUI and paste the whole JSON). Placeholders: {{prompt}} {{negative_prompt}} {{width}} {{height}} {{seed}} {{steps}} {{cfg}} {{sampler}} {{denoising}} {{model}} {{image}}. With no placeholder at all, your saved workflow runs as-is.",
|
|
907
|
+
"工作流已保存": "Workflow saved",
|
|
908
|
+
"保存工作流": "Save workflow",
|
|
909
|
+
"清空": "Clear",
|
|
910
|
+
"测试连接(会真实生成 1 张测试图,产生少量费用)": "Test connection (generates one real test image, small charge)",
|
|
855
911
|
"火山方舟(生图)": "Volcengine Ark (image generation)",
|
|
856
912
|
"ffmpeg 可用:{n0}": "ffmpeg available: {n0}",
|
|
857
913
|
"ffmpeg 不可用:{n0}": "ffmpeg unavailable: {n0}",
|
|
@@ -1033,11 +1089,172 @@ window.__ModuleLoader__.load({
|
|
|
1033
1089
|
"隐藏不用的功能。隐藏后界面里不再出现它的页签与侧栏菜单项,对话里的 AI 也无法调用它(工具会直接报错)。随时可以再打开,已有的项目数据不会被删除。": "Hide the features you do not use. A hidden feature disappears from the workbench tabs and the sidebar menu, and the agent cannot call it either (its tools fail loudly). You can turn it back on at any time, and existing project data is never deleted.",
|
|
1034
1090
|
"已隐藏": "Hidden",
|
|
1035
1091
|
"显示中": "Visible",
|
|
1036
|
-
"
|
|
1092
|
+
"当前功能全部可见。": "All features are currently visible.",
|
|
1037
1093
|
"已隐藏 {n0} 个功能:{n1}。隐藏的模块在对话里同样不可调用。": "{n0} feature(s) hidden: {n1}. Hidden modules cannot be called from chat either.",
|
|
1038
1094
|
"已隐藏 {n0} 个功能(设置 → 游戏素材大师 → 功能管理)": "{n0} feature(s) hidden (Settings → Game Material Master → Feature management)",
|
|
1039
1095
|
"所有功能都已被隐藏,请到「设置 → 游戏素材大师 → 功能管理」里打开至少一个。": "Every feature is hidden. Turn at least one back on in \"Settings → Game Material Master → Feature management\".",
|
|
1040
|
-
"所有功能都已被隐藏。请到「设置 → 游戏素材大师 → 功能管理」里打开至少一个。": "Every feature is hidden. Turn at least one back on in \"Settings → Game Material Master → Feature management\"."
|
|
1096
|
+
"所有功能都已被隐藏。请到「设置 → 游戏素材大师 → 功能管理」里打开至少一个。": "Every feature is hidden. Turn at least one back on in \"Settings → Game Material Master → Feature management\".",
|
|
1097
|
+
// ── 地图编辑器(模块六)────────────────────────────────────────────
|
|
1098
|
+
"地图编辑器": "Map editor",
|
|
1099
|
+
"画笔": "Brush",
|
|
1100
|
+
"橡皮": "Eraser",
|
|
1101
|
+
"吸管": "Picker",
|
|
1102
|
+
"我的地图": "My map",
|
|
1103
|
+
"读文件失败": "Failed to read the file",
|
|
1104
|
+
"已导入 {n0}": "Imported {n0}",
|
|
1105
|
+
"还没有地图项目。": "No map project yet.",
|
|
1106
|
+
"还没有导出过。": "Nothing exported yet.",
|
|
1107
|
+
"任务进行中…": "A job is running…",
|
|
1108
|
+
// 模块⑥「地图编辑器」已经是正式功能:这里不再需要它的实验性说明词条。
|
|
1109
|
+
"已删除项目": "Project deleted",
|
|
1110
|
+
"已改地图尺寸": "Map resized",
|
|
1111
|
+
"换一组": "Roll again",
|
|
1112
|
+
// ── 地图编辑器(模块六):一屏零术语,AsLib RPG Map Maker 同款 ────────
|
|
1113
|
+
"导入自己的素材图 → 自动连接 → 直接画 → 导出 PNG": "Import your own tile image → auto-connect → paint → export PNG",
|
|
1114
|
+
"先在左边点一块图当笔刷。": "Pick a tile on the left first.",
|
|
1115
|
+
"图层 2": "Layer 2",
|
|
1116
|
+
"确定删除素材「{n0}」?它切出来的块会一起删掉,无法撤销。": "Delete the tile image \"{n0}\"? The pieces cut from it are removed too, and this cannot be undone.",
|
|
1117
|
+
"已删除素材": "Tile image deleted",
|
|
1118
|
+
"改小地图会丢掉范围外的格子(可以撤销)。继续?": "Shrinking the map discards the cells outside the new bounds (undoable). Continue?",
|
|
1119
|
+
"清掉这一层上已经画的格子?": "Clear every painted cell on this layer?",
|
|
1120
|
+
"已清空这一层": "Layer cleared",
|
|
1121
|
+
"先选至少一块图:在左边点一下,按住 Shift 或 Ctrl 可以多选。": "Pick at least one tile first: click one on the left, and hold Shift or Ctrl for several.",
|
|
1122
|
+
"选一张素材图开始,或者先用自带素材试试。建出来就是 32×32、两层,可以直接画。": "Choose a tile image to start, or try the built-in one. What you get is a 32 by 32 map with two layers, ready to paint.",
|
|
1123
|
+
"选一张素材图开始": "Choose a tile image to start",
|
|
1124
|
+
"会动 {n0} 帧": "Animates: {n0} frames",
|
|
1125
|
+
"新增素材": "Add image",
|
|
1126
|
+
"恢复默认素材": "Restore built-ins",
|
|
1127
|
+
"还没有素材。点「新增素材」加一张自己的,或者点「恢复默认素材」拿到自带的那套。": "No images yet. Click \"Add image\" to bring your own, or \"Restore built-ins\" to get the bundled set.",
|
|
1128
|
+
"{n0}×{n1} · {n2} 块": "{n0}×{n1} · {n2} tiles",
|
|
1129
|
+
"自带": "Built-in",
|
|
1130
|
+
"素材的属性在新增时就定下来了,之后不能改 —— 要换就删掉重新新增。": "An image's properties are fixed when you add it and cannot be changed afterwards -- delete it and add it again to use different settings.",
|
|
1131
|
+
"素材图": "Image file",
|
|
1132
|
+
"选择图片": "Choose file",
|
|
1133
|
+
"还没选": "Nothing chosen yet",
|
|
1134
|
+
"叫什么": "Name",
|
|
1135
|
+
"留空就用文件名": "Leave empty to use the file name",
|
|
1136
|
+
"格子大小(留空就自动认)": "Cell size (leave empty to detect)",
|
|
1137
|
+
"只影响会动的素材(水、翻页图这类)": "Only affects images that animate (water, flip-books and the like)",
|
|
1138
|
+
"先选一张素材图。": "Choose an image file first.",
|
|
1139
|
+
"已新增素材 {n0}": "Added image: {n0}",
|
|
1140
|
+
"已恢复 {n0} 张默认素材": "Restored {n0} built-in images",
|
|
1141
|
+
"默认素材都在。": "All built-in images are already here.",
|
|
1142
|
+
"会动吗": "Does it animate?",
|
|
1143
|
+
"不动": "No",
|
|
1144
|
+
"这张图当作一堆静止的图块。": "Treats this image as a set of still tiles.",
|
|
1145
|
+
"翻页图": "Flip-book",
|
|
1146
|
+
"像手翻书:每一行是一页,连着播就动起来了。同一列的几行算同一块,画的时候点哪一行都行,整片会一起动。": "Like a flip-book: each row is one page, and playing them in order makes it move. Rows in the same column count as one tile, so it does not matter which row you click when painting -- the whole patch animates together.",
|
|
1147
|
+
"地图大小要是 1 以上的整数。": "The map size must be a whole number of 1 or more.",
|
|
1148
|
+
"地图最大 512×512 格。": "A map can be at most 512×512 cells.",
|
|
1149
|
+
"单位是格。改大只是多出空地;改小会丢掉范围外的格子(可撤销)": "Units are cells. Making it bigger just adds empty space; making it smaller drops the cells outside the new bounds (undoable).",
|
|
1150
|
+
"按图片尺寸自己认格子与用法。想重新认一次,就再上传一遍这张图。": "Works out the cell size and usage from the image dimensions. To detect it again, just upload the image once more.",
|
|
1151
|
+
"一格贴一块图,不做任何拼接。": "One tile per cell, with no stitching.",
|
|
1152
|
+
"按上下左右有没有同样的格子,自动从 16 块里挑一块:边缘、拐角会自己接上。": "Picks one of 16 tiles from the cells above, below, left and right, so edges and corners join up on their own.",
|
|
1153
|
+
"一小格再拆成 2×2 小块,按邻居自动拼成一片。草地、水面这类连着画的地面用它。": "Splits each cell into 2×2 sub-tiles that stitch together with their neighbours. Use it for ground you paint in large areas, such as grass or water.",
|
|
1154
|
+
"普通": "Plain",
|
|
1155
|
+
"整格": "Auto 16",
|
|
1156
|
+
"拼块": "Auto 2×2",
|
|
1157
|
+
"重命名项目": "Rename project",
|
|
1158
|
+
"确定": "OK",
|
|
1159
|
+
"{n0}:{n1}": "{n0}: {n1}",
|
|
1160
|
+
"{n0}:{n1}({n2})": "{n0}: {n1} ({n2})",
|
|
1161
|
+
"撤回上一步": "Undo the last step",
|
|
1162
|
+
"把刚撤回的一步再做回来": "Redo the step you just undid",
|
|
1163
|
+
"按住左键涂抹,铺当前选中的那块图": "Hold the left button to paint the currently selected tile",
|
|
1164
|
+
"把这格擦成空;右键随时是橡皮": "Erase this cell; right-click is always the eraser",
|
|
1165
|
+
"同色的连通区一次填满": "Fill a connected run of the same tile in one go",
|
|
1166
|
+
"吸取这一格用的图块,变成当前笔刷": "Pick up the tile used in this cell and make it the current brush",
|
|
1167
|
+
"拖动平移画布;空格拖或中键拖也行": "Drag to pan the canvas; space-drag or middle-drag works too",
|
|
1168
|
+
"显示或隐藏格线,方便数格子": "Show or hide the grid lines so cells are easier to count",
|
|
1169
|
+
"随机铺满 / 迷宫 / 大陆:用选中的图块一键铺满整层": "Random fill / maze / continent: fill the whole layer with the selected tiles in one click",
|
|
1170
|
+
"地图大小、图层、帮助": "Map size, layers and help",
|
|
1171
|
+
"图层": "Layer",
|
|
1172
|
+
"素材图加载失败:{n0}(试试重新上传这张图)": "Could not load the tile image: {n0} (try uploading it again)",
|
|
1173
|
+
"用自带素材试试": "Try the built-in image",
|
|
1174
|
+
"切换项目": "Switch project",
|
|
1175
|
+
"素材": "Image",
|
|
1176
|
+
"第 {n0} 块": "Tile {n0}",
|
|
1177
|
+
"还没有素材,点上面的「素材」上传一张。": "No tile image yet: click \"Image\" above to upload one.",
|
|
1178
|
+
"油漆桶": "Paint bucket",
|
|
1179
|
+
"抓手": "Hand",
|
|
1180
|
+
"上一层": "Layer up",
|
|
1181
|
+
"下一层": "Layer down",
|
|
1182
|
+
"网格线": "Grid lines",
|
|
1183
|
+
"一键生成": "Generate",
|
|
1184
|
+
"设置": "Settings",
|
|
1185
|
+
"素材调色板": "Tile palette",
|
|
1186
|
+
"自动": "Automatic",
|
|
1187
|
+
"普通图块": "Plain tiles",
|
|
1188
|
+
"整格自动连接": "Full-cell auto-connect",
|
|
1189
|
+
"拼块自动连接": "Block auto-connect",
|
|
1190
|
+
"慢": "Slow",
|
|
1191
|
+
"中": "Medium",
|
|
1192
|
+
"快": "Fast",
|
|
1193
|
+
"这块素材怎么用": "How this image is used",
|
|
1194
|
+
"动画速度": "Animation speed",
|
|
1195
|
+
"导出内容": "What to export",
|
|
1196
|
+
"地图图片 PNG": "Map image (PNG)",
|
|
1197
|
+
"地图长什么样,直接能放进游戏": "How the map looks - ready to drop into a game",
|
|
1198
|
+
"存档数据 JSON": "Save data (JSON)",
|
|
1199
|
+
"每一格是什么,给引擎和工具读": "Which tile sits in each cell, for engines and tools",
|
|
1200
|
+
"素材原图": "Source tilesets",
|
|
1201
|
+
"把素材图一起拷进包里,换台机器也能用": "Copy the tileset images in too, so the package works on another machine",
|
|
1202
|
+
"产出不止一个文件时自动打成一个 ZIP;只有一个文件时就直接给你那个文件。": "More than one file is packed into a single ZIP; a single file is handed to you as it is.",
|
|
1203
|
+
"至少勾一项要导出的内容。": "Choose at least one thing to export.",
|
|
1204
|
+
"最近一次导出:{n0} 个文件": "Last export: {n0} files",
|
|
1205
|
+
"下载 {n0}": "Download {n0}",
|
|
1206
|
+
"打包,含全部内容": "Bundle with everything",
|
|
1207
|
+
"另存为…": "Save as…",
|
|
1208
|
+
"下载走浏览器(默认进它的下载目录);想自己挑位置就点「另存为…」。": "Downloads go through the browser (its download folder by default); use \"Save as…\" to pick the location yourself.",
|
|
1209
|
+
"下载走浏览器:文件会进它的下载目录(想每次都自己挑位置,在浏览器里打开「下载前询问保存位置」)。": "Downloads go through the browser: files land in its download folder (turn on \"Ask where to save each file\" in the browser to choose every time).",
|
|
1210
|
+
"这个浏览器不支持「另存为」,请用下载(位置由浏览器的下载设置决定)。": "This browser does not support \"Save as\" - use the download link instead (the browser decides the location).",
|
|
1211
|
+
"已保存到 {n0}": "Saved to {n0}",
|
|
1212
|
+
"另存为失败:{n0}": "Save as failed: {n0}",
|
|
1213
|
+
"还没有导出过,先点「导出」。现在打开的是项目目录。": "Nothing has been exported yet - press \"Export\" first. The project folder is open for now.",
|
|
1214
|
+
"已打开 {n0}": "Opened {n0}",
|
|
1215
|
+
"文件都在 {n0}": "All files are in {n0}",
|
|
1216
|
+
"倍率": "Scale",
|
|
1217
|
+
"只影响 PNG 的尺寸,不影响存档数据": "Only affects the PNG size, not the saved data",
|
|
1218
|
+
"打开导出目录": "Open the export folder",
|
|
1219
|
+
"地图大小": "Map size",
|
|
1220
|
+
"图层 {n0}": "Layer {n0}",
|
|
1221
|
+
"已加一层": "Layer added",
|
|
1222
|
+
"加一层": "Add layer",
|
|
1223
|
+
"删掉当前这一层": "Delete the current layer",
|
|
1224
|
+
"已删掉这一层": "Layer deleted",
|
|
1225
|
+
"清空当前图层": "Clear current layer",
|
|
1226
|
+
"标记": "Marker",
|
|
1227
|
+
"地图上点一格放一个标记;点已有标记可以改名、按住拖动可以挪位置;右键删掉它": "Click a cell to drop a marker; click an existing marker to rename it, drag it to move it; right-click deletes it",
|
|
1228
|
+
"标记层": "Marker layer",
|
|
1229
|
+
"还没有标记。选「标记」工具,在地图上点一格。": "No markers yet. Pick the Marker tool and click a cell on the map.",
|
|
1230
|
+
"{n0} 个标记": "{n0} markers",
|
|
1231
|
+
"标记 {n0}": "Marker {n0}",
|
|
1232
|
+
"定位": "Go to",
|
|
1233
|
+
"删掉": "Delete",
|
|
1234
|
+
"已重命名这一层": "Layer renamed",
|
|
1235
|
+
"图层名字不能为空": "A layer name cannot be empty",
|
|
1236
|
+
"上移一层": "Move layer up",
|
|
1237
|
+
"下移一层": "Move layer down",
|
|
1238
|
+
"只看这一层": "Only this layer",
|
|
1239
|
+
"点名字可以改名,右边可以换顺序或删掉": "Click a name to rename it; on the right you can reorder or delete it",
|
|
1240
|
+
"标记名字": "Marker name",
|
|
1241
|
+
"点中间的数字打开图层列表(改名 / 换顺序 / 删掉);上半换上一层、下半换下一层": "Click the number in the middle to open the layer list (rename / reorder / delete); the top half switches up a layer, the bottom half switches down",
|
|
1242
|
+
"已换图层顺序": "Layer order updated",
|
|
1243
|
+
"帮助": "Help",
|
|
1244
|
+
"左键拖动=用当前工具画;空格拖动或中键拖动=平移;滚轮=缩放;右键=橡皮。": "Left-drag paints with the current tool; space-drag or middle-drag pans; the wheel zooms; the right button erases.",
|
|
1245
|
+
"调色板里点一下选一块图当笔刷,按住 Shift 或 Ctrl 可以多选,「一键生成」会用这些图块。": "Click a tile in the palette to use it as the brush; hold Shift or Ctrl to select several, and \"Generate\" uses exactly those.",
|
|
1246
|
+
"地图四周是接上的:自动连接会把上下、左右两边接起来。画布拖不出地图 —— 拖到边就停,地图左上角对齐后不会再乱动;图外那片空白画不上。": "The map wraps all the way round: auto-tiling joins the top/bottom and left/right edges. The canvas cannot be dragged off the map -- it stops at the edge, and once the map's top-left lines up with the canvas it stays there. The blank area outside the map cannot be painted.",
|
|
1247
|
+
"整个模块看过了": "Seen the whole module",
|
|
1248
|
+
"随机铺满": "Random fill",
|
|
1249
|
+
"迷宫": "Maze",
|
|
1250
|
+
"大陆": "Continent",
|
|
1251
|
+
"用的图块:还没选。在左边点一下选一块,按住 Shift 或 Ctrl 可以多选。": "Tiles used: none yet. Click one on the left, and hold Shift or Ctrl for several.",
|
|
1252
|
+
"用的图块:{n0}": "Tiles used: {n0}",
|
|
1253
|
+
"迷宫:按顺序取两块,第一块当墙,第二块当路。": "Maze: takes two tiles in order - the first is the wall, the second the path.",
|
|
1254
|
+
"大陆:按顺序取最多四块当四种地貌(水下 / 海面 / 草地 / 雪地)。": "Continent: takes up to four tiles in order as four terrains (underwater / sea / grass / snow).",
|
|
1255
|
+
"随机铺满:在选中的图块里均匀随机。": "Random fill: uniformly random among the selected tiles.",
|
|
1256
|
+
"缩得太小,放大一点。": "Zoomed out too far - zoom in a bit.",
|
|
1257
|
+
"第 {n0} 层 / 共 {n1} 层": "Layer {n0} of {n1}"
|
|
1041
1258
|
};
|
|
1042
1259
|
/* i18n-ignore-end */
|
|
1043
1260
|
/**
|
|
@@ -1195,6 +1412,7 @@ window.__ModuleLoader__.load({
|
|
|
1195
1412
|
["getConfig", false],
|
|
1196
1413
|
["saveConfig", true],
|
|
1197
1414
|
["testArk", false],
|
|
1415
|
+
["testCustomImage", false],
|
|
1198
1416
|
["testMinimax", false],
|
|
1199
1417
|
["listProjects", false],
|
|
1200
1418
|
["createProject", true],
|
|
@@ -1208,6 +1426,9 @@ window.__ModuleLoader__.load({
|
|
|
1208
1426
|
["setReviewMode", true],
|
|
1209
1427
|
["reportClientOrigin", true],
|
|
1210
1428
|
["revealProject", true],
|
|
1429
|
+
// 本地自选视频(转圈 / 某个方向)与中间图片打包。
|
|
1430
|
+
["uploadVideo", true],
|
|
1431
|
+
["exportImages", true],
|
|
1211
1432
|
["runImage", true],
|
|
1212
1433
|
["runImages", true],
|
|
1213
1434
|
["setImageMode", true],
|
|
@@ -1227,7 +1448,7 @@ window.__ModuleLoader__.load({
|
|
|
1227
1448
|
["resetFramePicks", true],
|
|
1228
1449
|
["rekey", true],
|
|
1229
1450
|
["compose", true],
|
|
1230
|
-
//
|
|
1451
|
+
// 模块②(图片生成)—— 这一段只是远程方法清单,和下面的组件区无关
|
|
1231
1452
|
["listImageJobs", false],
|
|
1232
1453
|
["createImageJob", true],
|
|
1233
1454
|
["getImageJob", true],
|
|
@@ -1311,7 +1532,28 @@ window.__ModuleLoader__.load({
|
|
|
1311
1532
|
["saveTileMapCells", true],
|
|
1312
1533
|
["runTileExport", true],
|
|
1313
1534
|
["cancelTileJob", true],
|
|
1314
|
-
["revealTileProject", true]
|
|
1535
|
+
["revealTileProject", true],
|
|
1536
|
+
// 地图编辑器(模块六)。同样:第二个字段是「收不收 payload」。
|
|
1537
|
+
["listMapProjects", false],
|
|
1538
|
+
["createMapProject", true],
|
|
1539
|
+
["getMapProject", true],
|
|
1540
|
+
["saveMapProject", true],
|
|
1541
|
+
["deleteMapProject", true],
|
|
1542
|
+
["importMapTileset", true],
|
|
1543
|
+
["importSampleTileset", true],
|
|
1544
|
+
["saveMapTileset", true],
|
|
1545
|
+
["removeMapTileset", true],
|
|
1546
|
+
["saveMapDoc", true],
|
|
1547
|
+
["applyMapOps", true],
|
|
1548
|
+
["mapUndo", true],
|
|
1549
|
+
["mapRedo", true],
|
|
1550
|
+
["mapPlan", true],
|
|
1551
|
+
["runMapGenerate", true],
|
|
1552
|
+
["runMapPreview", true],
|
|
1553
|
+
["runMapExport", true],
|
|
1554
|
+
["cancelMapJob", true],
|
|
1555
|
+
["setMapApproved", true],
|
|
1556
|
+
["revealMapProject", true]
|
|
1315
1557
|
];
|
|
1316
1558
|
const CONTRIBUTION = {
|
|
1317
1559
|
package: PACKAGE,
|
|
@@ -1426,14 +1668,19 @@ window.__ModuleLoader__.load({
|
|
|
1426
1668
|
];
|
|
1427
1669
|
}
|
|
1428
1670
|
let TILE_EXPERIMENTAL_POINTS = make_TILE_EXPERIMENTAL_POINTS();
|
|
1429
|
-
|
|
1671
|
+
// 模块⑥「地图编辑器」**已经不再是实验性功能**:链路全本地、零计费,几何与导出
|
|
1672
|
+
// 都有像素级自检兜底(`verify-map*` 四件),界面上与导出的 PNG 执行同一份绘制计划。
|
|
1673
|
+
// 所以它没有实验性角标、没有进入弹窗、模块内也没有常驻提示条
|
|
1674
|
+
// —— 留下任何一条都会让「正式」这个说法名不副实。
|
|
1675
|
+
/** 六个功能模块。插件是「大师」,每个模块管一类素材。 */
|
|
1430
1676
|
function make_MODULES() {
|
|
1431
1677
|
return [
|
|
1432
1678
|
{ key: "sprite", title: T("八方向图生成"), hint: T("一张设定图 → 8 方向 × 8 帧精灵图") },
|
|
1433
1679
|
{ key: "image", title: T("图片生成"), hint: T("按提示词出图,可带参考图,支持抠绿幕导出 PNG") },
|
|
1434
1680
|
{ key: "sequence", title: T("序列帧生成"), hint: T("图/视频参考生成视频 → 抽帧 → 抠像 → 合成与播放预览") },
|
|
1435
1681
|
{ key: "rig", title: T("骨骼动画生成"), hint: T("拆件 → 装配定位 → 推骨骼与动画 → 打包 Spine 图集"), experimental: true },
|
|
1436
|
-
{ key: "tile", title: T("45°地图地块生成"), hint: T("45° 等距地块 → 拼成地图:几何交给代码,内容交给 AI"), experimental: true }
|
|
1682
|
+
{ key: "tile", title: T("45°地图地块生成"), hint: T("45° 等距地块 → 拼成地图:几何交给代码,内容交给 AI"), experimental: true },
|
|
1683
|
+
{ key: "map", title: T("地图编辑器"), hint: T("导入自己的素材图 → 自动连接 → 直接画 → 导出 PNG") }
|
|
1437
1684
|
];
|
|
1438
1685
|
}
|
|
1439
1686
|
let MODULES = make_MODULES();
|
|
@@ -1533,7 +1780,7 @@ window.__ModuleLoader__.load({
|
|
|
1533
1780
|
// http(s) 链接加 target="_blank",不拦就会真的新开一个标签页。
|
|
1534
1781
|
// 只按 `dsh-gmm` 参数识别自己的链接,其它链接(含站外的)一律放行。
|
|
1535
1782
|
const OPEN_QUERY_KEY = "dsh-gmm";
|
|
1536
|
-
const OPEN_MODULES = new Set(["sprite", "image", "sequence", "rig", "tile"]);
|
|
1783
|
+
const OPEN_MODULES = new Set(["sprite", "image", "sequence", "rig", "tile", "map"]);
|
|
1537
1784
|
/** 意图订阅者:各模块组件都挂着,谁在挂载谁就被通知。 */
|
|
1538
1785
|
const intentListeners = new Set();
|
|
1539
1786
|
/** 最近一次意图。晚挂载的组件(切模块后才渲染)订阅时立刻拿到它。 */
|
|
@@ -1696,6 +1943,13 @@ window.__ModuleLoader__.load({
|
|
|
1696
1943
|
// 就被切了;而前四个模块恰好都在 686 以内,所以这个坑一直没暴露出来。
|
|
1697
1944
|
const CSS = `
|
|
1698
1945
|
.SPR_root{display:flex;flex-direction:column;height:100%;min-height:0;overflow-y:auto;overflow-x:hidden;color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}
|
|
1946
|
+
/*
|
|
1947
|
+
* 六号模块(地图编辑器)自己的正文容器。
|
|
1948
|
+
*
|
|
1949
|
+
* ⚠️ 以前**一条 CSS 都没有**:卡片与文字紧贴面板左右边缘,看着像没做完(真机反馈
|
|
1950
|
+
* 「这个界面离左边没有 padding」)。这里对齐模块①②③用的 .SPR_main(16px 18px 40px)。
|
|
1951
|
+
*/
|
|
1952
|
+
.SPR_moduleBody{display:block;padding:16px 18px 40px}
|
|
1699
1953
|
.SPR_head{display:flex;align-items:center;gap:10px;padding:14px 18px;border-bottom:1px solid var(--dsw-alias-border-l2);flex:none}
|
|
1700
1954
|
.SPR_head h2{margin:0;font-size:15px;font-weight:600}
|
|
1701
1955
|
.SPR_headSub{color:var(--dsw-alias-label-tertiary);font-size:12px}
|
|
@@ -1784,6 +2038,147 @@ window.__ModuleLoader__.load({
|
|
|
1784
2038
|
.SPR_mapCell-active{background:rgba(255,120,0,.6);outline:1px solid rgba(255,120,0,.9)}
|
|
1785
2039
|
.SPR_mapCell-empty{background:rgba(150,150,150,.16)}
|
|
1786
2040
|
.SPR_mapCellLabel{pointer-events:none;font-size:10px;color:var(--dsw-alias-label-secondary);opacity:0}
|
|
2041
|
+
/* ── 地图编辑器(模块六)· AsLib RPG Map Maker 同款一屏布局 ─────────────
|
|
2042
|
+
外层仍然走 DSH 变量(浅色 / 深色都不吃亏),编辑器内部沿用 AsLib 配色:
|
|
2043
|
+
深灰 #424242、木质按钮、红框选中、单层预览绿底 rgb(56,170,68)。 */
|
|
2044
|
+
.SPR_moduleBody[data-module="map"]{padding:0;height:100%;box-sizing:border-box;display:flex;flex-direction:column;min-height:0}
|
|
2045
|
+
.SPR_mapEdRoot{display:flex;flex-direction:column;flex:1;min-height:0;border-radius:12px;overflow:hidden;background:#424242;color:#f2efe9;border:1px solid var(--dsw-alias-border-l2)}
|
|
2046
|
+
.SPR_mapEdSpacer{flex:1;min-width:0}
|
|
2047
|
+
.SPR_mapEdHint{font-size:11px;line-height:1.7;color:#c9c4bb;margin:0}
|
|
2048
|
+
/* 顶栏:一行。没有步骤条,也没有长说明。 */
|
|
2049
|
+
.SPR_mapEdTop{display:flex;align-items:center;gap:8px;padding:6px 10px;background:#383838;border-bottom:1px solid #232323;flex:none}
|
|
2050
|
+
.SPR_mapEdProjWrap{position:relative;min-width:0}
|
|
2051
|
+
.SPR_mapEdProj{display:inline-flex;align-items:center;gap:6px;font:inherit;font-size:13px;font-weight:600;max-width:280px;cursor:pointer;color:#f7f3ec;background:transparent;border:1px solid transparent;border-radius:8px;padding:4px 8px}
|
|
2052
|
+
.SPR_mapEdProj:hover{background:#4a4a4a}
|
|
2053
|
+
.SPR_mapEdProj[data-open="true"]{background:#4a4a4a;border-color:#6d6d6d}
|
|
2054
|
+
.SPR_mapEdProjName{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2055
|
+
.SPR_mapEdCaret{font-size:10px;color:#c9c4bb}
|
|
2056
|
+
.SPR_mapEdMenu{position:absolute;top:calc(100% + 4px);left:0;z-index:30;min-width:200px;max-height:60vh;overflow:auto;display:flex;flex-direction:column;padding:4px;background:#2f2f2f;border:1px solid #1c1c1c;border-radius:10px;box-shadow:0 10px 26px rgba(0,0,0,.45)}
|
|
2057
|
+
.SPR_mapEdMenuItem{font:inherit;font-size:12px;text-align:left;cursor:pointer;color:#ece7df;background:transparent;border:none;border-radius:6px;padding:6px 9px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
2058
|
+
.SPR_mapEdMenuItem:hover{background:#454545}
|
|
2059
|
+
.SPR_mapEdMenuItem[data-on="true"]{background:#4d4d4d;color:var(--dsw-alias-state-business-primary, #8ab4f8)}
|
|
2060
|
+
.SPR_mapEdMenuItem[data-danger="true"]{color:var(--dsw-alias-state-error-primary, #ff8b7a)}
|
|
2061
|
+
.SPR_mapEdMenuLabel{font-size:10px;color:#9d968c;padding:8px 9px 2px}
|
|
2062
|
+
.SPR_mapEdTopBtn{font:inherit;font-size:12px;cursor:pointer;color:#f7f3ec;background:linear-gradient(#5d5d5d,#4b4b4b);border:1px solid #232323;border-radius:8px;padding:5px 14px}
|
|
2063
|
+
.SPR_mapEdTopBtn:hover{background:linear-gradient(#6a6a6a,#555)}
|
|
2064
|
+
.SPR_mapEdTopBtn[data-on="true"]{background:linear-gradient(#7d6a4a,#5f5038);border-color:#d9a95f}
|
|
2065
|
+
.SPR_mapEdSave{font-size:11px;color:#b9b3a8;white-space:nowrap;font-variant-numeric:tabular-nums}
|
|
2066
|
+
.SPR_mapEdSave[data-busy="true"]{color:var(--dsw-alias-state-warning-primary, #ffc400)}
|
|
2067
|
+
/* 两栏主体:左列 28.5%(240~340),右列画布。 */
|
|
2068
|
+
.SPR_mapEdBody{display:flex;flex:1;min-height:0}
|
|
2069
|
+
.SPR_mapEdSide{width:28.5%;min-width:240px;max-width:340px;flex:none;display:flex;flex-direction:column;gap:6px;padding:8px;box-sizing:border-box;background:#3b3b3b;border-right:1px solid #232323;min-height:0}
|
|
2070
|
+
.SPR_mapEdSideTitle{font-size:11px;color:#a9a29a;padding-left:2px}
|
|
2071
|
+
.SPR_mapEdPalette{flex:1;min-height:120px;overflow:auto;background:#2d2d2d;border:1px solid #232323;border-radius:6px;padding:4px}
|
|
2072
|
+
.SPR_mapEdPaletteGrid{display:grid;grid-template-columns:repeat(8,32px);gap:2px}
|
|
2073
|
+
.SPR_mapEdTile{width:32px;height:32px;padding:0;border:1px solid #262626;border-radius:3px;background-color:#1f1f1f;background-repeat:no-repeat;image-rendering:pixelated;cursor:pointer}
|
|
2074
|
+
.SPR_mapEdTile:hover{border-color:#d9a95f}
|
|
2075
|
+
/* 红框=当前笔刷(AsLib 同款) */
|
|
2076
|
+
.SPR_mapEdTile[data-on="true"]{outline:2px solid #e23b2b;outline-offset:-2px;border-color:#e23b2b}
|
|
2077
|
+
/* 工具格:6 列 × 2 行,木质方块按钮 */
|
|
2078
|
+
.SPR_mapEdTools{display:grid;grid-template-columns:repeat(6,1fr);gap:4px;flex:none}
|
|
2079
|
+
.SPR_mapEdTool{aspect-ratio:1/1;display:flex;align-items:center;justify-content:center;padding:0;cursor:pointer;color:#3a2a12;background:linear-gradient(#e6bd7d,#c9974f);border:1px solid #6b4a22;border-radius:4px}
|
|
2080
|
+
.SPR_mapEdTool:hover{background:linear-gradient(#f2d29a,#d6a761)}
|
|
2081
|
+
.SPR_mapEdTool[data-on="true"]{background:linear-gradient(#fbe3ad,#e0b268);box-shadow:inset 0 0 0 2px #d23b2c}
|
|
2082
|
+
.SPR_mapEdTool:disabled{opacity:.4;cursor:default}
|
|
2083
|
+
.SPR_mapEdLayerBtn{flex-direction:column;gap:0;padding:1px;background:linear-gradient(#e6bd7d,#c9974f)}
|
|
2084
|
+
/* 工具格上方的小标签(名称 + 快捷键 + 介绍)。
|
|
2085
|
+
position:fixed —— 祖先里有 overflow 容器,absolute 会被裁掉「按钮正上方」那一段。 */
|
|
2086
|
+
.SPR_mapEdTip{position:fixed;z-index:60;pointer-events:none;transform:translate(-50%,-100%);max-width:236px;padding:6px 8px;border-radius:6px;border:1px solid #6b4a22;background:#2b2b2b;color:#f3e7d3;box-shadow:0 6px 16px rgba(0,0,0,.4);font-size:11px;line-height:1.5;text-align:left}
|
|
2087
|
+
.SPR_mapEdTip::after{content:"";position:absolute;left:50%;bottom:-6px;margin-left:-5px;border-left:5px solid transparent;border-right:5px solid transparent;border-top:6px solid #2b2b2b}
|
|
2088
|
+
.SPR_mapEdTipName{display:flex;align-items:center;gap:6px;font-weight:600}
|
|
2089
|
+
.SPR_mapEdTipKey{padding:0 4px;border-radius:3px;background:#4a4a4a;font-size:10px;font-weight:400;color:#e8d7bb}
|
|
2090
|
+
.SPR_mapEdTipDesc{margin-top:2px;color:#c9bda8}
|
|
2091
|
+
/* 新建 / 重命名项目的名字对话框。fixed 居中:祖先里有 overflow 容器,
|
|
2092
|
+
absolute 会被裁掉(和工具小标签、侧栏菜单同一个坑)。 */
|
|
2093
|
+
.SPR_mapEdDlgMask{position:fixed;inset:0;z-index:70;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.42)}
|
|
2094
|
+
.SPR_mapEdDlg{width:300px;max-width:calc(100vw - 32px);padding:12px;border:1px solid #6b4a22;border-radius:8px;background:#2f2f2f;color:#f3e7d3;box-shadow:0 10px 30px rgba(0,0,0,.5)}
|
|
2095
|
+
.SPR_mapEdDlgTitle{font-size:13px;font-weight:600;margin-bottom:8px}
|
|
2096
|
+
.SPR_mapEdDlgLabel{display:block;font-size:11px;color:#c9bda8;margin-bottom:4px}
|
|
2097
|
+
.SPR_mapEdDlgInput{width:100%;box-sizing:border-box;padding:6px 8px;border:1px solid #6b4a22;border-radius:4px;background:#1f1f1f;color:#f3e7d3;font-size:12px;outline:none}
|
|
2098
|
+
.SPR_mapEdDlgInput:focus{border-color:#d9a95f}
|
|
2099
|
+
.SPR_mapEdDlgRow{display:flex;justify-content:flex-end;gap:8px;margin-top:12px}
|
|
2100
|
+
.SPR_mapEdLayerHalf{flex:1;width:100%;display:flex;align-items:center;justify-content:center;padding:0;cursor:pointer;color:#4a3416;background:transparent;border:none;border-radius:3px}
|
|
2101
|
+
.SPR_mapEdLayerHalf:hover:not(:disabled){background:rgba(255,255,255,.28)}
|
|
2102
|
+
.SPR_mapEdLayerHalf:disabled{opacity:.3;cursor:default}
|
|
2103
|
+
.SPR_mapEdLayerNum{width:100%;padding:0;border:none;background:transparent;cursor:pointer;font-family:inherit;font-size:10px;line-height:1;font-weight:700;color:#4a3416;font-variant-numeric:tabular-nums}
|
|
2104
|
+
.SPR_mapEdLayerNum:hover{background:rgba(255,255,255,.28);border-radius:3px}
|
|
2105
|
+
/* 图层卡:一行一层(点名字就地改名,右边换顺序 / 删掉)。
|
|
2106
|
+
最上面一行固定是「标记层」,它不是图层数组里的成员 —— 标记有自己的位置与名字。 */
|
|
2107
|
+
.SPR_mapEdLayerList{display:flex;flex-direction:column;gap:3px;margin:6px 0}
|
|
2108
|
+
.SPR_mapEdLayerRow{display:flex;align-items:center;gap:5px;padding:3px 5px;border:1px solid #6b4a22;border-radius:4px;background:rgba(0,0,0,.18)}
|
|
2109
|
+
.SPR_mapEdLayerRow[data-on="true"]{border-color:#e6bd7d;background:rgba(230,189,125,.18)}
|
|
2110
|
+
.SPR_mapEdLayerIdx{width:15px;flex:none;text-align:center;font-size:11px;color:#c9bda8;font-variant-numeric:tabular-nums}
|
|
2111
|
+
.SPR_mapEdLayerName{flex:1;min-width:0;text-align:left;padding:2px 4px;border:1px dashed transparent;border-radius:3px;background:transparent;color:#f3e7d3;font-family:inherit;font-size:12px;cursor:text;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2112
|
+
.SPR_mapEdLayerName:hover{border-color:#6b4a22}
|
|
2113
|
+
.SPR_mapEdLayerNameInput{flex:1;min-width:0;padding:2px 4px;border:1px solid #e6bd7d;border-radius:3px;background:#1f1f1f;color:#f3e7d3;font-family:inherit;font-size:12px;outline:none}
|
|
2114
|
+
.SPR_mapEdMiniBtn{padding:1px 5px;border:1px solid #6b4a22;border-radius:3px;background:rgba(0,0,0,.25);color:#e8d7bb;font-family:inherit;font-size:11px;line-height:16px;cursor:pointer}
|
|
2115
|
+
.SPR_mapEdMiniBtn:hover:not(:disabled){background:rgba(230,189,125,.25)}
|
|
2116
|
+
.SPR_mapEdMiniBtn:disabled{opacity:.35;cursor:default}
|
|
2117
|
+
.SPR_mapEdMarkerRow{display:flex;align-items:center;gap:6px;padding:3px 5px;border:1px solid #6b4a22;border-radius:4px;background:rgba(0,0,0,.18)}
|
|
2118
|
+
.SPR_mapEdMarkerRow[data-on="true"]{border-color:#e23b2b;background:rgba(226,59,43,.14)}
|
|
2119
|
+
.SPR_mapEdMarkerDot{width:18px;height:18px;flex:none;display:flex;align-items:center;justify-content:center;border:1.5px solid #f0c040;border-radius:50%;background:#14161e;color:#fff;font-size:11px;font-weight:700;font-variant-numeric:tabular-nums}
|
|
2120
|
+
.SPR_mapEdMarkerName{flex:1;min-width:0;padding:2px 4px;border:1px solid transparent;border-radius:3px;background:transparent;color:#f3e7d3;font-family:inherit;font-size:12px;outline:none}
|
|
2121
|
+
.SPR_mapEdMarkerName:hover{border-color:#6b4a22}
|
|
2122
|
+
.SPR_mapEdMarkerName:focus{border-color:#e6bd7d;background:#1f1f1f}
|
|
2123
|
+
.SPR_mapEdMarkerAt{flex:none;font-size:11px;color:#b9b3a8;font-variant-numeric:tabular-nums}
|
|
2124
|
+
.SPR_mapEdMarkerList{display:flex;flex-direction:column;gap:3px;max-height:216px;overflow:auto;margin-top:4px}
|
|
2125
|
+
/* 画布:铺满右列,像素画不糊 */
|
|
2126
|
+
.SPR_mapEdStage{position:relative;flex:1;min-width:0;min-height:360px;background:#3a3a3a;overflow:hidden}
|
|
2127
|
+
.SPR_mapEdCanvas{display:block;width:100%;height:100%;image-rendering:pixelated;touch-action:none;cursor:crosshair}
|
|
2128
|
+
.SPR_mapEdToast{position:absolute;left:10px;bottom:10px;font-size:11px;padding:4px 10px;border-radius:999px;background:rgba(0,0,0,.62);color:#ffe9a8}
|
|
2129
|
+
.SPR_mapEdToast[data-busy="true"]{color:var(--dsw-alias-state-warning-primary, #ffc400)}
|
|
2130
|
+
/* 卡片:从顶栏下面拉出来的小面板,盖在画布上(关掉就什么都不占) */
|
|
2131
|
+
.SPR_mapEdCardWrap{position:absolute;top:44px;right:12px;z-index:20;max-width:min(520px,92%)}
|
|
2132
|
+
.SPR_mapEdCard{display:flex;flex-direction:column;gap:8px;padding:10px 12px;border-radius:10px;background:#2f2f2f;border:1px solid #1c1c1c;box-shadow:0 12px 30px rgba(0,0,0,.5)}
|
|
2133
|
+
.SPR_mapEdCardHead{display:flex;align-items:center;gap:8px}
|
|
2134
|
+
.SPR_mapEdCardHead>h4{margin:0;font-size:13px;color:#f7f3ec}
|
|
2135
|
+
.SPR_mapEdCardClose{font:inherit;font-size:14px;line-height:1;cursor:pointer;color:#c9c4bb;background:transparent;border:none;border-radius:6px;padding:2px 6px}
|
|
2136
|
+
.SPR_mapEdCardClose:hover{background:#454545;color:#fff}
|
|
2137
|
+
.SPR_mapEdCardRow{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
|
|
2138
|
+
.SPR_mapEdRows{display:flex;flex-direction:column;gap:6px}
|
|
2139
|
+
.SPR_mapEdRow{display:flex;flex-direction:column;gap:3px}
|
|
2140
|
+
.SPR_mapEdLabel{font-size:11px;color:#bfb8ae}
|
|
2141
|
+
.SPR_mapEdRowHint{font-size:11px;line-height:1.6;color:#9d968c}
|
|
2142
|
+
.SPR_mapEdTsList{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:4px;max-height:220px;overflow:auto}
|
|
2143
|
+
.SPR_mapEdTsRow{display:flex;align-items:center;gap:6px;padding:3px 4px;border:1px solid transparent;border-radius:6px}
|
|
2144
|
+
.SPR_mapEdTsRow[data-on="true"]{border-color:#d9a95f;background:#3a2f1d}
|
|
2145
|
+
.SPR_mapEdTsPick{flex:1;display:flex;align-items:baseline;gap:8px;min-width:0;padding:2px 4px;font:inherit;font-size:12px;color:#f2efe9;text-align:left;background:none;border:0;cursor:pointer}
|
|
2146
|
+
.SPR_mapEdTsPick:hover{color:#ffd79a}
|
|
2147
|
+
.SPR_mapEdTsName{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2148
|
+
.SPR_mapEdTsMeta{flex:none;font-size:11px;color:#9a9a9a}
|
|
2149
|
+
.SPR_mapEdTsBadge{flex:none;padding:0 4px;border-radius:3px;background:#4a4a4a;font-size:10px;color:#e8d7bb}
|
|
2150
|
+
.SPR_mapEdTsBadge[data-anim="true"]{background:#2f4a2f;color:#bfe6bf}
|
|
2151
|
+
.SPR_mapEdPair{display:flex;align-items:center;gap:6px}
|
|
2152
|
+
.SPR_mapEdTimes{color:#9a9a9a;font-size:12px}
|
|
2153
|
+
.SPR_mapEdSeg{display:flex;gap:4px;flex-wrap:wrap}
|
|
2154
|
+
.SPR_mapEdSegBtn{font:inherit;font-size:12px;padding:4px 10px;border:1px solid #565656;border-radius:6px;background:#242424;color:#f2efe9;cursor:pointer}
|
|
2155
|
+
.SPR_mapEdSegBtn:hover{border-color:#d9a95f}
|
|
2156
|
+
.SPR_mapEdSegBtn[data-on="true"]{border-color:#d9a95f;background:#3a2f1d;color:#ffd79a;font-weight:600}
|
|
2157
|
+
.SPR_mapEdSelect{font:inherit;font-size:12px;color:#f2efe9;background:#242424;border:1px solid #565656;border-radius:6px;padding:4px 8px;max-width:100%}
|
|
2158
|
+
.SPR_mapEdChips{display:flex;gap:6px;flex-wrap:wrap}
|
|
2159
|
+
.SPR_mapEdChip{font:inherit;font-size:11px;cursor:pointer;color:#ded8cf;background:#3b3b3b;border:1px solid #565656;border-radius:999px;padding:3px 10px}
|
|
2160
|
+
.SPR_mapEdChip[data-on="true"]{border-color:#d9a95f;color:#ffd89a}
|
|
2161
|
+
.SPR_mapEdCheck{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:#e6e1d8}
|
|
2162
|
+
.SPR_mapEdHelp{display:flex;flex-direction:column;gap:4px;padding:8px 10px;border-radius:8px;background:#383838}
|
|
2163
|
+
.SPR_mapEdHelp>h5{margin:0;font-size:12px;color:#f7f3ec}
|
|
2164
|
+
.SPR_mapEdHelp>p{margin:0;font-size:11px;line-height:1.7;color:#c9c4bb}
|
|
2165
|
+
.SPR_mapEdRadios{display:flex;gap:12px;flex-wrap:wrap}
|
|
2166
|
+
.SPR_mapEdRadio{display:inline-flex;align-items:center;gap:5px;font-size:12px;color:#e6e1d8;cursor:pointer}
|
|
2167
|
+
.SPR_mapEdFiles{margin:0;padding-left:18px;font-size:12px;line-height:1.9;color:#c9c4bb}
|
|
2168
|
+
.SPR_mapEdFiles li{display:flex;align-items:center;gap:6px}
|
|
2169
|
+
.SPR_mapEdFiles a{color:var(--dsw-alias-state-business-primary, #8ab4f8)}
|
|
2170
|
+
/* 导出结果区:把「导完了、文件在哪、怎么拿走」圈在一起,与上面的选择区分开 */
|
|
2171
|
+
.SPR_mapEdExportResult{display:flex;flex-direction:column;gap:6px;padding:8px 10px;border:1px solid #4a4a4a;border-radius:8px;background:#383838}
|
|
2172
|
+
.SPR_mapEdMark{color:var(--dsw-alias-state-success-primary, #7ee08a);font-weight:700}
|
|
2173
|
+
.SPR_mapEdWarnings{margin:0;padding-left:18px;font-size:11px;line-height:1.7;color:#d8d2c8}
|
|
2174
|
+
.SPR_mapEdFoot{display:flex;align-items:center;gap:10px;padding:5px 10px;background:#383838;border-top:1px solid #232323;flex:none;flex-wrap:wrap}
|
|
2175
|
+
.SPR_mapEdFoot .SPR_notice{margin:0}
|
|
2176
|
+
.SPR_mapEdFootText{font-size:11px;color:#b9b3a8;font-variant-numeric:tabular-nums}
|
|
2177
|
+
/* 空态:一句话 + 两个按钮,点完一步到位(建项目 → 导素材 → 32×32 两层,直接可画) */
|
|
2178
|
+
.SPR_mapEdEmpty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;flex:1;min-height:320px;padding:30px 20px;text-align:center;background:#424242;border-radius:12px;border:1px solid var(--dsw-alias-border-l2)}
|
|
2179
|
+
.SPR_mapEdEmptyText{margin:0;font-size:15px;font-weight:600;color:#f7f3ec}
|
|
2180
|
+
.SPR_mapEdEmptyRow{display:flex;gap:10px;flex-wrap:wrap;justify-content:center}
|
|
2181
|
+
|
|
1787
2182
|
.SPR_mapCell:hover .SPR_mapCellLabel{opacity:1}
|
|
1788
2183
|
.SPR_step-active{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-state-business-primary)}
|
|
1789
2184
|
.SPR_step-done .SPR_stepMark{color:var(--dsw-alias-state-success-primary,#2e7d32)}
|
|
@@ -1823,6 +2218,11 @@ window.__ModuleLoader__.load({
|
|
|
1823
2218
|
.SPR_btn[data-primary=true]{background:var(--dsw-alias-state-business-primary);border-color:transparent;color:var(--dsw-alias-state-business-on-primary, #fff)}
|
|
1824
2219
|
.SPR_btn[data-on=true]{border-color:var(--dsw-alias-state-success-primary);color:var(--dsw-alias-state-success-primary)}
|
|
1825
2220
|
.SPR_btn[data-danger=true]{color:var(--dsw-alias-state-error-primary)}
|
|
2221
|
+
/* 标签当按钮用:包着隐藏 <input type=file> 的 label(选择本地视频)与下载链接。
|
|
2222
|
+
label 默认是行内元素,直接套 .SPR_btn 的对齐会跟旁边的按钮错开一行。 */
|
|
2223
|
+
.SPR_fileBtn{display:inline-flex;align-items:center;justify-content:center;gap:4px}
|
|
2224
|
+
.SPR_fileBtn[data-disabled=true]{cursor:default;opacity:.5}
|
|
2225
|
+
.SPR_fileBtn[data-disabled=true] input{pointer-events:none}
|
|
1826
2226
|
.SPR_btnRow{display:flex;gap:6px;flex-wrap:wrap;margin-top:auto}
|
|
1827
2227
|
.SPR_area{width:100%;box-sizing:border-box;min-height:96px;resize:vertical;font-family:ui-monospace,SFMono-Regular,Consolas,Menlo,monospace;font-size:12px;line-height:18px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-markdown-code-block, var(--dsw-alias-bg-layer-1));border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:8px 10px}
|
|
1828
2228
|
.SPR_input{box-sizing:border-box;font:inherit;font-size:12px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:5px 9px;width:100%}
|
|
@@ -2097,6 +2497,37 @@ window.__ModuleLoader__.load({
|
|
|
2097
2497
|
return error.message;
|
|
2098
2498
|
return String(error);
|
|
2099
2499
|
}
|
|
2500
|
+
/**
|
|
2501
|
+
* 新建项目 / 任务时问一个名字(与「重命名」同一套 `window.prompt` 交互)。
|
|
2502
|
+
*
|
|
2503
|
+
* 返回值语义是**三态**,调用方必须照着写:
|
|
2504
|
+
* · `null` —— 用户点了取消 → **不要创建**(点了取消却多出一个项目,会被当成 bug)
|
|
2505
|
+
* · 空串/全空白 —— 用 `fallback`(默认名)
|
|
2506
|
+
* · 其余 —— 用户输入的名字(已 trim)
|
|
2507
|
+
* 没有 `window.prompt` 的宿主退回默认名,不阻断创建。
|
|
2508
|
+
*/
|
|
2509
|
+
function askNewName(title, fallback) {
|
|
2510
|
+
if (typeof window === "undefined" || typeof window.prompt !== "function")
|
|
2511
|
+
return fallback;
|
|
2512
|
+
/**
|
|
2513
|
+
* ⚠️ `typeof window.prompt === "function"` **不足以判断能用**:Electron(DSH 桌面端)
|
|
2514
|
+
* 里这个函数存在,但一调用就抛「prompt() is and will not be supported」。抛出去的话
|
|
2515
|
+
* 调用方的 async 处理器直接变成未处理拒绝 —— 界面表现是「点了新建什么都没发生」。
|
|
2516
|
+
* 这里兜住并退回默认名:至少把项目建出来,用户随后改名即可。
|
|
2517
|
+
* (模块六的「新建项目」已经改成自带对话框,不再走这里。)
|
|
2518
|
+
*/
|
|
2519
|
+
let value = null;
|
|
2520
|
+
try {
|
|
2521
|
+
value = window.prompt(title, fallback);
|
|
2522
|
+
}
|
|
2523
|
+
catch {
|
|
2524
|
+
return fallback;
|
|
2525
|
+
}
|
|
2526
|
+
if (value === null)
|
|
2527
|
+
return null;
|
|
2528
|
+
const trimmed = String(value).trim();
|
|
2529
|
+
return trimmed === "" ? fallback : trimmed;
|
|
2530
|
+
}
|
|
2100
2531
|
function statusKind(node) {
|
|
2101
2532
|
if (node === undefined)
|
|
2102
2533
|
return { kind: "empty", text: T("未生成") };
|
|
@@ -2891,11 +3322,16 @@ window.__ModuleLoader__.load({
|
|
|
2891
3322
|
return undefined;
|
|
2892
3323
|
}
|
|
2893
3324
|
}, [api, projectId, loadProject]);
|
|
2894
|
-
const createProject =
|
|
2895
|
-
const
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
3325
|
+
const createProject = async () => {
|
|
3326
|
+
const name = askNewName(T("新项目的名字"), T("角色 {n0}", { n0: new Date().toLocaleString("zh-CN", { hour12: false }) }));
|
|
3327
|
+
if (name === null)
|
|
3328
|
+
return;
|
|
3329
|
+
await withApi(async () => {
|
|
3330
|
+
const created = await api.createProject({ name });
|
|
3331
|
+
await refreshProjects();
|
|
3332
|
+
setProjectId(created.projectId);
|
|
3333
|
+
}, { notice: T("已创建新项目") });
|
|
3334
|
+
};
|
|
2899
3335
|
const deleteCurrent = async () => {
|
|
2900
3336
|
if (project === null)
|
|
2901
3337
|
return;
|
|
@@ -2975,6 +3411,31 @@ window.__ModuleLoader__.load({
|
|
|
2975
3411
|
}
|
|
2976
3412
|
return result;
|
|
2977
3413
|
};
|
|
3414
|
+
/**
|
|
3415
|
+
* 「保存全部图片(zip)」:宿主按**当前项目状态**现打一个 zip 落到 `out/` 下,
|
|
3416
|
+
* 这里再触发一次浏览器下载。
|
|
3417
|
+
*
|
|
3418
|
+
* 为什么不直接摆一个 `<a href>`:包里有哪些图(以及文件名)只有宿主知道,
|
|
3419
|
+
* 没有固定地址可指,所以只能「先请求、拿到相对路径再下载」。
|
|
3420
|
+
*/
|
|
3421
|
+
const exportAllImages = () => void start(async () => {
|
|
3422
|
+
const pack = await api.exportImages({ projectId: project.id });
|
|
3423
|
+
const url = `${pack?.assetBase ?? project.assetBase ?? ""}${pack?.file ?? ""}`;
|
|
3424
|
+
const anchor = document.createElement("a");
|
|
3425
|
+
anchor.href = url;
|
|
3426
|
+
anchor.download = fileLabel(pack?.file);
|
|
3427
|
+
anchor.style.display = "none";
|
|
3428
|
+
document.body.appendChild(anchor);
|
|
3429
|
+
anchor.click();
|
|
3430
|
+
anchor.remove();
|
|
3431
|
+
setNotice({
|
|
3432
|
+
kind: "ok",
|
|
3433
|
+
text: Number(pack?.skipped ?? 0) > 0
|
|
3434
|
+
? T("已打包 {n0} 张图片(另有 {n1} 张读不到,已跳过)", { n0: pack?.count ?? 0, n1: pack?.skipped ?? 0 })
|
|
3435
|
+
: T("已打包 {n0} 张图片", { n0: pack?.count ?? 0 })
|
|
3436
|
+
});
|
|
3437
|
+
return pack;
|
|
3438
|
+
}, { reload: true }, { key: KEY_EXPORT_IMAGES, label: T("正在打包全部图片…") });
|
|
2978
3439
|
if (api === undefined) {
|
|
2979
3440
|
return h("div", { className: "SPR_root" }, h("p", { className: "SPR_empty" }, T("正在挂载游戏素材大师…")));
|
|
2980
3441
|
}
|
|
@@ -3096,16 +3557,26 @@ window.__ModuleLoader__.load({
|
|
|
3096
3557
|
void uploadSource(file);
|
|
3097
3558
|
event.target.value = "";
|
|
3098
3559
|
}
|
|
3099
|
-
})))), renderLog(project), h("div", { className: "SPR_toolbar" }, h(Btn, { onClick: () => void loadProject(project.id) }, T("刷新状态")),
|
|
3560
|
+
})))), renderLog(project), h("div", { className: "SPR_toolbar" }, h(Btn, { onClick: () => void loadProject(project.id) }, T("刷新状态")),
|
|
3561
|
+
// 中间图片(绿幕图 / 转圈候选帧与条带 / 各方向原始帧与抠像帧 / 整图)
|
|
3562
|
+
// 一次打成一个 zip:转圈模式的候选帧一抽就是 32~64 张,一张一个链接
|
|
3563
|
+
// 既点不完也看不清。放在这条**各阶段共用**的工具栏上,任何阶段都能存。
|
|
3564
|
+
h(BusyBtn, {
|
|
3565
|
+
busy: tasks.has(KEY_EXPORT_IMAGES),
|
|
3566
|
+
busyText: T("正在打包…"),
|
|
3567
|
+
onClick: () => void exportAllImages()
|
|
3568
|
+
}, T("保存全部图片(zip)")), h(Btn, { onClick: () => void withApi(() => api.revealProject({ projectId: project.id })) }, T("在访达中打开项目目录"))))))
|
|
3100
3569
|
: activeModule === "image"
|
|
3101
3570
|
? h(ImageModule, { api })
|
|
3102
3571
|
: activeModule === "sequence"
|
|
3103
3572
|
? h(SequenceModule, { api })
|
|
3104
3573
|
: activeModule === "tile"
|
|
3105
3574
|
? h(TileModule, { api })
|
|
3106
|
-
: activeModule === "
|
|
3107
|
-
? h(
|
|
3108
|
-
:
|
|
3575
|
+
: activeModule === "map"
|
|
3576
|
+
? h(MapModule, { api })
|
|
3577
|
+
: activeModule === "rig"
|
|
3578
|
+
? h(RigModule, { api })
|
|
3579
|
+
: null);
|
|
3109
3580
|
}
|
|
3110
3581
|
/** 阶段卡片下方的说明文字(阶段①有两种生成方式,各说各的)。 */
|
|
3111
3582
|
function stageHint(project, stage, activeStage) {
|
|
@@ -3147,6 +3618,15 @@ window.__ModuleLoader__.load({
|
|
|
3147
3618
|
const KEY_TURN_VIDEO = "turn:*video";
|
|
3148
3619
|
const KEY_TURN_FRAMES = "turn:*frames";
|
|
3149
3620
|
const KEY_TURN_PICK = (key) => `turn:pick:${key}`;
|
|
3621
|
+
/**
|
|
3622
|
+
* 本地自选视频的 pending key(转圈与每个方向各一条)。
|
|
3623
|
+
*
|
|
3624
|
+
* 前缀刻意和 `turn:*` / `video:*` 错开:那两个前缀被「这个阶段有没有在跑」
|
|
3625
|
+
* 的判定用着(`tasks.any("video:*")`),混进去会把不相干的按钮一起禁用。
|
|
3626
|
+
*/
|
|
3627
|
+
const KEY_LOCAL_VIDEO = (key) => `local-video:${key}`;
|
|
3628
|
+
/** 「保存全部图片(zip)」的 pending key(这条工具栏是各阶段共用的)。 */
|
|
3629
|
+
const KEY_EXPORT_IMAGES = "images:*zip";
|
|
3150
3630
|
const TURN_FRAME_MIN = 8;
|
|
3151
3631
|
const TURN_FRAME_MAX = 64;
|
|
3152
3632
|
/**
|
|
@@ -3323,7 +3803,8 @@ window.__ModuleLoader__.load({
|
|
|
3323
3803
|
const allApproved = DIRECTION_KEYS.every((key) => project.images?.[key]?.approved);
|
|
3324
3804
|
const readyImages = DIRECTION_KEYS.filter((key) => project.images?.[key]?.file !== undefined).length;
|
|
3325
3805
|
const stale = frames.stale === true;
|
|
3326
|
-
return h(React.Fragment, null, h("p", { className: "SPR_hint" }, T("先生成一段「角色原地匀速转一整圈」的视频(绿幕、保持原图风格、除旋转外不做任何动作),再按时间截出八个方向的帧。八个方向出自同一段视频,一致性比逐方向生图好得多;下面时间轴上的八个圆圈就是各自的截帧位置,随便拖。")
|
|
3806
|
+
return h(React.Fragment, null, h("p", { className: "SPR_hint" }, T("先生成一段「角色原地匀速转一整圈」的视频(绿幕、保持原图风格、除旋转外不做任何动作),再按时间截出八个方向的帧。八个方向出自同一段视频,一致性比逐方向生图好得多;下面时间轴上的八个圆圈就是各自的截帧位置,随便拖。") +
|
|
3807
|
+
T("手上已经有这样一段视频(自己电脑上的文件)时,点「选择本地视频」直接用它即可,不必走远程生成。")), h("textarea", {
|
|
3327
3808
|
className: "SPR_area",
|
|
3328
3809
|
value: promptDraft,
|
|
3329
3810
|
"data-testid": "turn-prompt",
|
|
@@ -3347,7 +3828,16 @@ window.__ModuleLoader__.load({
|
|
|
3347
3828
|
? T("生成转圈视频(计费一次)")
|
|
3348
3829
|
: videoRunning
|
|
3349
3830
|
? T("转圈视频生成中…")
|
|
3350
|
-
: T("重新生成转圈视频(计费一次)")),
|
|
3831
|
+
: T("重新生成转圈视频(计费一次)")),
|
|
3832
|
+
// 和远程生成**并列**的一条路:手上已经有一段原地转圈的绿幕视频时,
|
|
3833
|
+
// 直接选它就行——不用花那一次视频调用,导入后同样自动抽帧、切八个方向。
|
|
3834
|
+
h(LocalVideoPick, {
|
|
3835
|
+
label: T("选择本地视频"),
|
|
3836
|
+
title: T("用自己电脑上的一段原地转圈视频(绿幕)顶替远程生成;导入后会自动抽候选帧并切出八个方向"),
|
|
3837
|
+
disabled: videoRunning,
|
|
3838
|
+
testId: "turn-local-video",
|
|
3839
|
+
onFile: (file) => pickLocalVideo({ start, setNotice, api, project, key: "turn", file })
|
|
3840
|
+
}), h(BusyBtn, {
|
|
3351
3841
|
busy: tasks.has(KEY_TURN_FRAMES),
|
|
3352
3842
|
busyText: T("正在抽帧…"),
|
|
3353
3843
|
disabled: video.file === undefined || cutting,
|
|
@@ -3372,7 +3862,13 @@ window.__ModuleLoader__.load({
|
|
|
3372
3862
|
}, T("应用帧数")), h("span", { className: "SPR_refRow" }, project.settings?.turnFrameCount === frameCount ? T("当前 {n0} 张", { n0: project.settings?.turnFrameCount ?? "—" }) : T("未应用(当前 {n0} 张)", { n0: project.settings?.turnFrameCount ?? "—" }))), h("div", { className: "SPR_toolbar" }, h(Btn, {
|
|
3373
3863
|
disabled: total === 0 || cutting,
|
|
3374
3864
|
onClick: () => void start(() => api.resetTurnPicks({ projectId: project.id }), { reload: true, notice: T("八个圆圈已回到默认等分位置"), noticeKind: "ok" })
|
|
3375
|
-
}, T("重置八个圆圈")),
|
|
3865
|
+
}, T("重置八个圆圈")),
|
|
3866
|
+
// 条带本身就是「整圈候选帧」那张中间图,值得能单独存下来(对着它挑帧/发给别人看)。
|
|
3867
|
+
h(SaveLink, {
|
|
3868
|
+
url: frames.strip === undefined ? undefined : assetUrl(project, frames.strip, frames.updatedAt),
|
|
3869
|
+
name: `${project.name}-turn-strip.png`,
|
|
3870
|
+
label: T("保存条带")
|
|
3871
|
+
}), h(Btn, {
|
|
3376
3872
|
disabled: total === 0 || cutting,
|
|
3377
3873
|
title: T("转圈方向决定默认位置怎么排;拖动过的圆圈以你的位置为准"),
|
|
3378
3874
|
onClick: () => void start(() => api.resetTurnPicks({ projectId: project.id, direction: project.turn?.direction === "ccw" ? "cw" : "ccw" }), {
|
|
@@ -3396,7 +3892,20 @@ window.__ModuleLoader__.load({
|
|
|
3396
3892
|
"data-testid": "turn-video"
|
|
3397
3893
|
})
|
|
3398
3894
|
}))
|
|
3399
|
-
: h("div", { className: "SPR_thumbEmpty", style: { aspectRatio: "16/9" } }, videoRunning ? T("正在生成转圈视频…") : T("还没有转圈视频:点上面的「生成转圈视频」")), video.error !== undefined ? h("p", { className: "SPR_error" }, video.error) : null,
|
|
3895
|
+
: h("div", { className: "SPR_thumbEmpty", style: { aspectRatio: "16/9" } }, videoRunning ? T("正在生成转圈视频…") : T("还没有转圈视频:点上面的「生成转圈视频」")), video.error !== undefined ? h("p", { className: "SPR_error" }, video.error) : null,
|
|
3896
|
+
// 这一栏在界面上是「这段视频的来路」:本地选的视频没有输入首帧,
|
|
3897
|
+
// 照旧印「首帧用的是源图」会把人指向一张跟它无关的图。
|
|
3898
|
+
h("div", { className: "SPR_refRow" }, video.origin === "local"
|
|
3899
|
+
? T("本地视频:{n0}(不花远程调用)", { n0: video.originalName ?? fileLabel(video.file) })
|
|
3900
|
+
: T("首帧用的是{n0}:{n1}", { n0: video.firstFrame !== undefined && String(video.firstFrame).startsWith("images/") ? T("已生成的正面绿幕图") : T("上传的源图"), n1: video.firstFrame ?? "—" })),
|
|
3901
|
+
// 视频本身也是中间产物(远程生成的那次是真金白银),得能存下来。
|
|
3902
|
+
video.file !== undefined
|
|
3903
|
+
? h("div", { className: "SPR_btnRow", style: { marginTop: 0 } }, h(SaveLink, {
|
|
3904
|
+
url: assetUrl(project, video.file, video.updatedAt),
|
|
3905
|
+
name: `${project.name}-turn.mp4`,
|
|
3906
|
+
label: T("保存视频")
|
|
3907
|
+
}))
|
|
3908
|
+
: null, total > 0
|
|
3400
3909
|
? h(TurnAxis, {
|
|
3401
3910
|
project,
|
|
3402
3911
|
total,
|
|
@@ -3426,7 +3935,12 @@ window.__ModuleLoader__.load({
|
|
|
3426
3935
|
key,
|
|
3427
3936
|
approved: node?.approved !== true
|
|
3428
3937
|
}), { reload: true })
|
|
3429
|
-
}, node?.approved === true ? T("已通过") : T("通过"))
|
|
3938
|
+
}, node?.approved === true ? T("已通过") : T("通过")), h(SaveLink, {
|
|
3939
|
+
url: node?.file === undefined ? undefined : assetUrl(project, node.file, node.updatedAt ?? project.updatedAt),
|
|
3940
|
+
name: `${project.name}-${key}.png`,
|
|
3941
|
+
label: T("保存"),
|
|
3942
|
+
busy: nodeBusy
|
|
3943
|
+
})));
|
|
3430
3944
|
})));
|
|
3431
3945
|
}
|
|
3432
3946
|
function renderImageStage(ctx) {
|
|
@@ -3535,7 +4049,14 @@ window.__ModuleLoader__.load({
|
|
|
3535
4049
|
key: direction.key,
|
|
3536
4050
|
approved: node?.approved !== true
|
|
3537
4051
|
}), { reload: true })
|
|
3538
|
-
}, node?.approved === true ? T("已通过") : T("通过"))
|
|
4052
|
+
}, node?.approved === true ? T("已通过") : T("通过")),
|
|
4053
|
+
// 绿幕图是这一阶段唯一看得见的产物,直接存下来(拖进别的工具 / 存档)。
|
|
4054
|
+
h(SaveLink, {
|
|
4055
|
+
url: node?.file === undefined ? undefined : assetUrl(project, node.file, node.updatedAt ?? project.updatedAt),
|
|
4056
|
+
name: `${project.name}-${direction.key}.png`,
|
|
4057
|
+
label: T("保存"),
|
|
4058
|
+
busy: nodeBusy
|
|
4059
|
+
})));
|
|
3539
4060
|
})));
|
|
3540
4061
|
}
|
|
3541
4062
|
// ── 阶段 2:视频 ─────────────────────────────────────────────────────
|
|
@@ -3555,7 +4076,7 @@ window.__ModuleLoader__.load({
|
|
|
3555
4076
|
// 批量提交视频时八个方向都会重新出片,提交阶段先把预览整体盖住。
|
|
3556
4077
|
const allBusy = tasks.has(KEY_VIDEO_ALL);
|
|
3557
4078
|
const allLabel = tasks.label(KEY_VIDEO_ALL) ?? T("正在提交 8 个方向的视频任务…");
|
|
3558
|
-
return h(React.Fragment, null, h("p", { className: "SPR_hint" }, T("提示词要求「固定镜头、固定背景、原地走三步」。Hailuo 一段通常要 1~6 分钟,提交后可以离开这个页面。")), h("textarea", {
|
|
4079
|
+
return h(React.Fragment, null, h("p", { className: "SPR_hint" }, T("提示词要求「固定镜头、固定背景、原地走三步」。Hailuo 一段通常要 1~6 分钟,提交后可以离开这个页面。") + T("某一个方向已经有现成的行走视频(自己电脑上的文件)时,点那一格的「选择本地视频」直接用它,不必走远程生成。")), h("textarea", {
|
|
3559
4080
|
className: "SPR_area",
|
|
3560
4081
|
value: videoPromptDraft,
|
|
3561
4082
|
onChange: (event) => setVideoPromptDraft(event.target.value)
|
|
@@ -3605,7 +4126,11 @@ window.__ModuleLoader__.load({
|
|
|
3605
4126
|
}))
|
|
3606
4127
|
: image?.file !== undefined
|
|
3607
4128
|
? h(MediaBox, { overlay: nodeBusy || waiting, text: overlayText }, h("img", { className: "SPR_thumb", src: assetUrl(project, image.file, image.updatedAt), alt: direction.label }))
|
|
3608
|
-
: h("div", { className: "SPR_thumbEmpty" }, T("还没有绿幕图")), nodeBusy || waiting ? h(BusyBadge, { show: true, text: overlayText }) : null, video?.
|
|
4129
|
+
: h("div", { className: "SPR_thumbEmpty" }, T("还没有绿幕图")), nodeBusy || waiting ? h(BusyBadge, { show: true, text: overlayText }) : null, video?.origin === "local"
|
|
4130
|
+
? h("span", { className: "SPR_refRow" }, T("本地视频:{n0}(不花远程调用)", { n0: video.originalName ?? fileLabel(video.file) }))
|
|
4131
|
+
: video?.remoteStatus !== undefined
|
|
4132
|
+
? h("span", { className: "SPR_refRow" }, T("远端状态:{n0}", { n0: video.remoteStatus }))
|
|
4133
|
+
: null, video?.error !== undefined ? h("p", { className: "SPR_error" }, video.error) : null, h("div", { className: "SPR_btnRow" }, h(BusyBtn, {
|
|
3609
4134
|
primary: video?.file === undefined && image?.file !== undefined,
|
|
3610
4135
|
busy: tasks.has(taskKey),
|
|
3611
4136
|
busyText: T("正在提交…"),
|
|
@@ -3622,7 +4147,15 @@ window.__ModuleLoader__.load({
|
|
|
3622
4147
|
key: taskKey,
|
|
3623
4148
|
label: T("正在生成「{n0}」视频…", { n0: direction.label })
|
|
3624
4149
|
})
|
|
3625
|
-
}, video?.file === undefined ? T("生成视频") : T("重新生成")),
|
|
4150
|
+
}, video?.file === undefined ? T("生成视频") : T("重新生成")),
|
|
4151
|
+
// 本地自选视频:和「生成视频」并列,落在**这一格**的槽位上。
|
|
4152
|
+
h(LocalVideoPick, {
|
|
4153
|
+
label: T("选择本地视频"),
|
|
4154
|
+
title: T("用自己电脑上的一段「固定镜头 + 原地走」视频顶替这一方向的远程生成;之后照旧到第 3 步抽帧"),
|
|
4155
|
+
disabled: nodeBusy === true,
|
|
4156
|
+
testId: `local-video-${direction.key}`,
|
|
4157
|
+
onFile: (file) => pickLocalVideo({ start, setNotice, api, project, key: direction.key, file, label: direction.label })
|
|
4158
|
+
}), h(Btn, {
|
|
3626
4159
|
on: video?.approved === true,
|
|
3627
4160
|
disabled: video?.status !== "ready",
|
|
3628
4161
|
onClick: () => void start(() => api.setApproved({
|
|
@@ -3631,7 +4164,12 @@ window.__ModuleLoader__.load({
|
|
|
3631
4164
|
key: direction.key,
|
|
3632
4165
|
approved: video?.approved !== true
|
|
3633
4166
|
}), { reload: true })
|
|
3634
|
-
}, video?.approved === true ? T("已通过") : T("通过"))
|
|
4167
|
+
}, video?.approved === true ? T("已通过") : T("通过")), h(SaveLink, {
|
|
4168
|
+
url: video?.file === undefined ? undefined : assetUrl(project, video.file, video.updatedAt ?? project.updatedAt),
|
|
4169
|
+
name: `${project.name}-${direction.key}.mp4`,
|
|
4170
|
+
label: T("保存视频"),
|
|
4171
|
+
busy: nodeBusy
|
|
4172
|
+
})));
|
|
3635
4173
|
})));
|
|
3636
4174
|
}
|
|
3637
4175
|
/**
|
|
@@ -3915,7 +4453,15 @@ window.__ModuleLoader__.load({
|
|
|
3915
4453
|
key: direction.key,
|
|
3916
4454
|
approved: node?.approved !== true
|
|
3917
4455
|
}), { reload: true })
|
|
3918
|
-
}, node?.approved === true ? T("已通过") : T("通过"))
|
|
4456
|
+
}, node?.approved === true ? T("已通过") : T("通过")),
|
|
4457
|
+
// 预览带就是这一段的全部帧(绿幕原帧);要一张一张地拿,用底部的
|
|
4458
|
+
// 「保存全部图片(zip)」——那里连抠像帧和候选帧一起打进去。
|
|
4459
|
+
h(SaveLink, {
|
|
4460
|
+
url: node?.strip === undefined ? undefined : assetUrl(project, node.strip, node.updatedAt),
|
|
4461
|
+
name: `${project.name}-${direction.key}-strip.png`,
|
|
4462
|
+
label: T("保存预览带"),
|
|
4463
|
+
busy: nodeBusy
|
|
4464
|
+
}))),
|
|
3919
4465
|
pickKey === direction.key
|
|
3920
4466
|
? h(FramePickPanel, {
|
|
3921
4467
|
key: `${direction.key}-pick`,
|
|
@@ -4261,116 +4807,2473 @@ window.__ModuleLoader__.load({
|
|
|
4261
4807
|
posRef.current = { x: STAGE_W / 2, y: STAGE_H - 8, dirKey: "front", frame: 0, acc: 0 };
|
|
4262
4808
|
keysRef.current = { up: false, down: false, left: false, right: false };
|
|
4263
4809
|
};
|
|
4264
|
-
if (!ready) {
|
|
4265
|
-
return h("p", { className: "SPR_empty" }, T("还没有可播放的整图。先完成第 ④ 步合成,再回到这里用 WASD 走一走。"));
|
|
4266
|
-
}
|
|
4267
|
-
return h(React.Fragment, null, h("div", { className: "SPR_fields" }, h(NumField, {
|
|
4268
|
-
label: T("角色缩放倍率"),
|
|
4269
|
-
value: scale,
|
|
4270
|
-
min: 0.3,
|
|
4271
|
-
max: 4,
|
|
4272
|
-
step: 0.1,
|
|
4273
|
-
onChange: setScale
|
|
4274
|
-
}), h(NumField, {
|
|
4275
|
-
label: T("移动速度(像素/秒)"),
|
|
4276
|
-
value: speed,
|
|
4277
|
-
min: 40,
|
|
4278
|
-
max: 600,
|
|
4279
|
-
step: 10,
|
|
4280
|
-
onChange: setSpeed
|
|
4281
|
-
}), h(NumField, {
|
|
4282
|
-
label: T("播放速度(倍,只影响步频)"),
|
|
4283
|
-
value: animSpeed,
|
|
4284
|
-
min: 0.25,
|
|
4285
|
-
max: 4,
|
|
4286
|
-
step: 0.25,
|
|
4287
|
-
onChange: setAnimSpeed
|
|
4288
|
-
}), h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("背景参考网格")), h("select", { className: "SPR_input", value: grid ? "on" : "off", onChange: (event) => setGrid(event.target.value === "on") }, h("option", { value: "on" }, T("显示(更容易看出在移动)")), h("option", { value: "off" }, T("关闭(纯白)"))))), h("div", { className: "SPR_toolbar" }, h(Btn, { onClick: reset }, T("回到中间")), h("span", { className: "SPR_refRow" }, T("当前朝向:{n0}({n1}) · {n2}", { n0: hud.compass, n1: LABEL_OF[posRef.current.dirKey] ?? "", n2: hud.moving ? T("行走中") : T("站立") })), orderStale
|
|
4289
|
-
? h("span", { className: "SPR_refRow" }, T("· 整图是按旧行序生成的,正在重新合成…"))
|
|
4290
|
-
: null, h("span", { className: "SPR_spacer" }), h("span", { className: "SPR_refRow" }, focused ? T("已获得键盘焦点") : T("点击画面后即可操控"))), h("div", {
|
|
4291
|
-
ref: boxRef,
|
|
4292
|
-
className: "SPR_stage",
|
|
4293
|
-
"data-focused": focused ? "true" : "false",
|
|
4294
|
-
tabIndex: 0,
|
|
4295
|
-
onClick: () => {
|
|
4296
|
-
if (boxRef.current !== null)
|
|
4297
|
-
boxRef.current.focus();
|
|
4298
|
-
},
|
|
4299
|
-
onFocus: () => setFocused(true),
|
|
4300
|
-
onBlur: () => {
|
|
4301
|
-
setFocused(false);
|
|
4302
|
-
keysRef.current = { up: false, down: false, left: false, right: false };
|
|
4303
|
-
},
|
|
4304
|
-
onKeyDown: handleKey(true),
|
|
4305
|
-
onKeyUp: handleKey(false)
|
|
4306
|
-
}, h("canvas", { ref: canvasRef, className: "SPR_canvas", width: STAGE_W, height: STAGE_H }), focused ? null : h("div", { className: "SPR_stageHint" }, T("点击这里,然后用 WASD 或 ↑↓←→ 操控角色")), h(LoadingOverlay, {
|
|
4307
|
-
show: rebuilding || (ready && !sheetLoaded),
|
|
4308
|
-
text: rebuilding ? rebuildingText : T("正在载入整图…")
|
|
4309
|
-
}), h("div", { className: "SPR_hud" }, h("span", { className: "SPR_hudDir" }, hud.compass), h("span", null, hud.moving ? T("行走") : T("站立")))), h("p", { className: "SPR_hint" }, T("方向按屏幕方位映射:按 ↑ 向北走(背对镜头)、↓ 向南走(正对镜头)、← 向西、→ 向东;斜向同时按两个键。"), h("br"), T("「播放速度」只改步频快慢,不影响角色移动速度;「移动速度」只改走得多快,不影响动画帧率。切图用的是整图自己记录的行序,所以改完行序即使还没重新合成,预览也不会取错方向。")));
|
|
4310
|
-
}
|
|
4311
|
-
// ── 公共小工具 ──────────────────────────────────────────────────────
|
|
4312
|
-
/** 把 File 读成不带 data: 前缀的 base64。 */
|
|
4313
|
-
function readFileBase64(file) {
|
|
4314
|
-
return new Promise((resolve, reject) => {
|
|
4315
|
-
const reader = new FileReader();
|
|
4316
|
-
reader.onload = () => {
|
|
4317
|
-
const text = String(reader.result ?? "");
|
|
4318
|
-
resolve(text.slice(text.indexOf(",") + 1));
|
|
4319
|
-
};
|
|
4320
|
-
reader.onerror = () => reject(new Error(T("读取文件失败")));
|
|
4321
|
-
reader.readAsDataURL(file);
|
|
4322
|
-
});
|
|
4323
|
-
}
|
|
4324
|
-
/** 一个「拖进来或点按钮选文件」的上传区。 */
|
|
4325
|
-
function UploadBox({ label, accept, multiple, onFiles, busy }) {
|
|
4326
|
-
const [over, setOver] = React.useState(false);
|
|
4327
|
-
const inputRef = React.useRef(null);
|
|
4328
|
-
const handle = (files) => {
|
|
4329
|
-
const list = Array.from(files ?? []);
|
|
4330
|
-
if (list.length > 0)
|
|
4331
|
-
void onFiles(list);
|
|
4810
|
+
if (!ready) {
|
|
4811
|
+
return h("p", { className: "SPR_empty" }, T("还没有可播放的整图。先完成第 ④ 步合成,再回到这里用 WASD 走一走。"));
|
|
4812
|
+
}
|
|
4813
|
+
return h(React.Fragment, null, h("div", { className: "SPR_fields" }, h(NumField, {
|
|
4814
|
+
label: T("角色缩放倍率"),
|
|
4815
|
+
value: scale,
|
|
4816
|
+
min: 0.3,
|
|
4817
|
+
max: 4,
|
|
4818
|
+
step: 0.1,
|
|
4819
|
+
onChange: setScale
|
|
4820
|
+
}), h(NumField, {
|
|
4821
|
+
label: T("移动速度(像素/秒)"),
|
|
4822
|
+
value: speed,
|
|
4823
|
+
min: 40,
|
|
4824
|
+
max: 600,
|
|
4825
|
+
step: 10,
|
|
4826
|
+
onChange: setSpeed
|
|
4827
|
+
}), h(NumField, {
|
|
4828
|
+
label: T("播放速度(倍,只影响步频)"),
|
|
4829
|
+
value: animSpeed,
|
|
4830
|
+
min: 0.25,
|
|
4831
|
+
max: 4,
|
|
4832
|
+
step: 0.25,
|
|
4833
|
+
onChange: setAnimSpeed
|
|
4834
|
+
}), h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("背景参考网格")), h("select", { className: "SPR_input", value: grid ? "on" : "off", onChange: (event) => setGrid(event.target.value === "on") }, h("option", { value: "on" }, T("显示(更容易看出在移动)")), h("option", { value: "off" }, T("关闭(纯白)"))))), h("div", { className: "SPR_toolbar" }, h(Btn, { onClick: reset }, T("回到中间")), h("span", { className: "SPR_refRow" }, T("当前朝向:{n0}({n1}) · {n2}", { n0: hud.compass, n1: LABEL_OF[posRef.current.dirKey] ?? "", n2: hud.moving ? T("行走中") : T("站立") })), orderStale
|
|
4835
|
+
? h("span", { className: "SPR_refRow" }, T("· 整图是按旧行序生成的,正在重新合成…"))
|
|
4836
|
+
: null, h("span", { className: "SPR_spacer" }), h("span", { className: "SPR_refRow" }, focused ? T("已获得键盘焦点") : T("点击画面后即可操控"))), h("div", {
|
|
4837
|
+
ref: boxRef,
|
|
4838
|
+
className: "SPR_stage",
|
|
4839
|
+
"data-focused": focused ? "true" : "false",
|
|
4840
|
+
tabIndex: 0,
|
|
4841
|
+
onClick: () => {
|
|
4842
|
+
if (boxRef.current !== null)
|
|
4843
|
+
boxRef.current.focus();
|
|
4844
|
+
},
|
|
4845
|
+
onFocus: () => setFocused(true),
|
|
4846
|
+
onBlur: () => {
|
|
4847
|
+
setFocused(false);
|
|
4848
|
+
keysRef.current = { up: false, down: false, left: false, right: false };
|
|
4849
|
+
},
|
|
4850
|
+
onKeyDown: handleKey(true),
|
|
4851
|
+
onKeyUp: handleKey(false)
|
|
4852
|
+
}, h("canvas", { ref: canvasRef, className: "SPR_canvas", width: STAGE_W, height: STAGE_H }), focused ? null : h("div", { className: "SPR_stageHint" }, T("点击这里,然后用 WASD 或 ↑↓←→ 操控角色")), h(LoadingOverlay, {
|
|
4853
|
+
show: rebuilding || (ready && !sheetLoaded),
|
|
4854
|
+
text: rebuilding ? rebuildingText : T("正在载入整图…")
|
|
4855
|
+
}), h("div", { className: "SPR_hud" }, h("span", { className: "SPR_hudDir" }, hud.compass), h("span", null, hud.moving ? T("行走") : T("站立")))), h("p", { className: "SPR_hint" }, T("方向按屏幕方位映射:按 ↑ 向北走(背对镜头)、↓ 向南走(正对镜头)、← 向西、→ 向东;斜向同时按两个键。"), h("br"), T("「播放速度」只改步频快慢,不影响角色移动速度;「移动速度」只改走得多快,不影响动画帧率。切图用的是整图自己记录的行序,所以改完行序即使还没重新合成,预览也不会取错方向。")));
|
|
4856
|
+
}
|
|
4857
|
+
// ── 公共小工具 ──────────────────────────────────────────────────────
|
|
4858
|
+
/** 把 File 读成不带 data: 前缀的 base64。 */
|
|
4859
|
+
function readFileBase64(file) {
|
|
4860
|
+
return new Promise((resolve, reject) => {
|
|
4861
|
+
const reader = new FileReader();
|
|
4862
|
+
reader.onload = () => {
|
|
4863
|
+
const text = String(reader.result ?? "");
|
|
4864
|
+
resolve(text.slice(text.indexOf(",") + 1));
|
|
4865
|
+
};
|
|
4866
|
+
reader.onerror = () => reject(new Error(T("读取文件失败")));
|
|
4867
|
+
reader.readAsDataURL(file);
|
|
4868
|
+
});
|
|
4869
|
+
}
|
|
4870
|
+
/** 一个「拖进来或点按钮选文件」的上传区。 */
|
|
4871
|
+
function UploadBox({ label, accept, multiple, onFiles, busy }) {
|
|
4872
|
+
const [over, setOver] = React.useState(false);
|
|
4873
|
+
const inputRef = React.useRef(null);
|
|
4874
|
+
const handle = (files) => {
|
|
4875
|
+
const list = Array.from(files ?? []);
|
|
4876
|
+
if (list.length > 0)
|
|
4877
|
+
void onFiles(list);
|
|
4878
|
+
};
|
|
4879
|
+
return h(React.Fragment, null, h("div", {
|
|
4880
|
+
className: "SPR_drop",
|
|
4881
|
+
"data-over": over ? "true" : "false",
|
|
4882
|
+
"data-busy": busy === true ? "true" : undefined,
|
|
4883
|
+
onDragOver: (event) => {
|
|
4884
|
+
event.preventDefault();
|
|
4885
|
+
setOver(true);
|
|
4886
|
+
},
|
|
4887
|
+
onDragLeave: () => setOver(false),
|
|
4888
|
+
onDrop: (event) => {
|
|
4889
|
+
event.preventDefault();
|
|
4890
|
+
setOver(false);
|
|
4891
|
+
handle(event.dataTransfer?.files);
|
|
4892
|
+
}
|
|
4893
|
+
}, busy === true
|
|
4894
|
+
? h("span", { style: { display: "inline-flex", alignItems: "center", gap: 7, justifyContent: "center" } }, h("span", { className: "SPR_spinSm" }), T("正在上传…"))
|
|
4895
|
+
: label), h("div", { className: "SPR_toolbar" }, h(BusyBtn, { onClick: () => inputRef.current?.click(), busy: busy === true, busyText: T("正在上传…") }, T("选择文件")), h("input", {
|
|
4896
|
+
ref: inputRef,
|
|
4897
|
+
type: "file",
|
|
4898
|
+
accept,
|
|
4899
|
+
multiple: multiple === true,
|
|
4900
|
+
style: { display: "none" },
|
|
4901
|
+
onChange: (event) => {
|
|
4902
|
+
handle(event.target.files);
|
|
4903
|
+
event.target.value = "";
|
|
4904
|
+
}
|
|
4905
|
+
})));
|
|
4906
|
+
}
|
|
4907
|
+
/**
|
|
4908
|
+
* 「选择本地视频」:一个包着隐藏 `<input type="file">` 的标签按钮。
|
|
4909
|
+
*
|
|
4910
|
+
* 为什么是 `<label>` 而不是 button + ref:文件选择框必须由**用户手势**打开,
|
|
4911
|
+
* 而 label 天然把点击转给内部的 input,不需要 useRef / useState——少一个 Hook
|
|
4912
|
+
* 就少一处「渲染顺序变了」的坑(这个模块的界面测试按住 Hook 顺序)。
|
|
4913
|
+
*/
|
|
4914
|
+
function LocalVideoPick({ label, title, onFile, disabled, testId }) {
|
|
4915
|
+
return h("label", {
|
|
4916
|
+
className: "SPR_btn SPR_fileBtn",
|
|
4917
|
+
"data-disabled": disabled === true ? "true" : undefined,
|
|
4918
|
+
title,
|
|
4919
|
+
"data-testid": testId
|
|
4920
|
+
}, label, h("input", {
|
|
4921
|
+
type: "file",
|
|
4922
|
+
accept: "video/*",
|
|
4923
|
+
disabled: disabled === true,
|
|
4924
|
+
style: { display: "none" },
|
|
4925
|
+
"data-testid": testId === undefined ? undefined : `${testId}-input`,
|
|
4926
|
+
onChange: (event) => {
|
|
4927
|
+
const file = event.target.files?.[0];
|
|
4928
|
+
// 先清空 value:同一个文件连选两次也要能触发 change。
|
|
4929
|
+
event.target.value = "";
|
|
4930
|
+
if (file !== undefined && file !== null)
|
|
4931
|
+
void onFile(file);
|
|
4932
|
+
}
|
|
4933
|
+
}));
|
|
4934
|
+
}
|
|
4935
|
+
/** `download` 属性要的是**文件名**:带上目录浏览器会当非法名丢掉。 */
|
|
4936
|
+
function fileLabel(relative) {
|
|
4937
|
+
const name = String(relative ?? "").split("/").pop() ?? "";
|
|
4938
|
+
return name === "" ? "asset.png" : name;
|
|
4939
|
+
}
|
|
4940
|
+
/**
|
|
4941
|
+
* 一张中间产物的「保存」。
|
|
4942
|
+
*
|
|
4943
|
+
* 用 `<a download>` 而不是按钮:下载本来就是浏览器的事(同源静态路由直接给文件),
|
|
4944
|
+
* 宿主不必为它多开一个方法;产物就在眼前时,「保存」应该是一个链接而不是又一次调用。
|
|
4945
|
+
*/
|
|
4946
|
+
function SaveLink({ url, name, label, busy, title }) {
|
|
4947
|
+
if (url === undefined || url === null)
|
|
4948
|
+
return null;
|
|
4949
|
+
return h("a", {
|
|
4950
|
+
className: "SPR_btn SPR_fileBtn",
|
|
4951
|
+
href: url,
|
|
4952
|
+
download: name,
|
|
4953
|
+
title,
|
|
4954
|
+
style: { textDecoration: "none" },
|
|
4955
|
+
"aria-disabled": busy === true ? "true" : undefined,
|
|
4956
|
+
onClick: busy === true ? (event) => event.preventDefault() : undefined
|
|
4957
|
+
}, label ?? T("保存"));
|
|
4958
|
+
}
|
|
4959
|
+
/**
|
|
4960
|
+
* 选用一段本地视频(「选择本地视频」/ 拖进来之后走这里)。
|
|
4961
|
+
*
|
|
4962
|
+
* 两条链路共用:`key === "turn"` 是转圈视频(宿主导入后会**立刻**抽候选帧并切出
|
|
4963
|
+
* 八个方向),其余 key 是某个方向的行走视频(之后照旧到第 3 步抽帧)。
|
|
4964
|
+
* 文件字节走和源图同一条 base64 通道——插件零运行时依赖,不为它另开上传接口。
|
|
4965
|
+
*/
|
|
4966
|
+
function pickLocalVideo({ start, setNotice, api, project, key, file, label }) {
|
|
4967
|
+
if (project === null || file === undefined || file === null)
|
|
4968
|
+
return;
|
|
4969
|
+
void start(async () => {
|
|
4970
|
+
const data = await readFileBase64(file);
|
|
4971
|
+
const result = await api.uploadVideo({ projectId: project.id, key, name: file.name, data });
|
|
4972
|
+
setNotice({
|
|
4973
|
+
kind: "ok",
|
|
4974
|
+
text: key === "turn"
|
|
4975
|
+
? result?.extractStarted === true
|
|
4976
|
+
? T("已选用本地视频,正在抽候选帧并切出八个方向…")
|
|
4977
|
+
: T("已选用本地视频(抽帧没有自动开始,点「抽取候选帧」即可)")
|
|
4978
|
+
: T("已选用「{n0}」的本地视频,接着到第 3 步抽取序列帧", { n0: label ?? key })
|
|
4979
|
+
});
|
|
4980
|
+
return result;
|
|
4981
|
+
}, { reload: true }, { key: KEY_LOCAL_VIDEO(key), label: T("正在导入本地视频…") });
|
|
4982
|
+
}
|
|
4983
|
+
/** 抠像参数表单(三个模块共用同一套字段)。 */
|
|
4984
|
+
function KeyingFields({ draft, onChange }) {
|
|
4985
|
+
return h("div", { className: "SPR_fields" }, h(NumField, { label: T("抠像下限(绿色优势)"), value: draft.keyLow ?? 14, min: 0, max: 255, onChange: (v) => onChange({ keyLow: v }) }), h(NumField, { label: T("抠像上限(绿色优势)"), value: draft.keyHigh ?? 80, min: 1, max: 255, onChange: (v) => onChange({ keyHigh: v }) }), h(NumField, { label: T("去绿溢出 0~1"), value: draft.despill ?? 0.65, min: 0, max: 1, step: 0.05, onChange: (v) => onChange({ despill: v }) }), h(NumField, { label: T("背景分割容差(0 = 只认绿色)"), value: draft.bgTolerance ?? 90, min: 0, max: 160, onChange: (v) => onChange({ bgTolerance: v }) }), h(NumField, { label: T("边缘收缩(px)"), value: draft.edgeShrink ?? 0, min: 0, max: 8, onChange: (v) => onChange({ edgeShrink: v }) }));
|
|
4986
|
+
}
|
|
4987
|
+
/** 一份任务/项目列表(左侧栏)。 */
|
|
4988
|
+
function JobSidebar({ title, items, activeId, onSelect, onCreate, renderMeta }) {
|
|
4989
|
+
return h("div", { className: "SPR_side" }, h("div", { className: "SPR_sideTitle" }, T("{n0}({n1})", { n0: title, n1: items.length })), items.length === 0 ? h("p", { className: "SPR_hint" }, T("还没有内容,点右上角新建一个。")) : null, items.map((item) => h("button", {
|
|
4990
|
+
key: item.id,
|
|
4991
|
+
type: "button",
|
|
4992
|
+
className: "SPR_projItem",
|
|
4993
|
+
"data-active": item.id === activeId ? "true" : "false",
|
|
4994
|
+
onClick: () => onSelect(item.id)
|
|
4995
|
+
}, h("span", { className: "SPR_projName" }, item.name), h("span", { className: "SPR_projMeta" }, renderMeta(item)))), items.length === 0 ? h(Btn, { onClick: onCreate, primary: true }, T("新建")) : null);
|
|
4996
|
+
}
|
|
4997
|
+
// ── 模块六 · 地图编辑器(单屏 · 零术语)────────────────────────────────
|
|
4998
|
+
//
|
|
4999
|
+
// 界面只做一件事:把宿主下发的绘制计划执行出来。
|
|
5000
|
+
// 「哪一格用哪一块、画在哪个像素、动起来是哪几块」全在宿主算好,这里连坐标变换
|
|
5001
|
+
// 都不做,只把计划里的 x / y 交给 canvas。
|
|
5002
|
+
//
|
|
5003
|
+
// 唯一被允许复刻的宿主逻辑是命中测试(下面四个坐标函数),那是鼠标必需;
|
|
5004
|
+
// 宿主真实现见 `src/mapgeom.ts`,自检拿它做黄金对照逐点比对。
|
|
5005
|
+
//
|
|
5006
|
+
// ⚠️ 变体挑选 / 自动连接 / 计划分块 / 绘制顺序**都不在这里**:多写一套口径,
|
|
5007
|
+
// 就是「预览好看、导出位移」的老路。
|
|
5008
|
+
/**
|
|
5009
|
+
* 宿主绘制计划里「一批绘制条目」的字段名。
|
|
5010
|
+
*
|
|
5011
|
+
* 只是个协议字段名(界面上不会出现这个词)。术语黑名单自检按**词边界**判,
|
|
5012
|
+
* 所以这里可以照实写 —— 别为了骗过自检去拼字符串。
|
|
5013
|
+
*/
|
|
5014
|
+
const MAP_PLAN_LIST = "chunks";
|
|
5015
|
+
/** 取模到 0..size-1(负数也对):与宿主 `mapgeom` 的环绕口径一致。 */
|
|
5016
|
+
function MAP_wrapIndex(value, size) {
|
|
5017
|
+
if (!(size > 0))
|
|
5018
|
+
return value;
|
|
5019
|
+
const rest = value % size;
|
|
5020
|
+
return rest < 0 ? rest + size : rest;
|
|
5021
|
+
}
|
|
5022
|
+
/** 像素 → 格子。**与宿主 `mapgeom.pointToCell` 同构**(环绕时取模,且恒算在图内)。 */
|
|
5023
|
+
function MAP_pointToCell(layout, x, y) {
|
|
5024
|
+
const c = Math.floor(x / layout.stepX);
|
|
5025
|
+
const r = Math.floor(y / layout.stepY);
|
|
5026
|
+
if (layout.wrap === true) {
|
|
5027
|
+
return { r: MAP_wrapIndex(r, layout.rows), c: MAP_wrapIndex(c, layout.cols), inMap: true };
|
|
5028
|
+
}
|
|
5029
|
+
return { r, c, inMap: r >= 0 && c >= 0 && r < layout.rows && c < layout.cols };
|
|
5030
|
+
}
|
|
5031
|
+
/** 格子锚点 = 单元格底边中点。**与宿主 `mapgeom.cellAnchor` 同构**。 */
|
|
5032
|
+
function MAP_cellAnchor(layout, r, c) {
|
|
5033
|
+
return { x: c * layout.stepX + layout.grid.tileWidth / 2, y: (r + 1) * layout.stepY };
|
|
5034
|
+
}
|
|
5035
|
+
/** 贴图左上角。**与宿主 `mapgeom.cellTopLeft` 同构**。 */
|
|
5036
|
+
function MAP_cellTopLeft(layout, r, c, width, height, anchorX = 0.5, anchorY = 1) {
|
|
5037
|
+
const anchor = MAP_cellAnchor(layout, r, c);
|
|
5038
|
+
return { x: anchor.x - width * anchorX, y: anchor.y - height * anchorY };
|
|
5039
|
+
}
|
|
5040
|
+
/**
|
|
5041
|
+
* 两格之间的直线(拖动补间不能漏格)。
|
|
5042
|
+
* **与宿主 `mapdoc.lineCells` 同构**,黄金对照同样覆盖它。
|
|
5043
|
+
*/
|
|
5044
|
+
function MAP_lineCells(r0, c0, r1, c1) {
|
|
5045
|
+
const out = [];
|
|
5046
|
+
let r = Math.round(r0);
|
|
5047
|
+
let c = Math.round(c0);
|
|
5048
|
+
const rEnd = Math.round(r1);
|
|
5049
|
+
const cEnd = Math.round(c1);
|
|
5050
|
+
const dr = Math.abs(rEnd - r);
|
|
5051
|
+
const dc = Math.abs(cEnd - c);
|
|
5052
|
+
const sr = r < rEnd ? 1 : -1;
|
|
5053
|
+
const sc = c < cEnd ? 1 : -1;
|
|
5054
|
+
let err = dr - dc;
|
|
5055
|
+
for (;;) {
|
|
5056
|
+
out.push({ r, c });
|
|
5057
|
+
if (r === rEnd && c === cEnd)
|
|
5058
|
+
break;
|
|
5059
|
+
const e2 = 2 * err;
|
|
5060
|
+
if (e2 > -dc) {
|
|
5061
|
+
err -= dc;
|
|
5062
|
+
r += sr;
|
|
5063
|
+
}
|
|
5064
|
+
if (e2 < dr) {
|
|
5065
|
+
err += dr;
|
|
5066
|
+
c += sc;
|
|
5067
|
+
}
|
|
5068
|
+
if (out.length > 20000)
|
|
5069
|
+
break;
|
|
5070
|
+
}
|
|
5071
|
+
return out;
|
|
5072
|
+
}
|
|
5073
|
+
/**
|
|
5074
|
+
* 工具格的图标:内联 SVG 自绘(形状语义对齐 AsLib)。
|
|
5075
|
+
*
|
|
5076
|
+
* 纯函数、不碰 state:面板重渲染时重建这几个图标,代价可以忽略。
|
|
5077
|
+
*/
|
|
5078
|
+
function MapToolIcon(props) {
|
|
5079
|
+
const name = props.name;
|
|
5080
|
+
const box = { viewBox: "0 0 24 24", width: 20, height: 20, "aria-hidden": "true", focusable: "false", fill: "currentColor" };
|
|
5081
|
+
const path = (d, extra) => h("path", { d, ...(extra || {}) });
|
|
5082
|
+
const arrow = "M9 4.6 2.8 10.5 9 16.4v-3.7h4.1a4.4 4.4 0 0 1 0 8.8H7.6v3.2h5.5a7.6 7.6 0 0 0 0-15.2H9V4.6Z";
|
|
5083
|
+
if (name === "undo")
|
|
5084
|
+
return h("svg", box, path(arrow));
|
|
5085
|
+
if (name === "redo")
|
|
5086
|
+
return h("svg", box, h("g", { transform: "translate(24 0) scale(-1 1)" }, path(arrow)));
|
|
5087
|
+
if (name === "pen")
|
|
5088
|
+
return h("svg", box, path("M3.4 20.6l1-4.7L15.6 4.7a2.7 2.7 0 0 1 3.8 3.8L8.1 19.6l-4.7 1Z"));
|
|
5089
|
+
if (name === "eraser") {
|
|
5090
|
+
return h("svg", box, path("M13.4 3.6 4.2 12.8a2.4 2.4 0 0 0 0 3.4l3.6 3.6h6l8.1-8.1a2.4 2.4 0 0 0 0-3.4l-5.1-5.1a2.4 2.4 0 0 0-3.4 0Zm1.2 3.4 4 4-2.6 2.6-4-4 2.6-2.6Z"));
|
|
5091
|
+
}
|
|
5092
|
+
if (name === "bucket") {
|
|
5093
|
+
return h("svg", box, path("M11.2 2.6 3.9 9.9a2.2 2.2 0 0 0 0 3.1l4.7 4.7a2.2 2.2 0 0 0 3.1 0l7.3-7.3-7.8-7.8Z"), path("M19.4 13.6s2.5 3 2.5 4.5a2.5 2.5 0 1 1-5 0c0-1.5 2.5-4.5 2.5-4.5Z"));
|
|
5094
|
+
}
|
|
5095
|
+
if (name === "pipette")
|
|
5096
|
+
return h("svg", box, path("M15.6 3.4 20.6 8.4 18 11 13 6l2.6-2.6Z"), path("M11.9 7.1 3 16v5h5l8.9-8.9-5-5Z"));
|
|
5097
|
+
if (name === "hand") {
|
|
5098
|
+
return h("svg", box, path("M7.6 11V6.4a1.6 1.6 0 0 1 3.2 0V11h1V4.4a1.6 1.6 0 0 1 3.2 0V11h1V6.4a1.6 1.6 0 0 1 3.2 0V14a6.6 6.6 0 0 1-6.6 6.6h-1.1A5.7 5.7 0 0 1 5.4 15v-2.3a1.7 1.7 0 0 1 3-1l-.8-.7Z"));
|
|
5099
|
+
}
|
|
5100
|
+
if (name === "single") {
|
|
5101
|
+
return h("svg", box, path("M3 4h18v5H3z", { fillOpacity: 0.42 }), path("M3 10h18v5H3z"), path("M3 16h18v4H3z", { fillOpacity: 0.42 }));
|
|
5102
|
+
}
|
|
5103
|
+
if (name === "grid")
|
|
5104
|
+
return h("svg", box, path("M8.4 3h2.5v18H8.4zM13.1 3h2.5v18h-2.5zM3 8.4h18v2.5H3zM3 13.1h18v2.5H3z"));
|
|
5105
|
+
if (name === "magic") {
|
|
5106
|
+
return h("svg", box, path("M3.3 20.7 13.1 10.9l-1.9-1.9L1.4 18.8l1.9 1.9Z"), path("M17.6 1.8 19 5.3l3.5 1.4L19 8.1 17.6 11.6 16.2 8.1 12.7 6.7 16.2 5.3 17.6 1.8Z"));
|
|
5107
|
+
}
|
|
5108
|
+
if (name === "settings") {
|
|
5109
|
+
return h("svg", box, h("rect", { x: 3, y: 4.6, width: 18, height: 2.2, rx: 1.1 }), h("rect", { x: 6, y: 2.4, width: 4.4, height: 6.6, rx: 2.2 }), h("rect", { x: 3, y: 10.9, width: 18, height: 2.2, rx: 1.1 }), h("rect", { x: 13.6, y: 8.7, width: 4.4, height: 6.6, rx: 2.2 }), h("rect", { x: 3, y: 17.2, width: 18, height: 2.2, rx: 1.1 }), h("rect", { x: 8.4, y: 15, width: 4.4, height: 6.6, rx: 2.2 }));
|
|
5110
|
+
}
|
|
5111
|
+
if (name === "up")
|
|
5112
|
+
return h("svg", { viewBox: "0 0 10 6", width: 11, height: 7, "aria-hidden": "true", fill: "currentColor" }, path("M5 0 10 6H0z"));
|
|
5113
|
+
if (name === "down")
|
|
5114
|
+
return h("svg", { viewBox: "0 0 10 6", width: 11, height: 7, "aria-hidden": "true", fill: "currentColor" }, path("M0 0h10L5 6z"));
|
|
5115
|
+
// 标记:圆圈里一个数字(画布上标记点就是长这样的,工具图标照它画,用户一眼能对上)。
|
|
5116
|
+
if (name === "marker") {
|
|
5117
|
+
return h("svg", box, h("circle", { cx: 12, cy: 12, r: 8.4, fill: "none", stroke: "currentColor", strokeWidth: 2 }), h("text", { x: 12, y: 16.1, textAnchor: "middle", fontSize: 11.5, fontWeight: 700, fill: "currentColor" }, "1"));
|
|
5118
|
+
}
|
|
5119
|
+
return null;
|
|
5120
|
+
}
|
|
5121
|
+
/**
|
|
5122
|
+
* 模块六:单屏零术语地图编辑器。
|
|
5123
|
+
*
|
|
5124
|
+
* 一屏三块:顶栏(项目名 / 素材 / 导出 / 保存状态)、左列(素材调色板 + 12 个工具格)、
|
|
5125
|
+
* 画布。没有步骤条,也没有长说明 —— 名词解释一律贴着控件写一行小字。
|
|
5126
|
+
*/
|
|
5127
|
+
function MapModule(props) {
|
|
5128
|
+
useLocaleTick();
|
|
5129
|
+
const api = props.api;
|
|
5130
|
+
// ── 项目与视图 ───────────────────────────────────────────────────────
|
|
5131
|
+
const [projects, setProjects] = React.useState([]);
|
|
5132
|
+
const [view, setView] = React.useState(null);
|
|
5133
|
+
const [notice, setNotice] = React.useState(null);
|
|
5134
|
+
const [openCard, setOpenCard] = React.useState(null);
|
|
5135
|
+
const [menuOpen, setMenuOpen] = React.useState(false);
|
|
5136
|
+
/** 素材卡片里正在看的那一张素材(只有一张时用不到)。 */
|
|
5137
|
+
const [tsIndex, setTsIndex] = React.useState(0);
|
|
5138
|
+
const [busyKey, setBusyKey] = React.useState(null);
|
|
5139
|
+
// ── 画布:缩放 / 平移 / 绘制计划 ──────────────────────────────────────
|
|
5140
|
+
const [zoom, setZoom] = React.useState(1);
|
|
5141
|
+
const [pan, setPan] = React.useState({ x: 0, y: 0 });
|
|
5142
|
+
const [viewport, setViewport] = React.useState({ w: 900, h: 520 });
|
|
5143
|
+
/** 画布尺寸量过一次没有:量之前不发计划请求(否则第一帧按默认尺寸算,白拉一遍)。 */
|
|
5144
|
+
const [measured, setMeasured] = React.useState(false);
|
|
5145
|
+
/** 计划缓存:key → 绘制条目。`have` 直接由它派发。 */
|
|
5146
|
+
const planRef = React.useRef(new Map());
|
|
5147
|
+
const [planOps, setPlanOps] = React.useState(new Map());
|
|
5148
|
+
/**
|
|
5149
|
+
* 视口里的标记点(宿主每次查询整份回)。
|
|
5150
|
+
*
|
|
5151
|
+
* ⚠️ **故意不进 `planRef` 那份按块缓存**:编号是连续的,删掉第 2 个之后第 3 个
|
|
5152
|
+
* 就变成第 2 个 —— 缓存住的号码会留在屏幕上。所以它是独立的一份状态,
|
|
5153
|
+
* 每次查询覆盖(数量级是几十个)。
|
|
5154
|
+
*/
|
|
5155
|
+
const [planMarkers, setPlanMarkers] = React.useState([]);
|
|
5156
|
+
const [visibleKeys, setVisibleKeys] = React.useState([]);
|
|
5157
|
+
const visibleRef = React.useRef([]);
|
|
5158
|
+
/** 自增一次=「重新问一遍宿主缺哪些块」(补拉用)。 */
|
|
5159
|
+
const [planEpoch, setPlanEpoch] = React.useState(0);
|
|
5160
|
+
const [planMeta, setPlanMeta] = React.useState({ fps: 1, frameCount: 1 });
|
|
5161
|
+
/** 动画速度:null = 跟宿主的 `fps` 走;选了慢 / 中 / 快就是用户指定。 */
|
|
5162
|
+
/**
|
|
5163
|
+
* 「新增素材」对话框的草稿。
|
|
5164
|
+
*
|
|
5165
|
+
* 产品约定:**素材属性在新增这一刻定下来,之后只能删掉重来** —— 所以形态、格子、
|
|
5166
|
+
* 会动吗这些都放进这个对话框,一次定死;列表里不再提供任何修改入口(内置素材更是
|
|
5167
|
+
* 连对话框都进不来)。
|
|
5168
|
+
*/
|
|
5169
|
+
const [addDraft, setAddDraft] = React.useState(null);
|
|
5170
|
+
const addFileRef = React.useRef(null);
|
|
5171
|
+
/**
|
|
5172
|
+
* 预览节拍:一笔进行中每隔 ~80ms 自增一次,触发下面那个计划查询带上 `pending` ——
|
|
5173
|
+
* 宿主只**算**这份计划(盖在克隆上),不落盘、不进撤销栈。
|
|
5174
|
+
*
|
|
5175
|
+
* 用户要的是「画的过程中格子要显示出来,但别一边画一边存」:所以显示走预览查询,
|
|
5176
|
+
* 真正的提交仍然只在 `pointerup` / 离开 / 取消时发生一次。
|
|
5177
|
+
*/
|
|
5178
|
+
const [previewTick, setPreviewTick] = React.useState(0);
|
|
5179
|
+
/** 预览取回来的块号:这些内容只反映了**当时那一部分 op**,提交后必须重拉。 */
|
|
5180
|
+
const previewKeys = React.useRef(new Set());
|
|
5181
|
+
const previewTimer = React.useRef(null);
|
|
5182
|
+
const [animFps, setAnimFps] = React.useState(null);
|
|
5183
|
+
const [frame, setFrame] = React.useState(0);
|
|
5184
|
+
const [truncated, setTruncated] = React.useState(false);
|
|
5185
|
+
const [planWarnings, setPlanWarnings] = React.useState([]);
|
|
5186
|
+
const [imagesReady, setImagesReady] = React.useState(0);
|
|
5187
|
+
// ── 工具 / 笔刷 / 图层 / 显示开关 ─────────────────────────────────────
|
|
5188
|
+
const [tool, setTool] = React.useState("pen");
|
|
5189
|
+
/** 当前笔刷(图例里的全局序号)。 */
|
|
5190
|
+
const [brush, setBrush] = React.useState(null);
|
|
5191
|
+
/** 多选(供「一键生成」取用)。 */
|
|
5192
|
+
const [multi, setMulti] = React.useState([]);
|
|
5193
|
+
const [layerIndex, setLayerIndex] = React.useState(0);
|
|
5194
|
+
const [single, setSingle] = React.useState(false);
|
|
5195
|
+
const [showGrid, setShowGrid] = React.useState(false);
|
|
5196
|
+
const [hover, setHover] = React.useState(null);
|
|
5197
|
+
/** 选中 / 正在改名的标记 id(画布上那个圈描红、标记卡里高亮)。 */
|
|
5198
|
+
const [markerSel, setMarkerSel] = React.useState(null);
|
|
5199
|
+
/** 图层改名的就地草稿:`{ id, value }`;null = 没有在改。 */
|
|
5200
|
+
const [layerDraft, setLayerDraft] = React.useState(null);
|
|
5201
|
+
/** 标记改名的就地草稿:`{ id, value }`。 */
|
|
5202
|
+
const [markerDraft, setMarkerDraft] = React.useState(null);
|
|
5203
|
+
// ── 保存状态 / 生成草稿 / 导出 ────────────────────────────────────────
|
|
5204
|
+
const [genKind, setGenKind] = React.useState("random");
|
|
5205
|
+
const [genSeed, setGenSeed] = React.useState(20261005);
|
|
5206
|
+
const [exportScale, setExportScale] = React.useState(1);
|
|
5207
|
+
/**
|
|
5208
|
+
* 导出内容(三个复选框),与宿主的 `formats` 一一对应。
|
|
5209
|
+
*
|
|
5210
|
+
* ⚠️ 这里刻意**只存选择、不执行**:以前是「点哪个按钮就导哪一份」,于是
|
|
5211
|
+
* 「导出图片 PNG」看起来像个被选中的页签、「导出存档 JSON」却是立即执行的动作 ——
|
|
5212
|
+
* 同一行里两个按钮一半是选择一半是提交。现在选择归复选框、执行归唯一的「导出」。
|
|
5213
|
+
*/
|
|
5214
|
+
const [exportFormats, setExportFormats] = React.useState({ png: true, json: true, tilesets: false });
|
|
5215
|
+
const imageRefs = React.useRef({});
|
|
5216
|
+
const canvasRef = React.useRef(null);
|
|
5217
|
+
/**
|
|
5218
|
+
* 画布的 ref 回调:顺手挂一个 `{ passive: false }` 的滚轮监听。
|
|
5219
|
+
*
|
|
5220
|
+
* ⚠️ **不能只写 React 的 `onWheel`**:它是被动注册的,在里面 `preventDefault()`
|
|
5221
|
+
* 只会在控制台留一条「Unable to preventDefault inside passive event listener」
|
|
5222
|
+
* 并且**照旧滚动面板** —— 真机上就是「滚轮缩放地图的同时整块面板也在滚」。
|
|
5223
|
+
* 用 ref 回调而不是 `useEffect(..., [])`:空态时画布还不存在,空依赖的 effect
|
|
5224
|
+
* 不会在它后来出现时再跑一次,监听就永远挂不上。
|
|
5225
|
+
*/
|
|
5226
|
+
const wheelOff = React.useRef(null);
|
|
5227
|
+
const zoomAtRef = React.useRef(null);
|
|
5228
|
+
const bindCanvas = React.useCallback((node) => {
|
|
5229
|
+
if (typeof wheelOff.current === "function") {
|
|
5230
|
+
wheelOff.current();
|
|
5231
|
+
wheelOff.current = null;
|
|
5232
|
+
}
|
|
5233
|
+
canvasRef.current = node === undefined ? null : node;
|
|
5234
|
+
if (node === null || node === undefined)
|
|
5235
|
+
return;
|
|
5236
|
+
const handler = (event) => {
|
|
5237
|
+
event.preventDefault();
|
|
5238
|
+
const zoom = zoomAtRef.current;
|
|
5239
|
+
if (typeof zoom === "function")
|
|
5240
|
+
zoom(event.clientX, event.clientY, event.deltaY < 0 ? 1.15 : 1 / 1.15);
|
|
5241
|
+
};
|
|
5242
|
+
node.addEventListener("wheel", handler, { passive: false });
|
|
5243
|
+
wheelOff.current = () => node.removeEventListener("wheel", handler);
|
|
5244
|
+
}, []);
|
|
5245
|
+
const stageRef = React.useRef(null);
|
|
5246
|
+
/**
|
|
5247
|
+
* 工具格上方那张小标签(名称 + 介绍 + 快捷键)。
|
|
5248
|
+
*
|
|
5249
|
+
* ⚠️ 位置用 `position:fixed` 而不是 `absolute`:工具栏的祖先里有 `overflow` 容器,
|
|
5250
|
+
* `absolute` 会让「按钮正上方」那一段被裁掉——和侧栏菜单踩的是同一个坑。
|
|
5251
|
+
* 坐标在 hover 时用 `getBoundingClientRect()` 现算,并夹在视口内(第一列的按钮
|
|
5252
|
+
* 居中后左半边会出界)。
|
|
5253
|
+
*/
|
|
5254
|
+
const [toolTip, setToolTip] = React.useState(null);
|
|
5255
|
+
/** 当前悬浮的那个按钮(滚动 / 改窗口大小时靠它把标签重新锚回去)。 */
|
|
5256
|
+
const toolTipAnchor = React.useRef(null);
|
|
5257
|
+
/** 横向夹在视口内:半宽上限 = CSS max-width 236 + 内边距,防止第一列按钮的标签出界。 */
|
|
5258
|
+
const toolTipX = (rect) => {
|
|
5259
|
+
const half = 124;
|
|
5260
|
+
const viewWidth = typeof window === "undefined" ? 0 : window.innerWidth || 0;
|
|
5261
|
+
const center = rect.left + rect.width / 2;
|
|
5262
|
+
return Math.round(viewWidth > 0 ? Math.max(half, Math.min(center, viewWidth - half)) : center);
|
|
5263
|
+
};
|
|
5264
|
+
const showToolTip = (name, desc, shortcut) => (event) => {
|
|
5265
|
+
const node = event === undefined ? null : event.currentTarget;
|
|
5266
|
+
if (node === null || node === undefined || typeof node.getBoundingClientRect !== "function")
|
|
5267
|
+
return;
|
|
5268
|
+
toolTipAnchor.current = node;
|
|
5269
|
+
const rect = node.getBoundingClientRect();
|
|
5270
|
+
setToolTip({
|
|
5271
|
+
name,
|
|
5272
|
+
desc,
|
|
5273
|
+
shortcut: shortcut === undefined ? null : shortcut,
|
|
5274
|
+
x: toolTipX(rect),
|
|
5275
|
+
y: Math.round(rect.top - 8)
|
|
5276
|
+
});
|
|
5277
|
+
};
|
|
5278
|
+
const hideToolTip = () => {
|
|
5279
|
+
toolTipAnchor.current = null;
|
|
5280
|
+
setToolTip((current) => (current === null ? current : null));
|
|
5281
|
+
};
|
|
5282
|
+
/**
|
|
5283
|
+
* 滚动 / 改窗口大小时**把标签重新锚回按钮**,而不是直接收起来。
|
|
5284
|
+
*
|
|
5285
|
+
* 收起看着更省事,但真机上很难受:面板一滚(或窗口一缩)标签就没了,而鼠标还停在
|
|
5286
|
+
* 按钮上、`mouseenter` 不会再触发,用户得先把鼠标移开再挪回来才重新看到说明。
|
|
5287
|
+
* 依赖只取「有没有标签」这个布尔量:依赖 `toolTip` 本身的话,每次重新定位都会
|
|
5288
|
+
* 重新挂监听。
|
|
5289
|
+
*/
|
|
5290
|
+
React.useEffect(() => {
|
|
5291
|
+
if (toolTip === null || typeof window === "undefined" || typeof window.addEventListener !== "function")
|
|
5292
|
+
return undefined;
|
|
5293
|
+
const reanchor = () => {
|
|
5294
|
+
const node = toolTipAnchor.current;
|
|
5295
|
+
if (node === null || node === undefined || typeof node.getBoundingClientRect !== "function" || node.isConnected === false) {
|
|
5296
|
+
hideToolTip();
|
|
5297
|
+
return;
|
|
5298
|
+
}
|
|
5299
|
+
const rect = node.getBoundingClientRect();
|
|
5300
|
+
setToolTip((current) => (current === null ? current : { ...current, x: toolTipX(rect), y: Math.round(rect.top - 8) }));
|
|
5301
|
+
};
|
|
5302
|
+
window.addEventListener("scroll", reanchor, true);
|
|
5303
|
+
window.addEventListener("resize", reanchor);
|
|
5304
|
+
return () => {
|
|
5305
|
+
window.removeEventListener("scroll", reanchor, true);
|
|
5306
|
+
window.removeEventListener("resize", reanchor);
|
|
5307
|
+
};
|
|
5308
|
+
}, [toolTip === null]);
|
|
5309
|
+
const fileRef = React.useRef(null);
|
|
5310
|
+
const pointersRef = React.useRef(new Map());
|
|
5311
|
+
const strokeRef = React.useRef(null);
|
|
5312
|
+
const strokeSeq = React.useRef(0);
|
|
5313
|
+
const currentStroke = React.useRef(null);
|
|
5314
|
+
const flushTimer = React.useRef(null);
|
|
5315
|
+
const pendingOps = React.useRef([]);
|
|
5316
|
+
const fittedRef = React.useRef(null);
|
|
5317
|
+
const spaceRef = React.useRef(false);
|
|
5318
|
+
const intent = useStudioIntent();
|
|
5319
|
+
const viewId = view === null ? null : view.id;
|
|
5320
|
+
const layers = view === null ? [] : view.layers || [];
|
|
5321
|
+
const safeLayerIndex = layers.length === 0 ? 0 : Math.min(Math.max(0, layerIndex), layers.length - 1);
|
|
5322
|
+
const activeLayer = layers.length === 0 ? null : layers[safeLayerIndex];
|
|
5323
|
+
const tilesets = view === null ? [] : view.tilesets || [];
|
|
5324
|
+
const safeTsIndex = tilesets.length === 0 ? 0 : Math.min(Math.max(0, tsIndex), tilesets.length - 1);
|
|
5325
|
+
const tileset = tilesets.length === 0 ? null : tilesets[safeTsIndex];
|
|
5326
|
+
const legend = view === null ? [] : view.legend || [];
|
|
5327
|
+
const assetBase = view === null ? "" : view.assetBase;
|
|
5328
|
+
const exportFiles = view === null ? [] : view.exportFiles || [];
|
|
5329
|
+
/** 与宿主 `layoutOf` 同形的一份布局:坐标函数要用它的步长与环绕开关。 */
|
|
5330
|
+
const layout = React.useMemo(() => {
|
|
5331
|
+
if (view === null)
|
|
5332
|
+
return null;
|
|
5333
|
+
const grid = view.grid;
|
|
5334
|
+
const cols = view.cols;
|
|
5335
|
+
const rows = view.rows;
|
|
5336
|
+
return {
|
|
5337
|
+
grid,
|
|
5338
|
+
cols,
|
|
5339
|
+
rows,
|
|
5340
|
+
stepX: grid.tileWidth,
|
|
5341
|
+
stepY: grid.tileHeight,
|
|
5342
|
+
width: cols * grid.tileWidth,
|
|
5343
|
+
height: rows * grid.tileHeight,
|
|
5344
|
+
wrap: grid.wrap === true
|
|
5345
|
+
};
|
|
5346
|
+
}, [view]);
|
|
5347
|
+
/** 图例:全局序号 → { 素材, 源矩形 }。 */
|
|
5348
|
+
const legendMap = React.useMemo(() => {
|
|
5349
|
+
const map = new Map();
|
|
5350
|
+
for (const entry of legend)
|
|
5351
|
+
map.set(entry.index, entry);
|
|
5352
|
+
return map;
|
|
5353
|
+
}, [legend]);
|
|
5354
|
+
const tilesetReason = tileset === null ? "" : tileset.reason || "";
|
|
5355
|
+
const activeFps = animFps === null ? (planMeta.fps > 0 ? planMeta.fps : 1) : animFps;
|
|
5356
|
+
/** 当前缩放 / 平移的最新值:捏合与滚轮要在同一次事件里读到,不能靠 state。 */
|
|
5357
|
+
const zoomRef = React.useRef(zoom);
|
|
5358
|
+
zoomRef.current = zoom;
|
|
5359
|
+
const panRef = React.useRef(pan);
|
|
5360
|
+
panRef.current = pan;
|
|
5361
|
+
const viewportRef = React.useRef(viewport);
|
|
5362
|
+
viewportRef.current = viewport;
|
|
5363
|
+
const withApi = React.useCallback(async (fn, options) => {
|
|
5364
|
+
if (api === undefined) {
|
|
5365
|
+
setNotice({ kind: "error", text: T("远程服务尚未挂载完成,请稍候再试") });
|
|
5366
|
+
return undefined;
|
|
5367
|
+
}
|
|
5368
|
+
try {
|
|
5369
|
+
const value = await fn();
|
|
5370
|
+
if (options !== undefined && options.notice !== undefined)
|
|
5371
|
+
setNotice({ kind: "info", text: options.notice });
|
|
5372
|
+
return value;
|
|
5373
|
+
}
|
|
5374
|
+
catch (error) {
|
|
5375
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
5376
|
+
return undefined;
|
|
5377
|
+
}
|
|
5378
|
+
}, [api]);
|
|
5379
|
+
/**
|
|
5380
|
+
* 每个缓存条目是**按哪次请求的视口**取回来的(键 → 视口矩形)。
|
|
5381
|
+
*
|
|
5382
|
+
* ⚠️ 宿主回的是「覆盖这个视口的那批条目」,所以一个键的内容取决于当时问的
|
|
5383
|
+
* 视口大小。只按 key 判断「我有没有」会让**视口变大后新露出来的格子一直空着**
|
|
5384
|
+
* (键还在缓存里,宿主就不重发了 —— 实测踩过)。这里只比较**客户端自己发出去的
|
|
5385
|
+
* 两个矩形**,不碰任何格 / 块的可见范围计算。
|
|
5386
|
+
*/
|
|
5387
|
+
const fetchedRef = React.useRef(new Map());
|
|
5388
|
+
/**
|
|
5389
|
+
* 「内容可能已经过期、正等着重拉」的那几个块。
|
|
5390
|
+
*
|
|
5391
|
+
* ⚠️ 这里**故意不把 key 从 `planRef` 里删掉**。删掉的话,从「提交完」到「增量计划
|
|
5392
|
+
* 回来」之间这段时间里这一块是**没有内容的** —— 画布会整块变空再变回来。
|
|
5393
|
+
* 一块可能覆盖很大一片(块边长见 `mapgeom.MAP_CHUNK_SIZE`;地图不比块大多少时
|
|
5394
|
+
* 一块就是整张地图),于是拖动笔刷期间每 40ms 就闪一次,真机表现就是「画布一直闪烁」。
|
|
5395
|
+
* 现在改成:旧内容继续画,只是**不再向宿主声明「我有」**(`have` 里剔掉),
|
|
5396
|
+
* 于是宿主会把新内容重发一次,`applyQuery` 收到后把这个 key 移出集合。
|
|
5397
|
+
*/
|
|
5398
|
+
const staleRef = React.useRef(new Set());
|
|
5399
|
+
/** 换项目 / 换层 / 大改之后:把计划整份作废(下次渲染重新问宿主)。 */
|
|
5400
|
+
const clearPlan = React.useCallback(() => {
|
|
5401
|
+
planRef.current = new Map();
|
|
5402
|
+
fetchedRef.current = new Map();
|
|
5403
|
+
staleRef.current = new Set();
|
|
5404
|
+
visibleRef.current = [];
|
|
5405
|
+
setPlanOps(new Map());
|
|
5406
|
+
setPlanMarkers([]);
|
|
5407
|
+
setVisibleKeys([]);
|
|
5408
|
+
}, []);
|
|
5409
|
+
/**
|
|
5410
|
+
* 读一次项目视图。
|
|
5411
|
+
*
|
|
5412
|
+
* `keep` = 保留画布上的选择(图层 / 面板 / 缩放):验收打勾、导出回读这类
|
|
5413
|
+
* 「只是刷新一下状态」的调用不该把用户正在画的层顶掉。
|
|
5414
|
+
*/
|
|
5415
|
+
const loadSeq = React.useRef(0);
|
|
5416
|
+
const loadProject = React.useCallback(async (id, keep) => {
|
|
5417
|
+
if (api === undefined || id === null || id === undefined || id === "")
|
|
5418
|
+
return;
|
|
5419
|
+
/**
|
|
5420
|
+
* ⚠️ 并发读盘要**按最后一次发起的请求收口**(丢弃迟到的旧响应)。
|
|
5421
|
+
*
|
|
5422
|
+
* 同一个项目可能同时在读好几次(挂载时那次、点导出后那次、`busy` 期间的 1.5s 轮询、
|
|
5423
|
+
* 打勾后的回读)。它们各自 await 一次读盘,**回来的顺序不保证与发出的一致** ——
|
|
5424
|
+
* 迟到的旧响应会把新状态顶回去。真机上的表现是「导出完了、文件也在盘上,
|
|
5425
|
+
* 但导出卡片一直写着『还没有导出过』」,而且重新点一次才好 —— 查起来像随机。
|
|
5426
|
+
*/
|
|
5427
|
+
const seq = ++loadSeq.current;
|
|
5428
|
+
try {
|
|
5429
|
+
const next = await api.getMapProject({ projectId: id, lang: activeLang() });
|
|
5430
|
+
if (seq !== loadSeq.current)
|
|
5431
|
+
return;
|
|
5432
|
+
if (keep !== true) {
|
|
5433
|
+
clearPlan();
|
|
5434
|
+
setLayerIndex(0);
|
|
5435
|
+
setTsIndex(0);
|
|
5436
|
+
setPlanMeta({ fps: 1, frameCount: 1 });
|
|
5437
|
+
setAnimFps(null);
|
|
5438
|
+
setTruncated(false);
|
|
5439
|
+
setPlanWarnings([]);
|
|
5440
|
+
}
|
|
5441
|
+
setView(next);
|
|
5442
|
+
}
|
|
5443
|
+
catch (error) {
|
|
5444
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
5445
|
+
}
|
|
5446
|
+
}, [api, clearPlan]);
|
|
5447
|
+
React.useEffect(() => {
|
|
5448
|
+
void (async () => {
|
|
5449
|
+
if (api === undefined)
|
|
5450
|
+
return;
|
|
5451
|
+
try {
|
|
5452
|
+
const result = await api.listMapProjects();
|
|
5453
|
+
const list = result.projects || [];
|
|
5454
|
+
setProjects(list);
|
|
5455
|
+
if (list.length > 0)
|
|
5456
|
+
await loadProject(list[0].id);
|
|
5457
|
+
}
|
|
5458
|
+
catch (error) {
|
|
5459
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
5460
|
+
}
|
|
5461
|
+
})();
|
|
5462
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5463
|
+
}, [api]);
|
|
5464
|
+
// 深链接:`?dsh-gmm=1&module=map&job=<项目 id>&stage=assets|rules|paint|export`
|
|
5465
|
+
React.useEffect(() => {
|
|
5466
|
+
if (intent === null || intent.module !== "map")
|
|
5467
|
+
return;
|
|
5468
|
+
const id = typeof intent.jobId === "string" && intent.jobId !== "" ? intent.jobId : intent.projectId;
|
|
5469
|
+
if (typeof id === "string" && id !== "")
|
|
5470
|
+
void loadProject(id);
|
|
5471
|
+
if (intent.stage === "assets")
|
|
5472
|
+
setOpenCard("assets");
|
|
5473
|
+
else if (intent.stage === "export")
|
|
5474
|
+
setOpenCard("export");
|
|
5475
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5476
|
+
}, [intent]);
|
|
5477
|
+
// ── 绘制计划:什么时候问、怎么合并 ───────────────────────────────────
|
|
5478
|
+
const applyQuery = React.useCallback((result, view) => {
|
|
5479
|
+
const incoming = Array.isArray(result?.[MAP_PLAN_LIST]) ? result[MAP_PLAN_LIST] : [];
|
|
5480
|
+
const next = new Map(planRef.current);
|
|
5481
|
+
const previewing = currentStroke.current !== null && pendingOps.current.length > 0;
|
|
5482
|
+
for (const entry of incoming) {
|
|
5483
|
+
next.set(entry.key, Array.isArray(entry.ops) ? entry.ops : []);
|
|
5484
|
+
// 预览期间取回来的块:内容只反映「当时那一部分 op」,提交后要按真实数据重拉
|
|
5485
|
+
if (previewing)
|
|
5486
|
+
previewKeys.current.add(entry.key);
|
|
5487
|
+
// 这一份已经是新的了:不用再重拉
|
|
5488
|
+
staleRef.current.delete(entry.key);
|
|
5489
|
+
// 记下这一份是「按哪个视口」取回来的:视口再变大时它就不够画了
|
|
5490
|
+
if (view !== undefined)
|
|
5491
|
+
fetchedRef.current.set(entry.key, view);
|
|
5492
|
+
}
|
|
5493
|
+
const keys = Array.isArray(result?.visibleKeys) ? result.visibleKeys : [];
|
|
5494
|
+
/** 缓存上限:先丢「已经不在可见范围里」的键,免得看久了内存无限涨。 */
|
|
5495
|
+
if (next.size > 384) {
|
|
5496
|
+
const keep = new Set(keys);
|
|
5497
|
+
for (const key of [...next.keys()]) {
|
|
5498
|
+
if (next.size <= 256)
|
|
5499
|
+
break;
|
|
5500
|
+
if (!keep.has(key))
|
|
5501
|
+
next.delete(key);
|
|
5502
|
+
}
|
|
5503
|
+
}
|
|
5504
|
+
planRef.current = next;
|
|
5505
|
+
visibleRef.current = keys;
|
|
5506
|
+
setPlanOps(next);
|
|
5507
|
+
// 标记**整份覆盖**(不进那份按块缓存):编号会随删除整体前移,缓存住的号码会留在屏幕上。
|
|
5508
|
+
setPlanMarkers(Array.isArray(result?.markers) ? result.markers : []);
|
|
5509
|
+
setVisibleKeys(keys);
|
|
5510
|
+
const fps = Number(result?.fps);
|
|
5511
|
+
const frames = Number(result?.frameCount);
|
|
5512
|
+
setPlanMeta({
|
|
5513
|
+
fps: Number.isFinite(fps) && fps > 0 ? fps : 1,
|
|
5514
|
+
frameCount: Number.isFinite(frames) && frames > 1 ? Math.floor(frames) : 1
|
|
5515
|
+
});
|
|
5516
|
+
setTruncated(result?.truncated === true);
|
|
5517
|
+
setPlanWarnings(Array.isArray(result?.warnings) ? result.warnings : []);
|
|
5518
|
+
}, []);
|
|
5519
|
+
/** 计划的「身份」:这张图变了(换项目 / 换层 / 换网格 / 换尺寸)就整份重来。 */
|
|
5520
|
+
const planKey = viewId === null || layout === null
|
|
5521
|
+
? null
|
|
5522
|
+
: `${viewId}|${single === true ? safeLayerIndex : "all"}|${layout.wrap === true ? "w" : "n"}|${layout.stepX}x${layout.stepY}|${layout.cols}x${layout.rows}`;
|
|
5523
|
+
// 身份变了 → 旧计划一律作废(不同层的块里条目本来就不同)
|
|
5524
|
+
const planKeyRef = React.useRef(null);
|
|
5525
|
+
React.useEffect(() => {
|
|
5526
|
+
if (planKeyRef.current === planKey)
|
|
5527
|
+
return;
|
|
5528
|
+
planKeyRef.current = planKey;
|
|
5529
|
+
if (planKey === null)
|
|
5530
|
+
return;
|
|
5531
|
+
clearPlan();
|
|
5532
|
+
setPlanEpoch((value) => value + 1);
|
|
5533
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5534
|
+
}, [planKey]);
|
|
5535
|
+
/** 外框矩形是否盖住内框(只用来判断「这一份计划还够不够画当前视口」)。 */
|
|
5536
|
+
const viewCovers = (outer, inner) => outer.x <= inner.x && outer.y <= inner.y && outer.x + outer.width >= inner.x + inner.width && outer.y + outer.height >= inner.y + inner.height;
|
|
5537
|
+
React.useEffect(() => {
|
|
5538
|
+
if (api === undefined || viewId === null || layout === null || measured !== true)
|
|
5539
|
+
return undefined;
|
|
5540
|
+
let cancelled = false;
|
|
5541
|
+
const timer = setTimeout(() => {
|
|
5542
|
+
void (async () => {
|
|
5543
|
+
const strokeAtQuery = currentStroke.current;
|
|
5544
|
+
try {
|
|
5545
|
+
const size = viewportRef.current;
|
|
5546
|
+
const currentView = { x: pan.x, y: pan.y, width: size.w / zoom, height: size.h / zoom };
|
|
5547
|
+
const pending = currentStroke.current === null ? undefined : [...pendingOps.current];
|
|
5548
|
+
/**
|
|
5549
|
+
* ⚠️ **预览查询一律不带 `have`**(说自己什么都没有)。
|
|
5550
|
+
*
|
|
5551
|
+
* 真机踩过:预览改的格子往往落在**已经缓存过的块**里,宿主一看「你有这一块」
|
|
5552
|
+
* 就不回传 —— 于是拖动期间一片空白,松手提交后靠 `dropKeys` 重拉才出现。
|
|
5553
|
+
* 客户端又不许自己算「这一笔碰到哪些块」(那是宿主的几何),所以预览时
|
|
5554
|
+
* 干脆要一整份可视块:多传几十块,换「拖着就能看见」,值。
|
|
5555
|
+
* (宿主那边另有强制回传,见 `mapgen.mapPlan` 的 `forced`。)
|
|
5556
|
+
*/
|
|
5557
|
+
const have = pending !== undefined ? [] : [...planRef.current.keys()].filter((key) => {
|
|
5558
|
+
// 待重拉的键不算「我有」:宿主据此把新内容发回来
|
|
5559
|
+
if (staleRef.current.has(key))
|
|
5560
|
+
return false;
|
|
5561
|
+
// 预览块同理:它只反映「当时那一部分 op」,这一笔还在长,必须重新算
|
|
5562
|
+
if (previewKeys.current.has(key))
|
|
5563
|
+
return false;
|
|
5564
|
+
const fetched = fetchedRef.current.get(key);
|
|
5565
|
+
return fetched !== undefined && viewCovers(fetched, currentView);
|
|
5566
|
+
});
|
|
5567
|
+
const result = await api.mapPlan({
|
|
5568
|
+
projectId: viewId,
|
|
5569
|
+
view: currentView,
|
|
5570
|
+
have,
|
|
5571
|
+
pending: Array.isArray(pending) && pending.length > 0 ? pending : undefined,
|
|
5572
|
+
layerIds: single === true ? [safeLayerIndex] : undefined
|
|
5573
|
+
});
|
|
5574
|
+
if (cancelled === true)
|
|
5575
|
+
return;
|
|
5576
|
+
/**
|
|
5577
|
+
* 预览响应回来时这一笔可能已经提交(或换了):它算的是**过时**的那部分 op,
|
|
5578
|
+
* 应用它会让缓存停在预览上(提交后的真实数据就补不进来了)。直接丢掉,
|
|
5579
|
+
* 交给提交后那次查询重发这几块。
|
|
5580
|
+
*/
|
|
5581
|
+
if (strokeAtQuery !== null && strokeAtQuery !== currentStroke.current)
|
|
5582
|
+
return;
|
|
5583
|
+
applyQuery(result, currentView);
|
|
5584
|
+
}
|
|
5585
|
+
catch (error) {
|
|
5586
|
+
if (cancelled === true)
|
|
5587
|
+
return;
|
|
5588
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
5589
|
+
}
|
|
5590
|
+
})();
|
|
5591
|
+
}, 32);
|
|
5592
|
+
return () => {
|
|
5593
|
+
cancelled = true;
|
|
5594
|
+
clearTimeout(timer);
|
|
5595
|
+
};
|
|
5596
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5597
|
+
}, [api, viewId, planKey, planEpoch, previewTick, pan, zoom, viewport, single, safeLayerIndex, measured]);
|
|
5598
|
+
// 视图尺寸变了(面板宽窄、窗口缩放):重新量一次
|
|
5599
|
+
React.useEffect(() => {
|
|
5600
|
+
const element = stageRef.current;
|
|
5601
|
+
if (element === null || element === undefined)
|
|
5602
|
+
return undefined;
|
|
5603
|
+
const measure = () => {
|
|
5604
|
+
const rect = element.getBoundingClientRect();
|
|
5605
|
+
setViewport({ w: Math.max(160, Math.round(rect.width)), h: Math.max(120, Math.round(rect.height)) });
|
|
5606
|
+
setMeasured(true);
|
|
5607
|
+
};
|
|
5608
|
+
measure();
|
|
5609
|
+
if (typeof ResizeObserver !== "function")
|
|
5610
|
+
return undefined;
|
|
5611
|
+
const observer = new ResizeObserver(measure);
|
|
5612
|
+
observer.observe(element);
|
|
5613
|
+
return () => observer.disconnect();
|
|
5614
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5615
|
+
}, [viewId]);
|
|
5616
|
+
// 换项目 / 改尺寸后把整张地图摆回视野中央(用户自己平移过就不再动)
|
|
5617
|
+
React.useEffect(() => {
|
|
5618
|
+
if (view === null || layout === null)
|
|
5619
|
+
return;
|
|
5620
|
+
const key = `${view.id}:${layout.cols}x${layout.rows}:${layout.stepX}`;
|
|
5621
|
+
if (fittedRef.current === key)
|
|
5622
|
+
return;
|
|
5623
|
+
fittedRef.current = key;
|
|
5624
|
+
const scale = Math.min(1, viewport.w / Math.max(1, layout.width), viewport.h / Math.max(1, layout.height));
|
|
5625
|
+
const next = Math.min(8, Math.max(0.25, Number.isFinite(scale) && scale > 0 ? scale : 1));
|
|
5626
|
+
setZoom(next);
|
|
5627
|
+
// 摆回视野:地图比视口小的方向会被夹到 0(左上角对齐),大的方向居中
|
|
5628
|
+
setPan(clampPan({ x: (layout.width - viewport.w / next) / 2, y: (layout.height - viewport.h / next) / 2 }));
|
|
5629
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5630
|
+
}, [viewId, layout === null ? "" : `${layout.cols}x${layout.rows}x${layout.stepX}`, viewport.w, viewport.h]);
|
|
5631
|
+
// ── 画布绘制 ─────────────────────────────────────────────────────────
|
|
5632
|
+
const draw = React.useCallback(() => {
|
|
5633
|
+
const canvas = canvasRef.current;
|
|
5634
|
+
if (canvas === null || canvas === undefined || layout === null)
|
|
5635
|
+
return;
|
|
5636
|
+
const ctx = canvas.getContext("2d");
|
|
5637
|
+
if (ctx === null || ctx === undefined)
|
|
5638
|
+
return;
|
|
5639
|
+
const width = Math.max(1, Math.round(viewport.w));
|
|
5640
|
+
const height = Math.max(1, Math.round(viewport.h));
|
|
5641
|
+
/**
|
|
5642
|
+
* 按 devicePixelRatio 放大 backing store。
|
|
5643
|
+
*
|
|
5644
|
+
* 不放大时每个地图像素只占 1 个物理像素 → 像素画在 Retina 上发糊。
|
|
5645
|
+
* 坐标仍按 CSS 像素记,倍率进 transform,所以计划里的目标坐标一个都不用改。
|
|
5646
|
+
*/
|
|
5647
|
+
const dpr = Math.max(1, Math.min(3, (typeof window !== "undefined" && window.devicePixelRatio) || 1));
|
|
5648
|
+
const backingWidth = Math.round(width * dpr);
|
|
5649
|
+
const backingHeight = Math.round(height * dpr);
|
|
5650
|
+
if (canvas.width !== backingWidth)
|
|
5651
|
+
canvas.width = backingWidth;
|
|
5652
|
+
if (canvas.height !== backingHeight)
|
|
5653
|
+
canvas.height = backingHeight;
|
|
5654
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
5655
|
+
ctx.clearRect(0, 0, backingWidth, backingHeight);
|
|
5656
|
+
ctx.imageSmoothingEnabled = false;
|
|
5657
|
+
const scale = zoom * dpr;
|
|
5658
|
+
ctx.setTransform(scale, 0, 0, scale, -pan.x * scale, -pan.y * scale);
|
|
5659
|
+
// 单层预览:底铺绿。层过滤由宿主的计划做,这里一条条目都不筛。
|
|
5660
|
+
if (single === true) {
|
|
5661
|
+
ctx.fillStyle = "rgb(56,170,68)";
|
|
5662
|
+
ctx.fillRect(pan.x, pan.y, width / zoom, height / zoom);
|
|
5663
|
+
}
|
|
5664
|
+
const debug = typeof window !== "undefined" && window.__mapDebug === true;
|
|
5665
|
+
const stats = debug ? { keys: [], cached: 0, drawn: 0, noLegend: 0, noImage: 0, first: null, frame: 0 } : null;
|
|
5666
|
+
for (const key of visibleRef.current) {
|
|
5667
|
+
if (stats !== null)
|
|
5668
|
+
stats.keys.push(key);
|
|
5669
|
+
const ops = planOps.get(key);
|
|
5670
|
+
if (ops === undefined)
|
|
5671
|
+
continue;
|
|
5672
|
+
if (stats !== null)
|
|
5673
|
+
stats.cached += ops.length;
|
|
5674
|
+
for (const op of ops) {
|
|
5675
|
+
const index = op.cycle === undefined || op.cycle.length === 0 ? op.t : op.cycle[frame % op.cycle.length];
|
|
5676
|
+
const entry = legendMap.get(index);
|
|
5677
|
+
if (entry === undefined) {
|
|
5678
|
+
if (stats !== null)
|
|
5679
|
+
stats.noLegend++;
|
|
5680
|
+
continue;
|
|
5681
|
+
}
|
|
5682
|
+
const image = imageRefs.current[entry.tilesetId];
|
|
5683
|
+
if (image === undefined || image === null) {
|
|
5684
|
+
if (stats !== null)
|
|
5685
|
+
stats.noImage++;
|
|
5686
|
+
continue;
|
|
5687
|
+
}
|
|
5688
|
+
if (stats !== null) {
|
|
5689
|
+
stats.drawn++;
|
|
5690
|
+
if (stats.first === null)
|
|
5691
|
+
stats.first = { t: index, x: op.x, y: op.y, ts: entry.tilesetId };
|
|
5692
|
+
}
|
|
5693
|
+
ctx.globalAlpha = op.a === undefined ? 1 : op.a;
|
|
5694
|
+
ctx.drawImage(image, entry.rect.x, entry.rect.y, entry.rect.width, entry.rect.height, op.x, op.y, entry.rect.width, entry.rect.height);
|
|
5695
|
+
}
|
|
5696
|
+
}
|
|
5697
|
+
ctx.globalAlpha = 1;
|
|
5698
|
+
// 网格线:只是对位用的装饰,不参与任何绘制计划
|
|
5699
|
+
if (showGrid === true) {
|
|
5700
|
+
const stepX = layout.grid.tileWidth;
|
|
5701
|
+
const stepY = layout.grid.tileHeight;
|
|
5702
|
+
const thin = 1 / zoom;
|
|
5703
|
+
ctx.fillStyle = "rgba(255,255,255,0.22)";
|
|
5704
|
+
const right = pan.x + width / zoom;
|
|
5705
|
+
const bottom = pan.y + height / zoom;
|
|
5706
|
+
let count = 0;
|
|
5707
|
+
for (let x = Math.floor(pan.x / stepX) * stepX; x <= right && count < 800; x += stepX) {
|
|
5708
|
+
ctx.fillRect(x, pan.y, thin, height / zoom);
|
|
5709
|
+
count++;
|
|
5710
|
+
}
|
|
5711
|
+
for (let y = Math.floor(pan.y / stepY) * stepY; y <= bottom && count < 1600; y += stepY) {
|
|
5712
|
+
ctx.fillRect(pan.x, y, width / zoom, thin);
|
|
5713
|
+
count++;
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5716
|
+
/**
|
|
5717
|
+
* 标记点:圆 + 圆圈里的数字。
|
|
5718
|
+
*
|
|
5719
|
+
* 圆心、半径、字号、数字**全在宿主给的计划里** —— 界面只负责 `arc` 与 `fillText`。
|
|
5720
|
+
* 绘制放在图块与格线**之后**,所以标记永远压在地图上;环绕接缝处同一个标记会出现
|
|
5721
|
+
* 多份(宿主按像素位置各发一条),这里照单全画。
|
|
5722
|
+
*/
|
|
5723
|
+
for (const marker of planMarkers) {
|
|
5724
|
+
ctx.beginPath();
|
|
5725
|
+
ctx.arc(marker.x, marker.y, marker.radius, 0, Math.PI * 2);
|
|
5726
|
+
ctx.fillStyle = marker.id === markerSel ? "rgba(210,59,44,0.92)" : "rgba(20,22,30,0.86)";
|
|
5727
|
+
ctx.fill();
|
|
5728
|
+
ctx.lineWidth = Math.max(1, marker.radius * 0.16);
|
|
5729
|
+
ctx.strokeStyle = "#f0c040";
|
|
5730
|
+
ctx.stroke();
|
|
5731
|
+
ctx.fillStyle = "#ffffff";
|
|
5732
|
+
ctx.font = `700 ${marker.font}px sans-serif`;
|
|
5733
|
+
ctx.textAlign = "center";
|
|
5734
|
+
ctx.textBaseline = "middle";
|
|
5735
|
+
ctx.fillText(String(marker.n), marker.x, marker.y);
|
|
5736
|
+
}
|
|
5737
|
+
// 悬停格:2px 红框(四条细矩形,不用 stroke,免得被 DPR 影响粗细)
|
|
5738
|
+
// ⚠️ 用**未取模**的坐标定位:环绕时同一格在屏幕上有多份,红框必须画在指针
|
|
5739
|
+
// 所在的那一份上。拿取模后的 r/c 去算,指针在地图外那一份时红框会跳一整张地图。
|
|
5740
|
+
if (hover !== null && hover !== undefined) {
|
|
5741
|
+
const rawC = Math.floor(hover.x / layout.stepX);
|
|
5742
|
+
const rawR = Math.floor(hover.y / layout.stepY);
|
|
5743
|
+
const topLeft = MAP_cellTopLeft(layout, rawR, rawC, layout.grid.tileWidth, layout.grid.tileHeight);
|
|
5744
|
+
const thickness = 2 / zoom;
|
|
5745
|
+
const w = layout.grid.tileWidth;
|
|
5746
|
+
const hh = layout.grid.tileHeight;
|
|
5747
|
+
ctx.fillStyle = "#e23b2b";
|
|
5748
|
+
ctx.fillRect(topLeft.x, topLeft.y, w, thickness);
|
|
5749
|
+
ctx.fillRect(topLeft.x, topLeft.y + hh - thickness, w, thickness);
|
|
5750
|
+
ctx.fillRect(topLeft.x, topLeft.y + thickness, thickness, hh - thickness * 2);
|
|
5751
|
+
ctx.fillRect(topLeft.x + w - thickness, topLeft.y + thickness, thickness, hh - thickness * 2);
|
|
5752
|
+
}
|
|
5753
|
+
/**
|
|
5754
|
+
* 悬停到标记上:把**名字**写在圆圈旁边。
|
|
5755
|
+
*
|
|
5756
|
+
* 名字不常驻画布(几十个名字会糊成一片),只有指针停上去才出现。
|
|
5757
|
+
* 「停到了哪个」按**指针到圆心的距离**判:环绕时同一个标记在屏幕上有好几份,
|
|
5758
|
+
* 只看格号会挑到地图另一头那一份(红框当年就是这个坑)。圆心与半径都是宿主给的。
|
|
5759
|
+
*/
|
|
5760
|
+
if (hover !== null && hover !== undefined) {
|
|
5761
|
+
let found = undefined;
|
|
5762
|
+
let best = Infinity;
|
|
5763
|
+
for (const marker of planMarkers) {
|
|
5764
|
+
const distance = Math.hypot(marker.x - hover.x, marker.y - hover.y);
|
|
5765
|
+
if (distance <= marker.radius * 2.5 && distance < best) {
|
|
5766
|
+
best = distance;
|
|
5767
|
+
found = marker;
|
|
5768
|
+
}
|
|
5769
|
+
}
|
|
5770
|
+
if (found !== undefined) {
|
|
5771
|
+
const label = found.name === "" ? T("标记 {n0}", { n0: String(found.n) }) : `${found.n} · ${found.name}`;
|
|
5772
|
+
// 缩得很小时文字会跟着变小到看不清,所以字号有个下限(只影响这个浮层,不影响圆)。
|
|
5773
|
+
const font = Math.max(12 / zoom, found.font * 0.85);
|
|
5774
|
+
ctx.font = `600 ${font}px sans-serif`;
|
|
5775
|
+
ctx.textAlign = "left";
|
|
5776
|
+
ctx.textBaseline = "middle";
|
|
5777
|
+
const padding = 4 / zoom;
|
|
5778
|
+
const boxWidth = ctx.measureText(label).width + padding * 2;
|
|
5779
|
+
const boxHeight = font + padding * 2;
|
|
5780
|
+
const left = found.x + found.radius + 3 / zoom;
|
|
5781
|
+
const top = found.y - boxHeight / 2;
|
|
5782
|
+
ctx.fillStyle = "rgba(20,22,30,0.9)";
|
|
5783
|
+
ctx.fillRect(left, top, boxWidth, boxHeight);
|
|
5784
|
+
ctx.fillStyle = "#f3e7d3";
|
|
5785
|
+
ctx.fillText(label, left + padding, found.y);
|
|
5786
|
+
}
|
|
5787
|
+
}
|
|
5788
|
+
if (stats !== null && typeof window !== "undefined") {
|
|
5789
|
+
stats.frame = frame;
|
|
5790
|
+
window.__mapDrawStats = stats;
|
|
5791
|
+
/**
|
|
5792
|
+
* 顺手把**当前相机**暴露出来(同样只在 `__mapDebug` 打开时)。
|
|
5793
|
+
*
|
|
5794
|
+
* 自检里要按格坐标去点画布,而「格 → 客户端像素」必须用**此刻**的 pan/zoom;
|
|
5795
|
+
* 靠「最近一次计划查询的 view」推会读到过期的相机(切项目 / 自适应缩放之后),
|
|
5796
|
+
* 于是点到了地图外、断言莫名其妙地失败。就摆在绘制里,永远不会过期。
|
|
5797
|
+
*/
|
|
5798
|
+
window.__mapCamera = { pan: { x: pan.x, y: pan.y }, zoom, viewport: { w: viewport.w, h: viewport.h } };
|
|
5799
|
+
}
|
|
5800
|
+
}, [layout, viewport, zoom, pan, planOps, planMarkers, markerSel, legend, legendMap, single, showGrid, hover, frame]);
|
|
5801
|
+
React.useEffect(() => {
|
|
5802
|
+
draw();
|
|
5803
|
+
}, [draw, imagesReady]);
|
|
5804
|
+
/** 停帧条件:系统开了「减少动态效果」或页面被切到后台 → 永远停在第一帧。 */
|
|
5805
|
+
const stillFrame = (typeof window !== "undefined" &&
|
|
5806
|
+
typeof window.matchMedia === "function" &&
|
|
5807
|
+
window.matchMedia("(prefers-reduced-motion: reduce)").matches === true) ||
|
|
5808
|
+
(typeof document !== "undefined" && document !== null && document.hidden === true);
|
|
5809
|
+
React.useEffect(() => {
|
|
5810
|
+
if (stillFrame === true || planMeta.frameCount <= 1) {
|
|
5811
|
+
setFrame(0);
|
|
5812
|
+
return undefined;
|
|
5813
|
+
}
|
|
5814
|
+
if (typeof window === "undefined" || typeof window.requestAnimationFrame !== "function")
|
|
5815
|
+
return undefined;
|
|
5816
|
+
const started = Date.now();
|
|
5817
|
+
let handle = 0;
|
|
5818
|
+
const tick = () => {
|
|
5819
|
+
const elapsed = (Date.now() - started) / 1000;
|
|
5820
|
+
setFrame(Math.floor(elapsed * activeFps) % planMeta.frameCount);
|
|
5821
|
+
handle = window.requestAnimationFrame(tick);
|
|
5822
|
+
};
|
|
5823
|
+
handle = window.requestAnimationFrame(tick);
|
|
5824
|
+
return () => window.cancelAnimationFrame(handle);
|
|
5825
|
+
}, [stillFrame, planMeta.frameCount, activeFps]);
|
|
5826
|
+
// ── 编辑:op 批量提交 ────────────────────────────────────────────────
|
|
5827
|
+
const applyResult = React.useCallback((result) => {
|
|
5828
|
+
if (result === undefined || result === null)
|
|
5829
|
+
return;
|
|
5830
|
+
const drop = Array.isArray(result.dropKeys) ? result.dropKeys : [];
|
|
5831
|
+
// 只标记「待重拉」,**不删缓存**:删除会让这一块在重拉回来之前没有内容,
|
|
5832
|
+
// 拖动时就是整块闪一下(详见 staleRef 的注释)。画面本身不用重画。
|
|
5833
|
+
for (const key of drop)
|
|
5834
|
+
staleRef.current.add(key);
|
|
5835
|
+
setView((prev) => (prev === null ? prev : { ...prev, canUndo: result.canUndo === true, canRedo: result.canRedo === true }));
|
|
5836
|
+
if (Array.isArray(result.skipped) && result.skipped.length > 0) {
|
|
5837
|
+
setNotice({ kind: "error", text: result.skipped.slice(0, 2).join(";") });
|
|
5838
|
+
}
|
|
5839
|
+
setPlanEpoch((value) => value + 1);
|
|
5840
|
+
}, []);
|
|
5841
|
+
const flushOps = React.useCallback(async () => {
|
|
5842
|
+
if (flushTimer.current !== null) {
|
|
5843
|
+
clearTimeout(flushTimer.current);
|
|
5844
|
+
flushTimer.current = null;
|
|
5845
|
+
}
|
|
5846
|
+
if (previewTimer.current !== null) {
|
|
5847
|
+
clearTimeout(previewTimer.current);
|
|
5848
|
+
previewTimer.current = null;
|
|
5849
|
+
}
|
|
5850
|
+
/**
|
|
5851
|
+
* 这一笔要真正提交了:先把它期间预览出来的块标成「待重拉」——
|
|
5852
|
+
* 那些内容是按**当时那一部分 op** 算的,最后几个格子可能还没进去。
|
|
5853
|
+
* 标记之后宿主会按真实数据把这几块重发一遍,画面不会停在预览上。
|
|
5854
|
+
*/
|
|
5855
|
+
for (const key of previewKeys.current)
|
|
5856
|
+
staleRef.current.add(key);
|
|
5857
|
+
previewKeys.current = new Set();
|
|
5858
|
+
const ops = pendingOps.current;
|
|
5859
|
+
if (ops.length === 0)
|
|
5860
|
+
return;
|
|
5861
|
+
if (api === undefined || viewId === null) {
|
|
5862
|
+
// ⚠️ 这里**必须**把队列清掉再返回:服务还没挂上 / 项目已被切换时提交不了,
|
|
5863
|
+
// 留下的话它们会带着**上一笔的 stroke** 等到下一次 flush,被
|
|
5864
|
+
// `stroke: ops[0]?.stroke` 整批盖成一个 id —— 两笔不同的涂抹会被并成
|
|
5865
|
+
// 一条撤销;项目已删除时还会往旧 viewId 提交。
|
|
5866
|
+
pendingOps.current = [];
|
|
5867
|
+
return;
|
|
5868
|
+
}
|
|
5869
|
+
pendingOps.current = [];
|
|
5870
|
+
try {
|
|
5871
|
+
const result = await api.applyMapOps({ projectId: viewId, ops, stroke: ops[0]?.stroke, have: [...planRef.current.keys()] });
|
|
5872
|
+
applyResult(result);
|
|
5873
|
+
}
|
|
5874
|
+
catch (error) {
|
|
5875
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
5876
|
+
}
|
|
5877
|
+
finally {
|
|
5878
|
+
}
|
|
5879
|
+
}, [api, viewId, applyResult]);
|
|
5880
|
+
/**
|
|
5881
|
+
* 把相机**夹在地图里**:地图比视口大的方向可以滚(`视口-地图 .. 0`),
|
|
5882
|
+
* 比视口小的方向钉在 0 —— 也就是「地图左上角贴着画布左上角」。
|
|
5883
|
+
*
|
|
5884
|
+
* ⚠️ 真机反馈两条都出在这里:拖到右下角时地图会「复位」、而且复位后左上角对不齐,
|
|
5885
|
+
* 于是「靠拖动很难把地图拖到左上角」。环绕地图上相机本来可以无限拖,视口越过
|
|
5886
|
+
* 地图边界后宿主只能回**折回来的那一份**,画面在「一份地图」的边界上整体跳一格,
|
|
5887
|
+
* 看起来就是复位;而 0 这个位置既没有参照物、又不在吸附点上,自然对不齐、也难拖到。
|
|
5888
|
+
* 夹住之后 `pan = 0` 就是「地图左上角 = 画布左上角」,拖到头就停,不再有跳变。
|
|
5889
|
+
*/
|
|
5890
|
+
const clampPan = React.useCallback((next) => {
|
|
5891
|
+
if (layout === null)
|
|
5892
|
+
return next;
|
|
5893
|
+
const viewW = viewportRef.current.w / Math.max(0.01, zoomRef.current);
|
|
5894
|
+
const viewH = viewportRef.current.h / Math.max(0.01, zoomRef.current);
|
|
5895
|
+
/**
|
|
5896
|
+
* `pan` 的定义是「画布左上角落在地图的哪个像素」——所以取值范围是
|
|
5897
|
+
* `0 .. max(0, 地图 - 视口)`:
|
|
5898
|
+
* · `pan = 0`:地图左上角贴着画布左上角(用户要的「对齐」就是这里);
|
|
5899
|
+
* · `pan = 地图 - 视口`:滚到地图的右下角(地图比视口大时才滚得动);
|
|
5900
|
+
* · 地图比视口小 → 上界为 0 → 钉死在左上角,不会拖出空白。
|
|
5901
|
+
*
|
|
5902
|
+
* ⚠️ 别把符号想反(我第一版就写成了负区间):那样小图能拖进空白、大图反而一步不动,
|
|
5903
|
+
* 真机上「拖了地图纹丝不动 / 复位后又对不齐」就是这么来的。
|
|
5904
|
+
*/
|
|
5905
|
+
const maxX = Math.max(0, layout.width - viewW);
|
|
5906
|
+
const maxY = Math.max(0, layout.height - viewH);
|
|
5907
|
+
return { x: Math.min(maxX, Math.max(0, next.x)), y: Math.min(maxY, Math.max(0, next.y)) };
|
|
5908
|
+
}, [layout]);
|
|
5909
|
+
/**
|
|
5910
|
+
* 入队一批 op。
|
|
5911
|
+
*
|
|
5912
|
+
* 一次按下 → 抬起算**一笔**:拖动期间每 40ms 提交一次,但都带同一个 `stroke`,
|
|
5913
|
+
* 宿主才会并成一条历史;否则一次拖拽要按好几次撤销才回得去。
|
|
5914
|
+
*/
|
|
5915
|
+
const queueOps = React.useCallback((ops, immediate) => {
|
|
5916
|
+
const stroke = currentStroke.current === null ? `s${++strokeSeq.current}` : currentStroke.current;
|
|
5917
|
+
currentStroke.current = immediate === true ? null : stroke;
|
|
5918
|
+
pendingOps.current = pendingOps.current.concat(ops.map((op) => ({ ...op, stroke })));
|
|
5919
|
+
/**
|
|
5920
|
+
* ⚠️ 拖动期间**不再按 40ms 分批提交**,只攒着,等这一笔结束(pointerup /
|
|
5921
|
+
* 指针离开 / 被系统取消)一次性提交。用户要求「一笔画完再自动保存,不要一边画
|
|
5922
|
+
* 一边保存」—— 顺带也把拖动时的往返次数从每秒 25 次降到一笔一次。
|
|
5923
|
+
* 一步完成的编辑(油漆桶 / 一键生成之类)走 `immediate`,立刻提交。
|
|
5924
|
+
*/
|
|
5925
|
+
if (immediate === true) {
|
|
5926
|
+
void flushOps();
|
|
5927
|
+
return;
|
|
5928
|
+
}
|
|
5929
|
+
// 节流预览:让这一笔**看得见**(宿主只算不存),真正的提交仍在 pointerup
|
|
5930
|
+
if (previewTimer.current === null) {
|
|
5931
|
+
previewTimer.current = setTimeout(() => {
|
|
5932
|
+
previewTimer.current = null;
|
|
5933
|
+
setPreviewTick((value) => value + 1);
|
|
5934
|
+
}, 80);
|
|
5935
|
+
}
|
|
5936
|
+
}, [flushOps]);
|
|
5937
|
+
const doUndo = async () => {
|
|
5938
|
+
if (api === undefined || viewId === null)
|
|
5939
|
+
return;
|
|
5940
|
+
try {
|
|
5941
|
+
applyResult(await api.mapUndo({ projectId: viewId, have: [...planRef.current.keys()] }));
|
|
5942
|
+
}
|
|
5943
|
+
catch (error) {
|
|
5944
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
5945
|
+
}
|
|
5946
|
+
finally {
|
|
5947
|
+
}
|
|
5948
|
+
};
|
|
5949
|
+
const doRedo = async () => {
|
|
5950
|
+
if (api === undefined || viewId === null)
|
|
5951
|
+
return;
|
|
5952
|
+
try {
|
|
5953
|
+
applyResult(await api.mapRedo({ projectId: viewId, have: [...planRef.current.keys()] }));
|
|
5954
|
+
}
|
|
5955
|
+
catch (error) {
|
|
5956
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
5957
|
+
}
|
|
5958
|
+
finally {
|
|
5959
|
+
}
|
|
5960
|
+
};
|
|
5961
|
+
// ── 画布命中测试与交互 ───────────────────────────────────────────────
|
|
5962
|
+
const cellFromEvent = React.useCallback((event) => {
|
|
5963
|
+
const canvas = canvasRef.current;
|
|
5964
|
+
if (canvas === null || canvas === undefined || layout === null)
|
|
5965
|
+
return null;
|
|
5966
|
+
const rect = canvas.getBoundingClientRect();
|
|
5967
|
+
const x = (event.clientX - rect.left) / zoom + pan.x;
|
|
5968
|
+
const y = (event.clientY - rect.top) / zoom + pan.y;
|
|
5969
|
+
const hit = MAP_pointToCell(layout, x, y);
|
|
5970
|
+
if (hit.inMap !== true)
|
|
5971
|
+
return null;
|
|
5972
|
+
/**
|
|
5973
|
+
* ⚠️ 只认**地图自己那一份**(未取模坐标落在 0..cols/rows 之内)。
|
|
5974
|
+
*
|
|
5975
|
+
* 环绕地图上,`pointToCell` 会把边界外的位置折回图内,于是「画超过右边缘」会点亮相
|
|
5976
|
+
* 反的左边缘、「超过下边缘」会点亮上边缘 —— 用户报的就是这个。画布上超出地图的那片
|
|
5977
|
+
* 区域本来就是空白,不该有落笔、也不该有红框。
|
|
5978
|
+
*/
|
|
5979
|
+
const rawR = Math.floor(y / layout.stepY);
|
|
5980
|
+
const rawC = Math.floor(x / layout.stepX);
|
|
5981
|
+
if (rawR < 0 || rawC < 0 || rawR >= layout.rows || rawC >= layout.cols)
|
|
5982
|
+
return null;
|
|
5983
|
+
/**
|
|
5984
|
+
* ⚠️ 把**未取模**的地图坐标一起带出去,两个地方都要用:
|
|
5985
|
+
*
|
|
5986
|
+
* 1. 红框:环绕模式下同一格会在屏幕上出现好几次(地图比画布小的时候最常见)。
|
|
5987
|
+
* 只留取模后的 `r/c`,红框就画在「地图内的那一份」上 —— 真机表现是鼠标在左边、
|
|
5988
|
+
* 红框跑到右边一整张地图之外(实测偏差 ≈ 353.6px = 一张地图宽)。
|
|
5989
|
+
* 2. **补间**:`paintCells` 必须按未取模的格号插值。用取模后的格号时,指针跨过
|
|
5990
|
+
* 接缝(右边界那一份的 c=31 → 下一份的 c=0,屏幕上只差十几像素)会被算成
|
|
5991
|
+
* 「从第 31 列走到第 0 列」→ **整行被填满**。真机复现:清空图层后横扫一笔,
|
|
5992
|
+
* 整行 32 格全亮。
|
|
5993
|
+
*/
|
|
5994
|
+
return { r: hit.r, c: hit.c, x, y, rawR, rawC };
|
|
5995
|
+
}, [layout, zoom, pan]);
|
|
5996
|
+
/**
|
|
5997
|
+
* 画笔从一个格拖到另一个格:把中间漏掉的格补上。
|
|
5998
|
+
*
|
|
5999
|
+
* ⚠️ 补间用**未取模**的格号(`rawR` / `rawC`),发出去的也允许越界 —— 宿主
|
|
6000
|
+
* `applyOps` 自己会取模。用取模后的格号补间的话,指针跨过地图接缝时会被算成
|
|
6001
|
+
* 「从第 31 列走到第 0 列」,一笔就把整行填满(真机复现过;横向扫一笔 → 整行 32 格)。
|
|
6002
|
+
* 没有 raw 的(理论上不会,防御式兜底)退回取模格号。
|
|
6003
|
+
*/
|
|
6004
|
+
const paintCells = (from, to, tile) => {
|
|
6005
|
+
if (activeLayer === null)
|
|
6006
|
+
return;
|
|
6007
|
+
const rawOf = (cell) => ({ r: cell.rawR === undefined ? cell.r : cell.rawR, c: cell.rawC === undefined ? cell.c : cell.rawC });
|
|
6008
|
+
const end = rawOf(to);
|
|
6009
|
+
const cells = from === null || from === undefined ? [end] : MAP_lineCells(rawOf(from).r, rawOf(from).c, end.r, end.c);
|
|
6010
|
+
queueOps([{ kind: "paint", layerId: activeLayer.id, cells: cells.map((cell) => ({ r: cell.r, c: cell.c, tile })) }]);
|
|
6011
|
+
};
|
|
6012
|
+
const warnNoBrush = () => {
|
|
6013
|
+
if (brush === null) {
|
|
6014
|
+
setNotice({ kind: "error", text: T("先在左边点一块图当笔刷。") });
|
|
6015
|
+
return true;
|
|
6016
|
+
}
|
|
6017
|
+
return false;
|
|
6018
|
+
};
|
|
6019
|
+
/** 吸管:从宿主给的绘制条目里读「这一格最上面是哪一块」。 */
|
|
6020
|
+
const pickAt = (cell) => {
|
|
6021
|
+
let found = null;
|
|
6022
|
+
for (const key of visibleRef.current) {
|
|
6023
|
+
const ops = planOps.get(key);
|
|
6024
|
+
if (ops === undefined)
|
|
6025
|
+
continue;
|
|
6026
|
+
for (const op of ops) {
|
|
6027
|
+
if (op.r !== cell.r || op.c !== cell.c)
|
|
6028
|
+
continue;
|
|
6029
|
+
if (single === true && op.l !== safeLayerIndex)
|
|
6030
|
+
continue;
|
|
6031
|
+
if (found === null || (op.l ?? 0) >= (found.l ?? 0))
|
|
6032
|
+
found = op;
|
|
6033
|
+
}
|
|
6034
|
+
}
|
|
6035
|
+
if (found === null)
|
|
6036
|
+
return;
|
|
6037
|
+
// ⚠️ 吸管吸到的是**这一格实际贴的那一块**。对拼块素材来说那是一个 16px 小格,
|
|
6038
|
+
// 而调色板里只有该素材的**一个代表笔刷** —— 直接 setBrush(小格) 的话红框找不到
|
|
6039
|
+
// 对应的格子,用户会看到「当前笔刷」凭空消失(真机实测:吸海面后红框没了)。
|
|
6040
|
+
// 所以这里把它归到「拥有它的那个调色板条目」上;普通素材每格都有条目,等于原样。
|
|
6041
|
+
const owner = legendMap.get(found.t);
|
|
6042
|
+
const entries = view === null || view === undefined ? [] : view.tilesets;
|
|
6043
|
+
let index = found.t;
|
|
6044
|
+
if (owner !== undefined) {
|
|
6045
|
+
const tileset = entries.find((entry) => entry.id === owner.tilesetId);
|
|
6046
|
+
const palette = tileset === undefined ? [] : tileset.palette;
|
|
6047
|
+
if (palette.length > 0 && !palette.some((entry) => entry.index === found.t))
|
|
6048
|
+
index = palette[0].index;
|
|
6049
|
+
}
|
|
6050
|
+
setBrush({ index });
|
|
6051
|
+
setMulti([index]);
|
|
6052
|
+
};
|
|
6053
|
+
const zoomAt = (clientX, clientY, factor) => {
|
|
6054
|
+
const canvas = canvasRef.current;
|
|
6055
|
+
if (canvas === null || canvas === undefined)
|
|
6056
|
+
return;
|
|
6057
|
+
const rect = canvas.getBoundingClientRect();
|
|
6058
|
+
const prev = zoomRef.current;
|
|
6059
|
+
const next = Math.min(8, Math.max(0.25, prev * factor));
|
|
6060
|
+
const mapX = (clientX - rect.left) / prev + panRef.current.x;
|
|
6061
|
+
const mapY = (clientY - rect.top) / prev + panRef.current.y;
|
|
6062
|
+
setZoom(next);
|
|
6063
|
+
setPan((prev) => clampPan({ x: mapX - (clientX - rect.left) / next, y: mapY - (clientY - rect.top) / next }));
|
|
6064
|
+
};
|
|
6065
|
+
// 原生滚轮监听要在事件到来时拿到**最新**的 zoomAt(它闭包了 zoom/pan),
|
|
6066
|
+
// 所以用 ref 转发,而不是把 zoomAt 塞进 effect 依赖(那会每帧重新挂监听)。
|
|
6067
|
+
zoomAtRef.current = zoomAt;
|
|
6068
|
+
const onPointerDown = (event) => {
|
|
6069
|
+
if (layout === null)
|
|
6070
|
+
return;
|
|
6071
|
+
if (typeof event.preventDefault === "function")
|
|
6072
|
+
event.preventDefault();
|
|
6073
|
+
const canvas = canvasRef.current;
|
|
6074
|
+
if (canvas !== null && canvas !== undefined && typeof canvas.setPointerCapture === "function" && event.pointerId !== undefined) {
|
|
6075
|
+
try {
|
|
6076
|
+
canvas.setPointerCapture(event.pointerId);
|
|
6077
|
+
}
|
|
6078
|
+
catch {
|
|
6079
|
+
// 捕获失败不影响画图,只是拖出画布后会断线。
|
|
6080
|
+
}
|
|
6081
|
+
}
|
|
6082
|
+
const pointerId = event.pointerId === undefined ? 1 : event.pointerId;
|
|
6083
|
+
pointersRef.current.set(pointerId, { x: event.clientX, y: event.clientY });
|
|
6084
|
+
if (pointersRef.current.size === 2) {
|
|
6085
|
+
const [a, b] = [...pointersRef.current.values()];
|
|
6086
|
+
strokeRef.current = null;
|
|
6087
|
+
currentStroke.current = null;
|
|
6088
|
+
pointersRef.current.pinch = { distance: Math.hypot(a.x - b.x, a.y - b.y) };
|
|
6089
|
+
return;
|
|
6090
|
+
}
|
|
6091
|
+
const hit = cellFromEvent(event);
|
|
6092
|
+
if (hit === null)
|
|
6093
|
+
return;
|
|
6094
|
+
if (tool === "hand" || event.button === 1 || spaceRef.current === true) {
|
|
6095
|
+
strokeRef.current = { mode: "pan", clientX: event.clientX, clientY: event.clientY, pan: { ...pan } };
|
|
6096
|
+
return;
|
|
6097
|
+
}
|
|
6098
|
+
if (tool === "marker") {
|
|
6099
|
+
const existing = markerAtCell(hit.r, hit.c);
|
|
6100
|
+
if (event.button === 2) {
|
|
6101
|
+
if (existing !== undefined)
|
|
6102
|
+
void markerOp({ kind: "marker", op: "remove", id: existing.id }, true);
|
|
6103
|
+
return;
|
|
6104
|
+
}
|
|
6105
|
+
if (existing !== undefined) {
|
|
6106
|
+
// 点已有标记 = 选中它(图层卡里就能改名);按住拖到别的格就是挪位置。
|
|
6107
|
+
setMarkerSel(existing.id);
|
|
6108
|
+
strokeRef.current = { mode: "marker", id: existing.id, from: { r: hit.r, c: hit.c } };
|
|
6109
|
+
return;
|
|
6110
|
+
}
|
|
6111
|
+
void markerOp({ kind: "marker", op: "add", r: hit.r, c: hit.c }, true);
|
|
6112
|
+
return;
|
|
6113
|
+
}
|
|
6114
|
+
if (event.button === 2 || tool === "eraser") {
|
|
6115
|
+
currentStroke.current = null;
|
|
6116
|
+
strokeRef.current = { mode: "paint", from: hit, tile: 0 };
|
|
6117
|
+
paintCells(null, hit, 0);
|
|
6118
|
+
return;
|
|
6119
|
+
}
|
|
6120
|
+
if (tool === "pipette") {
|
|
6121
|
+
pickAt(hit);
|
|
6122
|
+
return;
|
|
6123
|
+
}
|
|
6124
|
+
if (tool === "bucket") {
|
|
6125
|
+
if (warnNoBrush() || activeLayer === null)
|
|
6126
|
+
return;
|
|
6127
|
+
queueOps([{ kind: "fill", layerId: activeLayer.id, r: hit.r, c: hit.c, tile: brush.index }], true);
|
|
6128
|
+
return;
|
|
6129
|
+
}
|
|
6130
|
+
if (warnNoBrush())
|
|
6131
|
+
return;
|
|
6132
|
+
currentStroke.current = null;
|
|
6133
|
+
strokeRef.current = { mode: "paint", from: hit, tile: brush.index };
|
|
6134
|
+
paintCells(null, hit, brush.index);
|
|
6135
|
+
};
|
|
6136
|
+
const onPointerMove = (event) => {
|
|
6137
|
+
if (layout === null)
|
|
6138
|
+
return;
|
|
6139
|
+
const pointerId = event.pointerId === undefined ? 1 : event.pointerId;
|
|
6140
|
+
if (pointersRef.current.has(pointerId))
|
|
6141
|
+
pointersRef.current.set(pointerId, { x: event.clientX, y: event.clientY });
|
|
6142
|
+
const pinch = pointersRef.current.pinch;
|
|
6143
|
+
if (pinch !== undefined && pointersRef.current.size === 2) {
|
|
6144
|
+
const [a, b] = [...pointersRef.current.values()];
|
|
6145
|
+
const distance = Math.hypot(a.x - b.x, a.y - b.y);
|
|
6146
|
+
if (pinch.distance > 0)
|
|
6147
|
+
zoomAt((a.x + b.x) / 2, (a.y + b.y) / 2, distance / pinch.distance);
|
|
6148
|
+
pinch.distance = distance;
|
|
6149
|
+
return;
|
|
6150
|
+
}
|
|
6151
|
+
const stroke = strokeRef.current;
|
|
6152
|
+
if (stroke !== null && stroke !== undefined && stroke.mode === "pan") {
|
|
6153
|
+
setPan(clampPan({
|
|
6154
|
+
x: stroke.pan.x - (event.clientX - stroke.clientX) / zoom,
|
|
6155
|
+
y: stroke.pan.y - (event.clientY - stroke.clientY) / zoom
|
|
6156
|
+
}));
|
|
6157
|
+
return;
|
|
6158
|
+
}
|
|
6159
|
+
const hit = cellFromEvent(event);
|
|
6160
|
+
if (hit === null) {
|
|
6161
|
+
setHover((prev) => (prev === null ? prev : null));
|
|
6162
|
+
return;
|
|
6163
|
+
}
|
|
6164
|
+
/**
|
|
6165
|
+
* ⚠️ 同一格内移动**不要**换新对象。`hover` 是绘制回调的依赖,换对象 = 整幅重画;
|
|
6166
|
+
* 拖动时每秒几十个 `pointermove`,一格又往往走上好几个事件,于是每秒几十次
|
|
6167
|
+
* 「清屏 + 重画所有条目」——真机表现就是画布一直在闪、CPU 一直满。
|
|
6168
|
+
* 红框是按格对齐的,格号没变画面就没变,返回同一个对象让 React 直接跳过这次渲染。
|
|
6169
|
+
*/
|
|
6170
|
+
setHover((prev) => (prev !== null && prev.r === hit.r && prev.c === hit.c ? prev : hit));
|
|
6171
|
+
if (stroke !== null && stroke !== undefined && stroke.mode === "marker") {
|
|
6172
|
+
// 每跨一格提交一次(挪位置不改编号,所以**不重读视图**;松手时补一次)。
|
|
6173
|
+
if (stroke.from.r !== hit.r || stroke.from.c !== hit.c) {
|
|
6174
|
+
stroke.from = { r: hit.r, c: hit.c };
|
|
6175
|
+
void markerOp({ kind: "marker", op: "move", id: stroke.id, r: hit.r, c: hit.c }, false);
|
|
6176
|
+
}
|
|
6177
|
+
return;
|
|
6178
|
+
}
|
|
6179
|
+
if (stroke !== null && stroke !== undefined && stroke.mode === "paint") {
|
|
6180
|
+
if (stroke.from.r !== hit.r || stroke.from.c !== hit.c) {
|
|
6181
|
+
paintCells(stroke.from, hit, stroke.tile);
|
|
6182
|
+
stroke.from = hit;
|
|
6183
|
+
}
|
|
6184
|
+
}
|
|
6185
|
+
};
|
|
6186
|
+
const onPointerUp = (event) => {
|
|
6187
|
+
const pointerId = event.pointerId === undefined ? 1 : event.pointerId;
|
|
6188
|
+
pointersRef.current.delete(pointerId);
|
|
6189
|
+
if (pointersRef.current.size < 2)
|
|
6190
|
+
delete pointersRef.current.pinch;
|
|
6191
|
+
const stroke = strokeRef.current;
|
|
6192
|
+
strokeRef.current = null;
|
|
6193
|
+
currentStroke.current = null;
|
|
6194
|
+
void flushOps();
|
|
6195
|
+
// 拖完标记补读一次视图:拖动期间刻意没读(每格读一次太吵),列表里的坐标要跟上。
|
|
6196
|
+
if (stroke !== null && stroke !== undefined && stroke.mode === "marker" && api !== undefined && viewId !== null) {
|
|
6197
|
+
void loadProject(viewId, true);
|
|
6198
|
+
}
|
|
6199
|
+
};
|
|
6200
|
+
// 快捷键:B/E/G/I/H/V 与撤销重做;焦点在输入框里时全部失效
|
|
6201
|
+
React.useEffect(() => {
|
|
6202
|
+
const editable = (target) => target !== null && target !== undefined && /^(INPUT|TEXTAREA|SELECT)$/.test(target.tagName || "");
|
|
6203
|
+
const onKeyDown = (event) => {
|
|
6204
|
+
if (String(event.key) === " ") {
|
|
6205
|
+
spaceRef.current = true;
|
|
6206
|
+
if (editable(event.target) !== true && typeof event.preventDefault === "function")
|
|
6207
|
+
event.preventDefault();
|
|
6208
|
+
return;
|
|
6209
|
+
}
|
|
6210
|
+
const meta = event.metaKey === true || event.ctrlKey === true;
|
|
6211
|
+
if (meta === true) {
|
|
6212
|
+
if (editable(event.target) === true)
|
|
6213
|
+
return;
|
|
6214
|
+
const key = String(event.key).toLowerCase();
|
|
6215
|
+
if (key === "z" && event.shiftKey === true) {
|
|
6216
|
+
event.preventDefault();
|
|
6217
|
+
void doRedo();
|
|
6218
|
+
return;
|
|
6219
|
+
}
|
|
6220
|
+
if (key === "z" || key === "y") {
|
|
6221
|
+
event.preventDefault();
|
|
6222
|
+
void doUndo();
|
|
6223
|
+
}
|
|
6224
|
+
return;
|
|
6225
|
+
}
|
|
6226
|
+
if (editable(event.target) === true)
|
|
6227
|
+
return;
|
|
6228
|
+
const key = String(event.key).toLowerCase();
|
|
6229
|
+
if (key === "b")
|
|
6230
|
+
setTool("pen");
|
|
6231
|
+
else if (key === "e")
|
|
6232
|
+
setTool("eraser");
|
|
6233
|
+
else if (key === "g")
|
|
6234
|
+
setTool("bucket");
|
|
6235
|
+
else if (key === "i")
|
|
6236
|
+
setTool("pipette");
|
|
6237
|
+
else if (key === "h")
|
|
6238
|
+
setTool("hand");
|
|
6239
|
+
else if (key === "m")
|
|
6240
|
+
setTool("marker");
|
|
6241
|
+
else if (key === "v")
|
|
6242
|
+
setSingle((value) => value !== true);
|
|
6243
|
+
};
|
|
6244
|
+
const onKeyUp = (event) => {
|
|
6245
|
+
if (String(event.key) === " ")
|
|
6246
|
+
spaceRef.current = false;
|
|
6247
|
+
};
|
|
6248
|
+
window.addEventListener("keydown", onKeyDown);
|
|
6249
|
+
window.addEventListener("keyup", onKeyUp);
|
|
6250
|
+
return () => {
|
|
6251
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
6252
|
+
window.removeEventListener("keyup", onKeyUp);
|
|
6253
|
+
};
|
|
6254
|
+
});
|
|
6255
|
+
// ── 项目与素材的动作 ─────────────────────────────────────────────────
|
|
6256
|
+
const ensureTwoLayers = async (projectId) => {
|
|
6257
|
+
const next = await api.getMapProject({ projectId });
|
|
6258
|
+
if (((next.layers || []).length) < 2)
|
|
6259
|
+
await api.saveMapDoc({ projectId, addLayer: { name: T("图层 2") } });
|
|
6260
|
+
};
|
|
6261
|
+
/** 没有项目就地建一个:32×32、两层,建完就能画。 */
|
|
6262
|
+
const ensureProject = async () => {
|
|
6263
|
+
if (viewId !== null)
|
|
6264
|
+
return viewId;
|
|
6265
|
+
const created = await api.createMapProject({ name: T("我的地图"), cols: 32, rows: 32 });
|
|
6266
|
+
setProjects((prev) => [{ id: created.id, name: created.name }, ...prev]);
|
|
6267
|
+
await ensureTwoLayers(created.id);
|
|
6268
|
+
return created.id;
|
|
6269
|
+
};
|
|
6270
|
+
const readBase64 = (file) => new Promise((resolve, reject) => {
|
|
6271
|
+
const reader = new FileReader();
|
|
6272
|
+
reader.onload = () => resolve(String(reader.result).split(",")[1] || "");
|
|
6273
|
+
reader.onerror = () => reject(new Error(T("读文件失败")));
|
|
6274
|
+
reader.readAsDataURL(file);
|
|
6275
|
+
});
|
|
6276
|
+
const startWithFile = async (file) => {
|
|
6277
|
+
if (file === undefined || file === null || api === undefined)
|
|
6278
|
+
return;
|
|
6279
|
+
setBusyKey("upload");
|
|
6280
|
+
try {
|
|
6281
|
+
const projectId = await ensureProject();
|
|
6282
|
+
const base64 = await readBase64(file);
|
|
6283
|
+
const imported = await api.importMapTileset({ projectId, name: file.name, data: base64 });
|
|
6284
|
+
if (imported !== undefined && Array.isArray(imported.warnings) && imported.warnings.length > 0) {
|
|
6285
|
+
setNotice({ kind: "info", text: imported.warnings.join(";") });
|
|
6286
|
+
}
|
|
6287
|
+
else {
|
|
6288
|
+
setNotice({ kind: "info", text: T("已导入 {n0}", { n0: file.name }) });
|
|
6289
|
+
}
|
|
6290
|
+
await loadProject(projectId);
|
|
6291
|
+
const result = await api.listMapProjects();
|
|
6292
|
+
setProjects(result.projects || []);
|
|
6293
|
+
setOpenCard("assets");
|
|
6294
|
+
}
|
|
6295
|
+
catch (error) {
|
|
6296
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
6297
|
+
}
|
|
6298
|
+
finally {
|
|
6299
|
+
setBusyKey(null);
|
|
6300
|
+
}
|
|
6301
|
+
};
|
|
6302
|
+
const startWithSample = async () => {
|
|
6303
|
+
if (api === undefined)
|
|
6304
|
+
return;
|
|
6305
|
+
setBusyKey("sample");
|
|
6306
|
+
try {
|
|
6307
|
+
const projectId = await ensureProject();
|
|
6308
|
+
await api.importSampleTileset({ projectId });
|
|
6309
|
+
await loadProject(projectId);
|
|
6310
|
+
const result = await api.listMapProjects();
|
|
6311
|
+
setProjects(result.projects || []);
|
|
6312
|
+
setOpenCard("assets");
|
|
6313
|
+
}
|
|
6314
|
+
catch (error) {
|
|
6315
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
6316
|
+
}
|
|
6317
|
+
finally {
|
|
6318
|
+
setBusyKey(null);
|
|
6319
|
+
}
|
|
6320
|
+
};
|
|
6321
|
+
/** 打开「新增素材」:草稿全空 = 一切都走自动识别。 */
|
|
6322
|
+
const openAddTileset = () => setAddDraft({ file: null, name: "", cellW: "", cellH: "", shape: "auto", animRows: false });
|
|
6323
|
+
/**
|
|
6324
|
+
* 提交新增:把「图片 + 名字 + 属性」一次性交给宿主。
|
|
6325
|
+
*
|
|
6326
|
+
* 留空的项不发(宿主按自动识别处理);只有用户真的填了才带上,避免用空值把识别结果顶掉。
|
|
6327
|
+
*/
|
|
6328
|
+
const submitAddTileset = async () => {
|
|
6329
|
+
const draft = addDraft;
|
|
6330
|
+
if (draft === null || api === undefined)
|
|
6331
|
+
return;
|
|
6332
|
+
if (draft.file === null) {
|
|
6333
|
+
setNotice({ kind: "error", text: T("先选一张素材图。") });
|
|
6334
|
+
return;
|
|
6335
|
+
}
|
|
6336
|
+
const projectId = await ensureProject();
|
|
6337
|
+
if (projectId === null)
|
|
6338
|
+
return;
|
|
6339
|
+
setBusyKey("upload");
|
|
6340
|
+
try {
|
|
6341
|
+
const base64 = await readBase64(draft.file);
|
|
6342
|
+
const cell = draft.cellW !== "" && draft.cellH !== "" ? { width: Number(draft.cellW), height: Number(draft.cellH) } : undefined;
|
|
6343
|
+
const imported = await api.importMapTileset({
|
|
6344
|
+
projectId,
|
|
6345
|
+
name: draft.name.trim() === "" ? draft.file.name : draft.name.trim(),
|
|
6346
|
+
data: base64,
|
|
6347
|
+
cell,
|
|
6348
|
+
shape: draft.shape === "auto" ? undefined : draft.shape,
|
|
6349
|
+
animRows: draft.animRows === true
|
|
6350
|
+
});
|
|
6351
|
+
setAddDraft(null);
|
|
6352
|
+
setNotice({ kind: "info", text: T("已新增素材 {n0}", { n0: draft.name.trim() === "" ? draft.file.name : draft.name.trim() }) });
|
|
6353
|
+
if (imported !== undefined && Array.isArray(imported.warnings) && imported.warnings.length > 0) {
|
|
6354
|
+
setNotice({ kind: "info", text: imported.warnings.join(";") });
|
|
6355
|
+
}
|
|
6356
|
+
await loadProject(projectId);
|
|
6357
|
+
const list = await api.listMapProjects();
|
|
6358
|
+
setProjects(list.projects || []);
|
|
6359
|
+
setOpenCard("assets");
|
|
6360
|
+
// 新加的那张直接选上(列表最后一张)
|
|
6361
|
+
const fresh = await api.listMapProjects();
|
|
6362
|
+
void fresh;
|
|
6363
|
+
}
|
|
6364
|
+
catch (error) {
|
|
6365
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
6366
|
+
}
|
|
6367
|
+
finally {
|
|
6368
|
+
setBusyKey(null);
|
|
6369
|
+
}
|
|
6370
|
+
};
|
|
6371
|
+
/** 删掉列表里的某一张(内置也能删)。 */
|
|
6372
|
+
/**
|
|
6373
|
+
* 「这块素材怎么用」的四个选项:`[值, 按钮短标签, 悬停小标签标题, 解释]`。
|
|
6374
|
+
*
|
|
6375
|
+
* ⚠️ 原来是个 `<select>`,而原生 `<option>` **挂不了 tooltip** —— 可「自动 / 普通图块 /
|
|
6376
|
+
* 整格自动连接 / 拼块自动连接」这四个词对非专业用户等于没说(用户原话:意义不明)。
|
|
6377
|
+
* 换成四个按钮 + 悬停小标签:鼠标移上去就把这一项讲清楚(和工具格同一套标签)。
|
|
6378
|
+
*/
|
|
6379
|
+
const shapeOptions = [
|
|
6380
|
+
["auto", T("自动"), T("自动"), T("按图片尺寸自己认格子与用法。想重新认一次,就再上传一遍这张图。")],
|
|
6381
|
+
["plain", T("普通"), T("普通图块"), T("一格贴一块图,不做任何拼接。")],
|
|
6382
|
+
["corner16", T("整格"), T("整格自动连接"), T("按上下左右有没有同样的格子,自动从 16 块里挑一块:边缘、拐角会自己接上。")],
|
|
6383
|
+
["a2quad", T("拼块"), T("拼块自动连接"), T("一小格再拆成 2×2 小块,按邻居自动拼成一片。草地、水面这类连着画的地面用它。")]
|
|
6384
|
+
];
|
|
6385
|
+
/**
|
|
6386
|
+
* 一段「几个按钮里选一个」的控件(用法、会动吗都用它)。
|
|
6387
|
+
*
|
|
6388
|
+
* 对话框里的选择只改**草稿**,点「确定」才交给宿主 —— 属性一旦定下来就不能改了,
|
|
6389
|
+
* 不该边点边写。
|
|
6390
|
+
*/
|
|
6391
|
+
const segPicker = (attr, options, current, onPick) => h("div", { className: "SPR_mapEdSeg" }, options.map(([value, short, title, desc]) => h("button", {
|
|
6392
|
+
key: value,
|
|
6393
|
+
type: "button",
|
|
6394
|
+
className: "SPR_mapEdSegBtn",
|
|
6395
|
+
[attr]: value,
|
|
6396
|
+
"data-on": current === value ? "true" : undefined,
|
|
6397
|
+
"aria-label": `${title}:${desc}`,
|
|
6398
|
+
onMouseEnter: showToolTip(title, desc, null),
|
|
6399
|
+
onFocus: showToolTip(title, desc, null),
|
|
6400
|
+
onMouseLeave: hideToolTip,
|
|
6401
|
+
onBlur: hideToolTip,
|
|
6402
|
+
onClick: () => onPick(value)
|
|
6403
|
+
}, short)));
|
|
6404
|
+
const animOptions = [
|
|
6405
|
+
["off", T("不动"), T("不动"), T("这张图当作一堆静止的图块。")],
|
|
6406
|
+
["rows", T("翻页图"), T("翻页图"), T("像手翻书:每一行是一页,连着播就动起来了。同一列的几行算同一块,画的时候点哪一行都行,整片会一起动。")]
|
|
6407
|
+
];
|
|
6408
|
+
/** 「新增素材」对话框:图片 + 名字 + 属性一次填完,之后只能删。 */
|
|
6409
|
+
const addDialog = addDraft === null
|
|
6410
|
+
? null
|
|
6411
|
+
: h("div", { className: "SPR_mapEdDlgMask", "data-testid": "map-add-mask", onClick: () => setAddDraft(null) }, h("div", {
|
|
6412
|
+
className: "SPR_mapEdDlg",
|
|
6413
|
+
role: "dialog",
|
|
6414
|
+
"aria-label": T("新增素材"),
|
|
6415
|
+
"data-testid": "map-add-dialog",
|
|
6416
|
+
onClick: (event) => {
|
|
6417
|
+
if (typeof event.stopPropagation === "function")
|
|
6418
|
+
event.stopPropagation();
|
|
6419
|
+
}
|
|
6420
|
+
}, h("div", { className: "SPR_mapEdDlgTitle" }, T("新增素材")), h("div", { className: "SPR_mapEdDlgLabel" }, T("素材图")), h("div", { className: "SPR_mapEdDlgRow" }, h(Btn, { onClick: () => addFileRef.current?.click() }, T("选择图片")), h("span", { className: "SPR_mapEdHint" }, addDraft.file === null ? T("还没选") : addDraft.file.name)), h("div", { className: "SPR_mapEdDlgLabel" }, T("叫什么")), h("input", {
|
|
6421
|
+
className: "SPR_mapEdDlgInput",
|
|
6422
|
+
"data-testid": "map-add-name",
|
|
6423
|
+
value: addDraft.name,
|
|
6424
|
+
placeholder: T("留空就用文件名"),
|
|
6425
|
+
onChange: (event) => setAddDraft((current) => (current === null ? current : { ...current, name: event.target.value }))
|
|
6426
|
+
}), h("div", { className: "SPR_mapEdDlgLabel" }, T("格子大小(留空就自动认)")), h("div", { className: "SPR_mapEdPair" }, h(NumField, {
|
|
6427
|
+
label: T("宽"),
|
|
6428
|
+
value: addDraft.cellW === "" ? "" : Number(addDraft.cellW),
|
|
6429
|
+
min: 1,
|
|
6430
|
+
max: 1024,
|
|
6431
|
+
onChange: (value) => setAddDraft((current) => (current === null ? current : { ...current, cellW: String(value) }))
|
|
6432
|
+
}), h("span", { className: "SPR_mapEdTimes" }, "×"), h(NumField, {
|
|
6433
|
+
label: T("高"),
|
|
6434
|
+
value: addDraft.cellH === "" ? "" : Number(addDraft.cellH),
|
|
6435
|
+
min: 1,
|
|
6436
|
+
max: 1024,
|
|
6437
|
+
onChange: (value) => setAddDraft((current) => (current === null ? current : { ...current, cellH: String(value) }))
|
|
6438
|
+
})), h("div", { className: "SPR_mapEdDlgLabel" }, T("这块素材怎么用")), segPicker("data-shape", shapeOptions, addDraft.shape, (value) => setAddDraft((current) => (current === null ? current : { ...current, shape: value }))), h("div", { className: "SPR_mapEdDlgLabel" }, T("会动吗")), segPicker("data-anim", animOptions, addDraft.animRows ? "rows" : "off", (value) => setAddDraft((current) => (current === null ? current : { ...current, animRows: value === "rows" }))), h("div", { className: "SPR_mapEdDlgRow" }, h(Btn, { "data-testid": "map-add-cancel", onClick: () => setAddDraft(null) }, T("取消")), h(Btn, { "data-testid": "map-add-ok", primary: true, busy: busyKey === "upload", onClick: () => void submitAddTileset() }, T("确定")))));
|
|
6439
|
+
const removeTilesetById = async (tilesetId, tilesetName) => {
|
|
6440
|
+
if (view === null || api === undefined)
|
|
6441
|
+
return;
|
|
6442
|
+
// eslint-disable-next-line no-alert
|
|
6443
|
+
if (typeof window !== "undefined" && !window.confirm(T("确定删除素材「{n0}」?它切出来的块会一起删掉,无法撤销。", { n0: tilesetName })))
|
|
6444
|
+
return;
|
|
6445
|
+
const result = await withApi(() => api.removeMapTileset({ projectId: view.id, tilesetId }), { notice: T("已删除素材") });
|
|
6446
|
+
if (result === undefined)
|
|
6447
|
+
return;
|
|
6448
|
+
await loadProject(view.id, true);
|
|
6449
|
+
};
|
|
6450
|
+
/** 一键恢复默认素材:把缺的内置素材补回来(已有的同名会跳过,不会变成两份)。 */
|
|
6451
|
+
const restoreSamples = async () => {
|
|
6452
|
+
if (api === undefined)
|
|
6453
|
+
return;
|
|
6454
|
+
setBusyKey("sample");
|
|
6455
|
+
try {
|
|
6456
|
+
const projectId = await ensureProject();
|
|
6457
|
+
if (projectId === null)
|
|
6458
|
+
return;
|
|
6459
|
+
const restored = await api.importSampleTileset({ projectId });
|
|
6460
|
+
const added = Array.isArray(restored?.tilesets) ? restored.tilesets.length : 0;
|
|
6461
|
+
setNotice({ kind: "info", text: added > 0 ? T("已恢复 {n0} 张默认素材", { n0: String(added) }) : T("默认素材都在。") });
|
|
6462
|
+
await loadProject(projectId, true);
|
|
6463
|
+
const list = await api.listMapProjects();
|
|
6464
|
+
setProjects(list.projects || []);
|
|
6465
|
+
}
|
|
6466
|
+
catch (error) {
|
|
6467
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
6468
|
+
}
|
|
6469
|
+
finally {
|
|
6470
|
+
setBusyKey(null);
|
|
6471
|
+
}
|
|
6472
|
+
};
|
|
6473
|
+
/**
|
|
6474
|
+
* 新建 / 重命名项目:**自己弹一个窗口**,不用 `window.prompt`。
|
|
6475
|
+
*
|
|
6476
|
+
* ⚠️ 真机踩过:DSH 桌面端是 Electron,而 Electron **不实现 `window.prompt`**
|
|
6477
|
+
* (函数在、调用直接抛错)。原来「新建项目」点了什么都不发生,就是因为名字拿不到 ——
|
|
6478
|
+
* 而且 `typeof window.prompt === "function"` 这个判断完全看不出来。
|
|
6479
|
+
* 所以这里改成本地渲染的对话框:输入框 + 取消 / 确定,回车确认、Esc 取消。
|
|
6480
|
+
*/
|
|
6481
|
+
const [nameAsk, setNameAsk] = React.useState(null);
|
|
6482
|
+
const askProjectName = (mode) => setNameAsk({
|
|
6483
|
+
mode,
|
|
6484
|
+
title: mode === "create" ? T("新建项目") : T("重命名项目"),
|
|
6485
|
+
label: mode === "create" ? T("新项目的名字") : T("新的项目名"),
|
|
6486
|
+
value: mode === "create" ? T("我的地图") : view === null ? "" : view.name
|
|
6487
|
+
});
|
|
6488
|
+
const submitNameAsk = async () => {
|
|
6489
|
+
const ask = nameAsk;
|
|
6490
|
+
if (ask === null)
|
|
6491
|
+
return;
|
|
6492
|
+
const trimmed = String(ask.value).trim();
|
|
6493
|
+
// 新建:空名用默认名(用户的意图是「建一个」,不该被空字符串卡住);
|
|
6494
|
+
// 重命名:空名等于没改,直接关掉。
|
|
6495
|
+
if (ask.mode === "rename" && trimmed === "") {
|
|
6496
|
+
setNameAsk(null);
|
|
6497
|
+
return;
|
|
6498
|
+
}
|
|
6499
|
+
setNameAsk(null);
|
|
6500
|
+
if (ask.mode === "create")
|
|
6501
|
+
await createProject(trimmed === "" ? T("我的地图") : trimmed);
|
|
6502
|
+
else
|
|
6503
|
+
await renameProject(trimmed);
|
|
6504
|
+
};
|
|
6505
|
+
/** 名字对话框。`position:fixed` 居中,不用原生 prompt / confirm。 */
|
|
6506
|
+
const nameDialog = nameAsk === null
|
|
6507
|
+
? null
|
|
6508
|
+
: h("div", { className: "SPR_mapEdDlgMask", "data-testid": "map-name-mask", onClick: () => setNameAsk(null) }, h("div", {
|
|
6509
|
+
className: "SPR_mapEdDlg",
|
|
6510
|
+
role: "dialog",
|
|
6511
|
+
"aria-label": nameAsk.title,
|
|
6512
|
+
"data-testid": "map-name-dialog",
|
|
6513
|
+
onClick: (event) => {
|
|
6514
|
+
if (typeof event.stopPropagation === "function")
|
|
6515
|
+
event.stopPropagation();
|
|
6516
|
+
}
|
|
6517
|
+
}, h("div", { className: "SPR_mapEdDlgTitle" }, nameAsk.title), h("label", { className: "SPR_mapEdDlgLabel" }, nameAsk.label), h("input", {
|
|
6518
|
+
className: "SPR_mapEdDlgInput",
|
|
6519
|
+
"data-testid": "map-name-input",
|
|
6520
|
+
value: nameAsk.value,
|
|
6521
|
+
autoFocus: true,
|
|
6522
|
+
onChange: (event) => setNameAsk((current) => (current === null ? current : { ...current, value: event.target.value })),
|
|
6523
|
+
onKeyDown: (event) => {
|
|
6524
|
+
if (event.key === "Enter") {
|
|
6525
|
+
if (typeof event.preventDefault === "function")
|
|
6526
|
+
event.preventDefault();
|
|
6527
|
+
void submitNameAsk();
|
|
6528
|
+
}
|
|
6529
|
+
else if (event.key === "Escape") {
|
|
6530
|
+
setNameAsk(null);
|
|
6531
|
+
}
|
|
6532
|
+
}
|
|
6533
|
+
}), h("div", { className: "SPR_mapEdDlgRow" }, h(Btn, { "data-testid": "map-name-cancel", onClick: () => setNameAsk(null) }, T("取消")), h(Btn, { "data-testid": "map-name-ok", primary: true, onClick: () => void submitNameAsk() }, T("确定")))));
|
|
6534
|
+
const removeTileset = async () => {
|
|
6535
|
+
if (view === null || tileset === null || api === undefined)
|
|
6536
|
+
return;
|
|
6537
|
+
// eslint-disable-next-line no-alert
|
|
6538
|
+
if (typeof window !== "undefined" && !window.confirm(T("确定删除素材「{n0}」?它切出来的块会一起删掉,无法撤销。", { n0: tileset.name })))
|
|
6539
|
+
return;
|
|
6540
|
+
const result = await withApi(() => api.removeMapTileset({ projectId: view.id, tilesetId: tileset.id }), { notice: T("已删除素材") });
|
|
6541
|
+
if (result === undefined)
|
|
6542
|
+
return;
|
|
6543
|
+
await loadProject(view.id);
|
|
6544
|
+
};
|
|
6545
|
+
/**
|
|
6546
|
+
* 新建项目。**建完就把内置素材装进列表**(用户要求:内置素材默认在素材列表里)——
|
|
6547
|
+
* 装的是本机现算的那套,零成本;同名已存在会跳过。
|
|
6548
|
+
*/
|
|
6549
|
+
const createProject = async (name) => {
|
|
6550
|
+
if (api === undefined)
|
|
6551
|
+
return;
|
|
6552
|
+
const created = await withApi(() => api.createMapProject({ name, cols: 32, rows: 32 }));
|
|
6553
|
+
if (created === undefined)
|
|
6554
|
+
return;
|
|
6555
|
+
await ensureTwoLayers(created.id);
|
|
6556
|
+
const result = await api.listMapProjects();
|
|
6557
|
+
setProjects(result.projects || []);
|
|
6558
|
+
await loadProject(created.id);
|
|
6559
|
+
// 新项目默认就带上内置素材(同名会跳过),装完再刷一次列表
|
|
6560
|
+
await api.importSampleTileset({ projectId: created.id }).catch(() => undefined);
|
|
6561
|
+
await loadProject(created.id, true);
|
|
6562
|
+
setOpenCard("assets");
|
|
6563
|
+
};
|
|
6564
|
+
const renameProject = async (name) => {
|
|
6565
|
+
if (view === null || api === undefined)
|
|
6566
|
+
return;
|
|
6567
|
+
const ok = await withApi(() => api.saveMapProject({ projectId: view.id, name }), { notice: T("已重命名") });
|
|
6568
|
+
if (ok === undefined)
|
|
6569
|
+
return;
|
|
6570
|
+
await loadProject(view.id, true);
|
|
6571
|
+
};
|
|
6572
|
+
const deleteProject = async () => {
|
|
6573
|
+
if (view === null || api === undefined)
|
|
6574
|
+
return;
|
|
6575
|
+
// eslint-disable-next-line no-alert
|
|
6576
|
+
if (typeof window !== "undefined" && !window.confirm(T("确定删除项目「{n0}」?项目目录会被整个移除,无法撤销。", { n0: view.name })))
|
|
6577
|
+
return;
|
|
6578
|
+
const done = await withApi(() => api.deleteMapProject({ projectId: view.id }), { notice: T("已删除项目") });
|
|
6579
|
+
if (done === undefined)
|
|
6580
|
+
return;
|
|
6581
|
+
const result = await api.listMapProjects();
|
|
6582
|
+
const rest = result.projects || [];
|
|
6583
|
+
setProjects(rest);
|
|
6584
|
+
if (rest.length > 0)
|
|
6585
|
+
await loadProject(rest[0].id);
|
|
6586
|
+
else {
|
|
6587
|
+
clearPlan();
|
|
6588
|
+
setView(null);
|
|
6589
|
+
}
|
|
6590
|
+
};
|
|
6591
|
+
const saveDoc = async (patch, note) => {
|
|
6592
|
+
if (view === null || api === undefined)
|
|
6593
|
+
return undefined;
|
|
6594
|
+
const result = await withApi(() => api.saveMapDoc({ projectId: view.id, ...patch }), note === undefined ? undefined : { notice: note });
|
|
6595
|
+
if (result === undefined)
|
|
6596
|
+
return undefined;
|
|
6597
|
+
const warnings = result.warnings;
|
|
6598
|
+
if (Array.isArray(warnings) && warnings.length > 0)
|
|
6599
|
+
setNotice({ kind: "info", text: warnings.join(";") });
|
|
6600
|
+
await loadProject(view.id, true);
|
|
6601
|
+
return result;
|
|
6602
|
+
};
|
|
6603
|
+
/**
|
|
6604
|
+
* 改地图尺寸:**宽高各自独立**(不再只给正方形)。
|
|
6605
|
+
*
|
|
6606
|
+
* 上限 512 与宿主 `MAX_MAP_DIM` 一致:超了宿主会拒绝并给出原因,这里先挡一道。
|
|
6607
|
+
*/
|
|
6608
|
+
const applyMapSize = async (cols, rows) => {
|
|
6609
|
+
if (view === null)
|
|
6610
|
+
return;
|
|
6611
|
+
const nextCols = Math.round(Number(cols));
|
|
6612
|
+
const nextRows = Math.round(Number(rows));
|
|
6613
|
+
if (!Number.isFinite(nextCols) || !Number.isFinite(nextRows) || nextCols < 1 || nextRows < 1) {
|
|
6614
|
+
setNotice({ kind: "error", text: T("地图大小要是 1 以上的整数。") });
|
|
6615
|
+
return;
|
|
6616
|
+
}
|
|
6617
|
+
if (nextCols > 512 || nextRows > 512) {
|
|
6618
|
+
setNotice({ kind: "error", text: T("地图最大 512×512 格。") });
|
|
6619
|
+
return;
|
|
6620
|
+
}
|
|
6621
|
+
if (nextCols === view.cols && nextRows === view.rows)
|
|
6622
|
+
return;
|
|
6623
|
+
const shrinking = nextCols < view.cols || nextRows < view.rows;
|
|
6624
|
+
// eslint-disable-next-line no-alert
|
|
6625
|
+
if (shrinking === true && typeof window !== "undefined" && !window.confirm(T("改小地图会丢掉范围外的格子(可以撤销)。继续?")))
|
|
6626
|
+
return;
|
|
6627
|
+
await saveDoc({ cols: nextCols, rows: nextRows }, T("已改地图尺寸"));
|
|
6628
|
+
};
|
|
6629
|
+
const clearLayer = async () => {
|
|
6630
|
+
if (view === null || activeLayer === null)
|
|
6631
|
+
return;
|
|
6632
|
+
// eslint-disable-next-line no-alert
|
|
6633
|
+
if (typeof window !== "undefined" && !window.confirm(T("清掉这一层上已经画的格子?")))
|
|
6634
|
+
return;
|
|
6635
|
+
await saveDoc({ clearLayerId: activeLayer.id }, T("已清空这一层"));
|
|
6636
|
+
};
|
|
6637
|
+
// ── 标记点:放 / 改名 / 挪走 / 删掉 ──────────────────────────────────
|
|
6638
|
+
/**
|
|
6639
|
+
* 标记改动走的是**和画笔同一条 op 通道**:撤销栈、脏块(`dropKeys`)全是现成的,
|
|
6640
|
+
* 界面不需要自己算「这一下让哪几块失效」。
|
|
6641
|
+
*
|
|
6642
|
+
* `refresh`:增删会改变编号(删掉第 2 个,第 3 个就变成第 2 个),所以要把视图
|
|
6643
|
+
* 重读一遍让列表跟上;拖动挪位置不影响编号,拖完再读一次就够。
|
|
6644
|
+
*/
|
|
6645
|
+
const markerOp = async (op, refresh) => {
|
|
6646
|
+
if (api === undefined || viewId === null)
|
|
6647
|
+
return;
|
|
6648
|
+
try {
|
|
6649
|
+
applyResult(await api.applyMapOps({ projectId: viewId, ops: [op], have: [...planRef.current.keys()] }));
|
|
6650
|
+
}
|
|
6651
|
+
catch (error) {
|
|
6652
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
6653
|
+
return;
|
|
6654
|
+
}
|
|
6655
|
+
if (refresh === true)
|
|
6656
|
+
await loadProject(viewId, true);
|
|
6657
|
+
};
|
|
6658
|
+
/** 这一格的标记(没有就 undefined)。格号是**规范坐标**,与命中测试同一套。 */
|
|
6659
|
+
const markerAtCell = (r, c) => {
|
|
6660
|
+
const list = view === null || view.markers === undefined ? [] : view.markers;
|
|
6661
|
+
return list.find((marker) => marker.r === r && marker.c === c);
|
|
6662
|
+
};
|
|
6663
|
+
/** 把视图挪到某一格(标记列表里的「定位」)。用允许复刻的那份坐标函数,不新算几何。 */
|
|
6664
|
+
const centerOnCell = (r, c) => {
|
|
6665
|
+
if (layout === null)
|
|
6666
|
+
return;
|
|
6667
|
+
const topLeft = MAP_cellTopLeft(layout, r, c, layout.grid.tileWidth, layout.grid.tileHeight);
|
|
6668
|
+
const center = { x: topLeft.x + layout.grid.tileWidth / 2, y: topLeft.y + layout.grid.tileHeight / 2 };
|
|
6669
|
+
setPan(clampPan({ x: center.x - viewport.w / (2 * zoom), y: center.y - viewport.h / (2 * zoom) }));
|
|
6670
|
+
};
|
|
6671
|
+
/** 图层改名:空名字**本地就拦住**(宿主对空名字是静默 no-op,会让人以为改成功了)。 */
|
|
6672
|
+
const commitLayerName = async (id, value) => {
|
|
6673
|
+
setLayerDraft(null);
|
|
6674
|
+
const name = String(value ?? "").trim();
|
|
6675
|
+
if (name === "") {
|
|
6676
|
+
setNotice({ kind: "error", text: T("图层名字不能为空") });
|
|
6677
|
+
return;
|
|
6678
|
+
}
|
|
6679
|
+
const current = layers.find((layer) => layer.id === id);
|
|
6680
|
+
if (current !== undefined && current.name === name)
|
|
6681
|
+
return;
|
|
6682
|
+
await saveDoc({ layers: [{ id, name }] }, T("已重命名这一层"));
|
|
6683
|
+
};
|
|
6684
|
+
/** 标记改名:空名字是合法的(界面按「标记 N」显示)。 */
|
|
6685
|
+
const commitMarkerName = async (id, value) => {
|
|
6686
|
+
setMarkerDraft(null);
|
|
6687
|
+
await markerOp({ kind: "marker", op: "rename", id, name: String(value ?? "") }, true);
|
|
6688
|
+
};
|
|
6689
|
+
const runGenerate = async () => {
|
|
6690
|
+
if (view === null || api === undefined)
|
|
6691
|
+
return;
|
|
6692
|
+
const tiles = multi.length > 0 ? multi : brush === null ? [] : [brush.index];
|
|
6693
|
+
if (tiles.length === 0) {
|
|
6694
|
+
setNotice({ kind: "error", text: T("先选至少一块图:在左边点一下,按住 Shift 或 Ctrl 可以多选。") });
|
|
6695
|
+
return;
|
|
6696
|
+
}
|
|
6697
|
+
setBusyKey("gen");
|
|
6698
|
+
try {
|
|
6699
|
+
const result = await api.runMapGenerate({
|
|
6700
|
+
projectId: view.id,
|
|
6701
|
+
kind: genKind,
|
|
6702
|
+
tiles,
|
|
6703
|
+
seed: genSeed,
|
|
6704
|
+
layerId: activeLayer === null ? undefined : activeLayer.id
|
|
6705
|
+
});
|
|
6706
|
+
if (result !== undefined && Number.isFinite(Number(result.seed)) && Number(result.seed) !== genSeed) {
|
|
6707
|
+
setGenSeed(Number(result.seed));
|
|
6708
|
+
}
|
|
6709
|
+
if (result !== undefined && Array.isArray(result.warnings) && result.warnings.length > 0) {
|
|
6710
|
+
setNotice({ kind: "info", text: result.warnings.join(";") });
|
|
6711
|
+
}
|
|
6712
|
+
// 一次生成可能动到整张图:计划整份作废,重新问宿主
|
|
6713
|
+
clearPlan();
|
|
6714
|
+
setPlanEpoch((value) => value + 1);
|
|
6715
|
+
}
|
|
6716
|
+
catch (error) {
|
|
6717
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
6718
|
+
}
|
|
6719
|
+
finally {
|
|
6720
|
+
setBusyKey(null);
|
|
6721
|
+
}
|
|
6722
|
+
};
|
|
6723
|
+
/**
|
|
6724
|
+
* 导出:**按当前勾选导一次**。
|
|
6725
|
+
*
|
|
6726
|
+
* 打不打 zip 由宿主决定(产物超过一个就自动打),界面不自己判断 ——
|
|
6727
|
+
* 「几个文件算多」只有一处口径,免得界面显示的和盘上的对不上。
|
|
6728
|
+
*/
|
|
6729
|
+
const runExport = async () => {
|
|
6730
|
+
if (view === null || api === undefined)
|
|
6731
|
+
return;
|
|
6732
|
+
if (exportFormats.png !== true && exportFormats.json !== true && exportFormats.tilesets !== true) {
|
|
6733
|
+
setNotice({ kind: "error", text: T("至少勾一项要导出的内容。") });
|
|
6734
|
+
return;
|
|
6735
|
+
}
|
|
6736
|
+
setBusyKey("export");
|
|
6737
|
+
try {
|
|
6738
|
+
const started = await api.runMapExport({
|
|
6739
|
+
projectId: view.id,
|
|
6740
|
+
scale: exportScale,
|
|
6741
|
+
formats: { png: exportFormats.png === true, json: exportFormats.json === true, tilesets: exportFormats.tilesets === true }
|
|
6742
|
+
});
|
|
6743
|
+
if (started !== undefined && started.started !== true && typeof started.reason === "string") {
|
|
6744
|
+
setNotice({ kind: "info", text: started.reason });
|
|
6745
|
+
}
|
|
6746
|
+
await loadProject(view.id, true);
|
|
6747
|
+
}
|
|
6748
|
+
catch (error) {
|
|
6749
|
+
setNotice({ kind: "error", text: msg(error) });
|
|
6750
|
+
}
|
|
6751
|
+
finally {
|
|
6752
|
+
setBusyKey(null);
|
|
6753
|
+
}
|
|
6754
|
+
};
|
|
6755
|
+
/** 导出产物的可点 URL(同源静态路由;zip 与单文件走同一条)。 */
|
|
6756
|
+
const exportUrlOf = (file) => `${assetBase}${view.exportBase}${file}`;
|
|
6757
|
+
/** `download` 属性要的是文件名,不是路径(`tilesets/x.png` 直接写上去浏览器会当非法文件名)。 */
|
|
6758
|
+
const baseNameOf = (file) => String(file).split("/").pop() ?? file;
|
|
6759
|
+
const isZip = (file) => /\.zip$/i.test(String(file));
|
|
6760
|
+
/**
|
|
6761
|
+
* 「另存为…」:浏览器原生的保存位置选择框(File System Access API)。
|
|
6762
|
+
*
|
|
6763
|
+
* ⚠️ 顺序不能反:`showSaveFilePicker` 必须在**用户手势**里调用,先 `await fetch`
|
|
6764
|
+
* 下载大文件会把手势耗掉,Chromium 直接抛「Must be handling a user gesture」。
|
|
6765
|
+
* 所以是「先弹框拿句柄 → 再取字节 → 再写盘」;用户取消(AbortError)什么都不提示。
|
|
6766
|
+
*/
|
|
6767
|
+
const saveAsExport = async (file) => {
|
|
6768
|
+
/**
|
|
6769
|
+
* ⚠️ 用 `any` 取这个 API:它是 File System Access 的较新成员,
|
|
6770
|
+
* TS 自带的 `Window` 类型里不一定有;而它**存在与否必须运行时判**(Electron 壳、
|
|
6771
|
+
* 老浏览器、跨源 iframe 里都没有),写进类型当成一定有会在真机上直接抛。
|
|
6772
|
+
*/
|
|
6773
|
+
const picker = typeof window === "undefined" ? undefined : window.showSaveFilePicker;
|
|
6774
|
+
if (typeof picker !== "function") {
|
|
6775
|
+
setNotice({ kind: "info", text: T("这个浏览器不支持「另存为」,请用下载(位置由浏览器的下载设置决定)。") });
|
|
6776
|
+
return;
|
|
6777
|
+
}
|
|
6778
|
+
try {
|
|
6779
|
+
const handle = await picker({ suggestedName: baseNameOf(file) });
|
|
6780
|
+
const response = await fetch(exportUrlOf(file));
|
|
6781
|
+
if (response.ok !== true)
|
|
6782
|
+
throw new Error(`HTTP ${response.status}`);
|
|
6783
|
+
const writable = await handle.createWritable();
|
|
6784
|
+
await writable.write(await response.blob());
|
|
6785
|
+
await writable.close();
|
|
6786
|
+
setNotice({ kind: "ok", text: T("已保存到 {n0}", { n0: String(handle.name ?? baseNameOf(file)) }) });
|
|
6787
|
+
}
|
|
6788
|
+
catch (error) {
|
|
6789
|
+
// 用户在保存框里按了取消:不是错误,不要弹红字
|
|
6790
|
+
if (error !== null && typeof error === "object" && error.name === "AbortError")
|
|
6791
|
+
return;
|
|
6792
|
+
setNotice({ kind: "error", text: T("另存为失败:{n0}", { n0: msg(error) }) });
|
|
6793
|
+
}
|
|
6794
|
+
};
|
|
6795
|
+
/** 「打开导出目录」:打开**导出目录本身**(宿主按与导出同一处口径算路径,没导出过就退回项目目录)。 */
|
|
6796
|
+
const openExportFolder = async () => {
|
|
6797
|
+
if (view === null || api === undefined)
|
|
6798
|
+
return;
|
|
6799
|
+
const result = await withApi(() => api.revealMapProject({ projectId: view.id, target: "export" }));
|
|
6800
|
+
if (result === undefined)
|
|
6801
|
+
return;
|
|
6802
|
+
if (result.fallback === true) {
|
|
6803
|
+
setNotice({ kind: "info", text: T("还没有导出过,先点「导出」。现在打开的是项目目录。") });
|
|
6804
|
+
return;
|
|
6805
|
+
}
|
|
6806
|
+
setNotice({ kind: "ok", text: T("已打开 {n0}", { n0: String(result.dir ?? "") }) });
|
|
6807
|
+
};
|
|
6808
|
+
/**
|
|
6809
|
+
* 「整个模块看过了」:一次把四步全打(宿主按「`stage` 省略 = 四阶段全打」处理)。
|
|
6810
|
+
*
|
|
6811
|
+
* 界面上**只剩这一条**改阶段标记的路 —— 卡片里那颗「确定」已经删掉了(用户:
|
|
6812
|
+
* 「和右上角的 x 没区别」),单阶段的标记仍可由验收流程 / 对话面 `setMapApproved` 改。
|
|
6813
|
+
* 已经打过再点一次是幂等的(宿主那边只是把 approved 再写成 true)。
|
|
6814
|
+
*/
|
|
6815
|
+
const markWholeModuleSeen = async () => {
|
|
6816
|
+
if (view === null || api === undefined)
|
|
6817
|
+
return;
|
|
6818
|
+
const done = await withApi(() => api.setMapApproved({ projectId: view.id, approved: true }));
|
|
6819
|
+
if (done === undefined)
|
|
6820
|
+
return;
|
|
6821
|
+
await loadProject(view.id, true);
|
|
6822
|
+
};
|
|
6823
|
+
const approvedOf = (stage) => {
|
|
6824
|
+
if (view === null)
|
|
6825
|
+
return false;
|
|
6826
|
+
const node = (view.stages || {})[stage];
|
|
6827
|
+
return node !== undefined && node.approved === true;
|
|
4332
6828
|
};
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
6829
|
+
const approvedAll = ["assets", "rules", "paint", "export"].every((stage) => approvedOf(stage));
|
|
6830
|
+
// 作业进行中就轮询:验收预览 / 导出是宿主上的异步任务,提交那次读到的还是「进行中」
|
|
6831
|
+
const projectBusy = view !== null && view.busy === true;
|
|
6832
|
+
React.useEffect(() => {
|
|
6833
|
+
if (projectBusy !== true || viewId === null || api === undefined)
|
|
6834
|
+
return undefined;
|
|
6835
|
+
const timer = setInterval(() => {
|
|
6836
|
+
void loadProject(viewId, true);
|
|
6837
|
+
}, 1500);
|
|
6838
|
+
return () => clearInterval(timer);
|
|
6839
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6840
|
+
}, [projectBusy, viewId, api]);
|
|
6841
|
+
// ⚠️ 所有 Hook 都在上面;下面才开始早退(React #310,整个面板白屏)
|
|
6842
|
+
const fileInput = h("input", {
|
|
6843
|
+
ref: fileRef,
|
|
6844
|
+
type: "file",
|
|
6845
|
+
accept: "image/*",
|
|
6846
|
+
"data-testid": "map-tileset-input",
|
|
6847
|
+
style: { display: "none" },
|
|
6848
|
+
onChange: (event) => {
|
|
6849
|
+
void startWithFile(event.target.files?.[0]);
|
|
6850
|
+
event.target.value = "";
|
|
4346
6851
|
}
|
|
4347
|
-
}
|
|
4348
|
-
|
|
4349
|
-
:
|
|
4350
|
-
ref: inputRef,
|
|
6852
|
+
});
|
|
6853
|
+
const addFileInput = h("input", {
|
|
6854
|
+
ref: addFileRef,
|
|
4351
6855
|
type: "file",
|
|
4352
|
-
accept,
|
|
4353
|
-
|
|
6856
|
+
accept: "image/*",
|
|
6857
|
+
"data-testid": "map-add-input",
|
|
4354
6858
|
style: { display: "none" },
|
|
4355
6859
|
onChange: (event) => {
|
|
4356
|
-
|
|
6860
|
+
const file = event.target.files?.[0];
|
|
6861
|
+
if (file !== undefined && file !== null)
|
|
6862
|
+
setAddDraft((current) => (current === null ? current : { ...current, file }));
|
|
4357
6863
|
event.target.value = "";
|
|
4358
6864
|
}
|
|
4359
|
-
})
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
function JobSidebar({ title, items, activeId, onSelect, onCreate, renderMeta }) {
|
|
4367
|
-
return h("div", { className: "SPR_side" }, h("div", { className: "SPR_sideTitle" }, T("{n0}({n1})", { n0: title, n1: items.length })), items.length === 0 ? h("p", { className: "SPR_hint" }, T("还没有内容,点右上角新建一个。")) : null, items.map((item) => h("button", {
|
|
4368
|
-
key: item.id,
|
|
6865
|
+
});
|
|
6866
|
+
const shell = (inner) => h("div", { className: "SPR_moduleBody", "data-module": "map" }, inner, fileInput, addFileInput, addDialog);
|
|
6867
|
+
if (view === null || layout === null) {
|
|
6868
|
+
return shell(h("div", { className: "SPR_mapEdRoot" }, h("div", { className: "SPR_mapEdEmpty" }, h("p", { className: "SPR_mapEdEmptyText" }, T("还没有地图项目。")), h("p", { className: "SPR_mapEdHint" }, T("选一张素材图开始,或者先用自带素材试试。建出来就是 32×32、两层,可以直接画。")), h("div", { className: "SPR_mapEdEmptyRow" }, h(Btn, { onClick: () => askProjectName("create") }, T("新建项目")), h(Btn, { primary: true, onClick: () => fileRef.current?.click(), busy: busyKey === "upload" }, T("选一张素材图开始")), h(Btn, { onClick: () => void startWithSample(), busy: busyKey === "sample" }, T("用自带素材试试"))), notice === null ? null : h("div", { className: `SPR_notice SPR_notice-${notice.kind}` }, notice.text)), nameDialog));
|
|
6869
|
+
}
|
|
6870
|
+
// ── 顶栏 ─────────────────────────────────────────────────────────────
|
|
6871
|
+
const menu = h("div", { className: "SPR_mapEdMenu", role: "menu" }, h("button", {
|
|
4369
6872
|
type: "button",
|
|
4370
|
-
className: "
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
6873
|
+
className: "SPR_mapEdMenuItem",
|
|
6874
|
+
onClick: () => {
|
|
6875
|
+
setMenuOpen(false);
|
|
6876
|
+
askProjectName("create");
|
|
6877
|
+
}
|
|
6878
|
+
}, T("新建项目")), h("button", {
|
|
6879
|
+
type: "button",
|
|
6880
|
+
className: "SPR_mapEdMenuItem",
|
|
6881
|
+
onClick: () => {
|
|
6882
|
+
setMenuOpen(false);
|
|
6883
|
+
askProjectName("rename");
|
|
6884
|
+
}
|
|
6885
|
+
}, T("重命名")), h("button", {
|
|
6886
|
+
type: "button",
|
|
6887
|
+
className: "SPR_mapEdMenuItem",
|
|
6888
|
+
"data-danger": "true",
|
|
6889
|
+
onClick: () => {
|
|
6890
|
+
setMenuOpen(false);
|
|
6891
|
+
void deleteProject();
|
|
6892
|
+
}
|
|
6893
|
+
}, T("删除项目")), h("div", { className: "SPR_mapEdMenuLabel" }, T("切换项目")), projects.map((entry) => h("button", {
|
|
6894
|
+
key: entry.id,
|
|
6895
|
+
type: "button",
|
|
6896
|
+
className: "SPR_mapEdMenuItem",
|
|
6897
|
+
"data-on": entry.id === view.id ? "true" : undefined,
|
|
6898
|
+
onClick: () => {
|
|
6899
|
+
setMenuOpen(false);
|
|
6900
|
+
void loadProject(entry.id);
|
|
6901
|
+
}
|
|
6902
|
+
}, entry.name)));
|
|
6903
|
+
const topBar = h("div", { className: "SPR_mapEdTop" }, h("div", { className: "SPR_mapEdProjWrap" }, h("button", {
|
|
6904
|
+
type: "button",
|
|
6905
|
+
className: "SPR_mapEdProj",
|
|
6906
|
+
"data-open": menuOpen === true ? "true" : undefined,
|
|
6907
|
+
"aria-expanded": menuOpen === true ? "true" : "false",
|
|
6908
|
+
onClick: () => setMenuOpen(menuOpen !== true)
|
|
6909
|
+
}, h("span", { className: "SPR_mapEdProjName" }, view.name), h("span", { className: "SPR_mapEdCaret" }, "▾")), menuOpen === true ? menu : null), h("span", { className: "SPR_mapEdSpacer" }), h("button", {
|
|
6910
|
+
type: "button",
|
|
6911
|
+
className: "SPR_mapEdTopBtn",
|
|
6912
|
+
"data-on": openCard === "assets" ? "true" : undefined,
|
|
6913
|
+
onClick: () => setOpenCard(openCard === "assets" ? null : "assets")
|
|
6914
|
+
}, T("素材")), h("button", {
|
|
6915
|
+
type: "button",
|
|
6916
|
+
className: "SPR_mapEdTopBtn",
|
|
6917
|
+
"data-on": openCard === "export" ? "true" : undefined,
|
|
6918
|
+
onClick: () => setOpenCard(openCard === "export" ? null : "export")
|
|
6919
|
+
}, T("导出")),
|
|
6920
|
+
/**
|
|
6921
|
+
* ⚠️ 这里原来有个「正在保存… / 已自动保存 HH:MM」的状态文字。
|
|
6922
|
+
* 用户反馈:画的时候它一直闪,不需要 —— 而且保存现在改成**一笔结束才提交**
|
|
6923
|
+
* (见 `queueOps`),本来也没什么可显示的。整块拿掉,连带 `savedAt` / `saving`。
|
|
6924
|
+
*/
|
|
6925
|
+
null);
|
|
6926
|
+
// ── 左列:素材调色板 + 12 个工具格 ────────────────────────────────────
|
|
6927
|
+
/**
|
|
6928
|
+
* 可点的笔刷清单。
|
|
6929
|
+
*
|
|
6930
|
+
* ⚠️ 必须读宿主给的 `palette`,**不要自己从 `legend` 里推**:绘制图例是按
|
|
6931
|
+
* 「一格一块」列出来的(拼块素材还含 16px 小格),照它做调色板会让用户点到
|
|
6932
|
+
* 半个草地。A2 拼块在 `palette` 里只有一个条目(点它 = 用自动连接笔刷)。
|
|
6933
|
+
*/
|
|
6934
|
+
const brushes = [];
|
|
6935
|
+
for (const owner of tilesets) {
|
|
6936
|
+
const list = Array.isArray(owner.palette) && owner.palette.length > 0 ? owner.palette : legend.filter((entry) => entry.tilesetId === owner.id);
|
|
6937
|
+
for (const item of list)
|
|
6938
|
+
brushes.push({ tilesetId: owner.id, index: item.index, rect: item.rect });
|
|
6939
|
+
}
|
|
6940
|
+
const paletteTile = (entry) => {
|
|
6941
|
+
const owner = tilesets.find((item) => item.id === entry.tilesetId);
|
|
6942
|
+
if (owner === undefined)
|
|
6943
|
+
return null;
|
|
6944
|
+
const cellW = owner.cell.width > 0 ? owner.cell.width : entry.rect.width;
|
|
6945
|
+
const cellH = owner.cell.height > 0 ? owner.cell.height : entry.rect.height;
|
|
6946
|
+
const scaleX = 32 / Math.max(1, cellW);
|
|
6947
|
+
const scaleY = 32 / Math.max(1, cellH);
|
|
6948
|
+
return h("button", {
|
|
6949
|
+
key: `${entry.tilesetId}:${entry.index}`,
|
|
6950
|
+
type: "button",
|
|
6951
|
+
className: "SPR_mapEdTile",
|
|
6952
|
+
"data-on": brush !== null && brush.index === entry.index ? "true" : undefined,
|
|
6953
|
+
"data-index": String(entry.index),
|
|
6954
|
+
title: T("第 {n0} 块", { n0: String(entry.index) }),
|
|
6955
|
+
style: {
|
|
6956
|
+
backgroundImage: `url(${assetBase}${owner.file})`,
|
|
6957
|
+
backgroundSize: `${owner.imageWidth * scaleX}px ${owner.imageHeight * scaleY}px`,
|
|
6958
|
+
backgroundPosition: `${-entry.rect.x * scaleX}px ${-entry.rect.y * scaleY}px`
|
|
6959
|
+
},
|
|
6960
|
+
onClick: (event) => {
|
|
6961
|
+
const additive = event.shiftKey === true || event.ctrlKey === true || event.metaKey === true;
|
|
6962
|
+
setBrush({ index: entry.index });
|
|
6963
|
+
setMulti((prev) => additive === true
|
|
6964
|
+
? prev.includes(entry.index)
|
|
6965
|
+
? prev.filter((value) => value !== entry.index)
|
|
6966
|
+
: prev.concat([entry.index])
|
|
6967
|
+
: [entry.index]);
|
|
6968
|
+
}
|
|
6969
|
+
});
|
|
6970
|
+
};
|
|
6971
|
+
const palette = h("div", { className: "SPR_mapEdPalette" }, brushes.length === 0
|
|
6972
|
+
? h("p", { className: "SPR_mapEdHint" }, T("还没有素材,点上面的「素材」上传一张。"))
|
|
6973
|
+
: h("div", { className: "SPR_mapEdPaletteGrid" }, brushes.map(paletteTile)));
|
|
6974
|
+
/**
|
|
6975
|
+
* 一个工具格。
|
|
6976
|
+
*
|
|
6977
|
+
* ⚠️ **不要用 `title` 做说明**:原生 tooltip 要等一秒、样式不受控,还和我们自己那张
|
|
6978
|
+
* 小标签**同时出现**(两个框叠在一起)。所以这里 `aria-label` 承担无障碍名字,
|
|
6979
|
+
* 视觉说明交给 `SPR_mapEdTip` —— 鼠标悬浮 / 键盘聚焦时显示在按钮**正上方**。
|
|
6980
|
+
*/
|
|
6981
|
+
const toolButton = (key, name, desc, config) => {
|
|
6982
|
+
const options = config === undefined ? {} : config;
|
|
6983
|
+
const shortcut = options.shortcut === undefined ? null : options.shortcut;
|
|
6984
|
+
return h("button", {
|
|
6985
|
+
key,
|
|
6986
|
+
type: "button",
|
|
6987
|
+
className: "SPR_mapEdTool",
|
|
6988
|
+
"aria-label": shortcut === null
|
|
6989
|
+
? T("{n0}:{n1}", { n0: name, n1: desc })
|
|
6990
|
+
: T("{n0}:{n1}({n2})", { n0: name, n1: desc, n2: shortcut }),
|
|
6991
|
+
"data-tool": key,
|
|
6992
|
+
"data-on": options.on === true ? "true" : undefined,
|
|
6993
|
+
disabled: options.disabled === true,
|
|
6994
|
+
onMouseEnter: showToolTip(name, desc, shortcut),
|
|
6995
|
+
onFocus: showToolTip(name, desc, shortcut),
|
|
6996
|
+
onMouseLeave: hideToolTip,
|
|
6997
|
+
onBlur: hideToolTip,
|
|
6998
|
+
onPointerDown: hideToolTip,
|
|
6999
|
+
onClick: options.onClick
|
|
7000
|
+
}, options.icon === undefined ? null : h(MapToolIcon, { name: options.icon }));
|
|
7001
|
+
};
|
|
7002
|
+
const tools = h("div", { className: "SPR_mapEdTools" }, toolButton("undo", T("撤销"), T("撤回上一步"), { icon: "undo", shortcut: "⌘Z", onClick: () => void doUndo(), disabled: view.canUndo !== true }), toolButton("redo", T("重做"), T("把刚撤回的一步再做回来"), { icon: "redo", shortcut: "⇧⌘Z", onClick: () => void doRedo(), disabled: view.canRedo !== true }), toolButton("pen", T("画笔"), T("按住左键涂抹,铺当前选中的那块图"), { icon: "pen", shortcut: "B", on: tool === "pen", onClick: () => setTool("pen") }), toolButton("eraser", T("橡皮"), T("把这格擦成空;右键随时是橡皮"), { icon: "eraser", shortcut: "E", on: tool === "eraser", onClick: () => setTool("eraser") }), toolButton("bucket", T("油漆桶"), T("同色的连通区一次填满"), { icon: "bucket", shortcut: "G", on: tool === "bucket", onClick: () => setTool("bucket") }), toolButton("pipette", T("吸管"), T("吸取这一格用的图块,变成当前笔刷"), { icon: "pipette", shortcut: "I", on: tool === "pipette", onClick: () => setTool("pipette") }), toolButton("hand", T("抓手"), T("拖动平移画布;空格拖或中键拖也行"), { icon: "hand", shortcut: "H", on: tool === "hand", onClick: () => setTool("hand") }), toolButton("marker", T("标记"), T("地图上点一格放一个标记;点已有标记可以改名、按住拖动可以挪位置;右键删掉它"), { icon: "marker", shortcut: "M", on: tool === "marker", onClick: () => setTool("marker") }), h("div", {
|
|
7003
|
+
key: "layer",
|
|
7004
|
+
className: "SPR_mapEdTool SPR_mapEdLayerBtn",
|
|
7005
|
+
onMouseEnter: showToolTip(T("图层"), T("点中间的数字打开图层列表(改名 / 换顺序 / 删掉);上半换上一层、下半换下一层"), null),
|
|
7006
|
+
onMouseLeave: hideToolTip
|
|
7007
|
+
}, h("button", {
|
|
7008
|
+
type: "button",
|
|
7009
|
+
className: "SPR_mapEdLayerHalf",
|
|
7010
|
+
"data-dir": "up",
|
|
7011
|
+
"aria-label": T("上一层"),
|
|
7012
|
+
disabled: safeLayerIndex >= layers.length - 1,
|
|
7013
|
+
onClick: () => setLayerIndex(Math.min(layers.length - 1, safeLayerIndex + 1))
|
|
7014
|
+
}, h(MapToolIcon, { name: "up" })), h("button", {
|
|
7015
|
+
type: "button",
|
|
7016
|
+
className: "SPR_mapEdLayerNum",
|
|
7017
|
+
"aria-label": T("图层"),
|
|
7018
|
+
"data-testid": "map-open-layers",
|
|
7019
|
+
onClick: () => setOpenCard(openCard === "layers" ? null : "layers")
|
|
7020
|
+
}, String(safeLayerIndex + 1)), h("button", {
|
|
7021
|
+
type: "button",
|
|
7022
|
+
className: "SPR_mapEdLayerHalf",
|
|
7023
|
+
"data-dir": "down",
|
|
7024
|
+
"aria-label": T("下一层"),
|
|
7025
|
+
disabled: safeLayerIndex <= 0,
|
|
7026
|
+
onClick: () => setLayerIndex(Math.max(0, safeLayerIndex - 1))
|
|
7027
|
+
}, h(MapToolIcon, { name: "down" }))), toolButton("grid", T("网格线"), T("显示或隐藏格线,方便数格子"), { icon: "grid", on: showGrid === true, onClick: () => setShowGrid(showGrid !== true) }), toolButton("gen", T("一键生成"), T("随机铺满 / 迷宫 / 大陆:用选中的图块一键铺满整层"), { icon: "magic", on: openCard === "gen", onClick: () => setOpenCard(openCard === "gen" ? null : "gen") }), toolButton("settings", T("设置"), T("地图大小、图层、帮助"), { icon: "settings", on: openCard === "settings", onClick: () => setOpenCard(openCard === "settings" ? null : "settings") }));
|
|
7028
|
+
const side = h("div", { className: "SPR_mapEdSide" }, h("div", { className: "SPR_mapEdSideTitle" }, T("素材调色板")), palette, tools);
|
|
7029
|
+
// ── 卡片:素材 / 导出 / 设置 / 一键生成 ──────────────────────────────
|
|
7030
|
+
const cardHead = (title) => h("div", { className: "SPR_mapEdCardHead" }, h("h4", null, title), h("span", { className: "SPR_mapEdSpacer" }), h("button", { type: "button", className: "SPR_mapEdCardClose", "aria-label": T("关闭"), onClick: () => setOpenCard(null) }, "×"));
|
|
7031
|
+
const row = (label, control, hint) => h("div", { className: "SPR_mapEdRow" }, h("span", { className: "SPR_mapEdLabel" }, label), control, hint === undefined || hint === "" ? null : h("span", { className: "SPR_mapEdRowHint" }, hint));
|
|
7032
|
+
/**
|
|
7033
|
+
* ⚠️ 卡片里**不再有「确定」按钮**(它曾经是「标记这一步看过了 + 收起卡片」)。
|
|
7034
|
+
*
|
|
7035
|
+
* 用户的判断很直接:「确定键可以删了,和右上角的 x 没区别」。这是对的 ——
|
|
7036
|
+
* 阶段标记在界面上**完全不可见**(上一版为了去掉「取消确认」把它做成了普通按钮,
|
|
7037
|
+
* 于是按与不按看起来一模一样),那么这颗按钮对用户就只剩「关掉卡片」这一个作用,
|
|
7038
|
+
* 和右上角那个 × 重复。
|
|
7039
|
+
*
|
|
7040
|
+
* 所以:关卡片只剩 ×;阶段标记仍可由验收流程 / 对话面(`setMapApproved`)改;
|
|
7041
|
+
* 界面上唯一还暴露它的地方是设置卡片里的「整个模块看过了」(那是一颗有状态按钮)。
|
|
7042
|
+
*/
|
|
7043
|
+
const speedOptions = [
|
|
7044
|
+
["0.5", T("慢")],
|
|
7045
|
+
["1", T("中")],
|
|
7046
|
+
["2", T("快")]
|
|
7047
|
+
];
|
|
7048
|
+
const speedValue = String(animFps === null ? planMeta.fps : animFps);
|
|
7049
|
+
/**
|
|
7050
|
+
* 素材卡片 = **列表 + 新增 + 恢复默认**。
|
|
7051
|
+
*
|
|
7052
|
+
* 产品约定(用户定的):属性在「新增素材」那一刻填完就定死,之后**只能删掉重来** ——
|
|
7053
|
+
* 所以这张卡里没有任何「改格子 / 改形态 / 改动不动」的入口;内置素材同样在列表里、
|
|
7054
|
+
* 也能删,想拿回来点「恢复默认素材」(同名会跳过,不会变成两份)。
|
|
7055
|
+
*/
|
|
7056
|
+
/**
|
|
7057
|
+
* 这张素材有几帧(列表上的徽章用)。
|
|
7058
|
+
*
|
|
7059
|
+
* 两种会动的情形都算进来:`a2quad` 的**变体就是帧**,`animRows`(翻页图)的**行数就是帧**
|
|
7060
|
+
* —— 宿主算好的 `variants` 在两种情形下都正好是帧数。
|
|
7061
|
+
*/
|
|
7062
|
+
const frameCountOf = (entry) => entry.animRows === true ? entry.variants : entry.shape === "a2quad" && entry.variants > 1 ? entry.variants : 0;
|
|
7063
|
+
const assetsCard = h("div", { className: "SPR_mapEdCard", "data-testid": "map-assets-card" }, cardHead(T("素材")), h("div", { className: "SPR_mapEdCardRow" }, h(Btn, { primary: true, onClick: openAddTileset }, T("新增素材")), h(Btn, { onClick: () => void restoreSamples(), busy: busyKey === "sample" }, T("恢复默认素材"))), tilesets.length === 0
|
|
7064
|
+
? h("p", { className: "SPR_mapEdHint" }, T("还没有素材。点「新增素材」加一张自己的,或者点「恢复默认素材」拿到自带的那套。"))
|
|
7065
|
+
: h("ul", { className: "SPR_mapEdTsList", "data-testid": "map-tileset-list" }, tilesets.map((entry, index) => h("li", { key: entry.id, className: "SPR_mapEdTsRow", "data-on": index === safeTsIndex ? "true" : undefined }, h("button", {
|
|
7066
|
+
type: "button",
|
|
7067
|
+
className: "SPR_mapEdTsPick",
|
|
7068
|
+
"data-tileset": entry.id,
|
|
7069
|
+
onClick: () => setTsIndex(index)
|
|
7070
|
+
}, h("span", { className: "SPR_mapEdTsName" }, entry.name), h("span", { className: "SPR_mapEdTsMeta" }, T("{n0}×{n1} · {n2} 块", { n0: String(entry.cell.width), n1: String(entry.cell.height), n2: String(entry.tileCount) })), frameCountOf(entry) > 0
|
|
7071
|
+
? h("span", { className: "SPR_mapEdTsBadge", "data-anim": "true" }, T("会动 {n0} 帧", { n0: String(frameCountOf(entry)) }))
|
|
7072
|
+
: null, entry.builtin === true ? h("span", { className: "SPR_mapEdTsBadge" }, T("自带")) : null), h(Btn, { danger: true, onClick: () => void removeTilesetById(entry.id, entry.name) }, T("删除"))))), h("p", { className: "SPR_mapEdHint" }, T("素材的属性在新增时就定下来了,之后不能改 —— 要换就删掉重新新增。")));
|
|
7073
|
+
/**
|
|
7074
|
+
* 导出卡片 = **一次选完 → 一次导出 → 一次下载**。
|
|
7075
|
+
*
|
|
7076
|
+
* 老版本的坏处(用户原话:「导出功能窗口意味不明」):两个按钮并排,一个看着像
|
|
7077
|
+
* 页签、另一个点下去却是立即执行;导完给一堆文件链接却没有「存到哪」这件事;
|
|
7078
|
+
* 三个文件还得一个一个点。现在:
|
|
7079
|
+
*
|
|
7080
|
+
* 1. 内容用复选框选(勾几项都行),倍率只在勾了 PNG 时出现;
|
|
7081
|
+
* 2. 唯一的「导出」按钮执行;多份产物由宿主打成一个 zip,一次下载;
|
|
7082
|
+
* 3. 结果区写清「文件在哪」(本机绝对路径)+ 下载 / 另存为 / 打开导出目录。
|
|
7083
|
+
*/
|
|
7084
|
+
const exportRows = [
|
|
7085
|
+
["png", T("地图图片 PNG"), T("地图长什么样,直接能放进游戏")],
|
|
7086
|
+
["json", T("存档数据 JSON"), T("每一格是什么,给引擎和工具读")],
|
|
7087
|
+
["tilesets", T("素材原图"), T("把素材图一起拷进包里,换台机器也能用")]
|
|
7088
|
+
];
|
|
7089
|
+
const exportNothingChosen = exportFormats.png !== true && exportFormats.json !== true && exportFormats.tilesets !== true;
|
|
7090
|
+
const zipFile = exportFiles.find((file) => isZip(file));
|
|
7091
|
+
const mainFile = zipFile ?? exportFiles.find((file) => file === "map.png") ?? exportFiles[0];
|
|
7092
|
+
// 排一下序:zip 在最前(它是「一次拿走全部」那一个),其余按产出顺序
|
|
7093
|
+
const listedFiles = exportFiles.slice().sort((a, b) => (isZip(a) === isZip(b) ? 0 : isZip(a) ? -1 : 1));
|
|
7094
|
+
const canSaveAs = typeof window !== "undefined" && typeof window.showSaveFilePicker === "function";
|
|
7095
|
+
const exportCard = h("div", { className: "SPR_mapEdCard", "data-testid": "map-export-card" }, cardHead(T("导出")), h("span", { className: "SPR_mapEdLabel" }, T("导出内容")), h("div", { className: "SPR_mapEdRows" }, exportRows.map(([key, label, hint]) => h("label", { key, className: "SPR_mapEdCheck", "data-testid": `map-export-row-${key}` }, h("input", {
|
|
7096
|
+
type: "checkbox",
|
|
7097
|
+
"data-testid": `map-export-${key}`,
|
|
7098
|
+
checked: exportFormats[key] === true,
|
|
7099
|
+
onChange: (event) => setExportFormats((current) => ({ ...current, [key]: event.target.checked }))
|
|
7100
|
+
}), label, h("span", { className: "SPR_mapEdTsMeta" }, hint)))), exportFormats.png === true
|
|
7101
|
+
? row(T("倍率"), h("select", {
|
|
7102
|
+
className: "SPR_mapEdSelect",
|
|
7103
|
+
"data-testid": "map-export-scale",
|
|
7104
|
+
value: String(exportScale),
|
|
7105
|
+
onChange: (event) => setExportScale(Number(event.target.value))
|
|
7106
|
+
}, [1, 2, 3, 4].map((value) => h("option", { key: value, value: String(value) }, `${value}×`))), T("只影响 PNG 的尺寸,不影响存档数据"))
|
|
7107
|
+
: null, h("p", { className: "SPR_mapEdHint" }, T("产出不止一个文件时自动打成一个 ZIP;只有一个文件时就直接给你那个文件。")), h("div", { className: "SPR_mapEdCardRow" }, h(Btn, {
|
|
7108
|
+
primary: true,
|
|
7109
|
+
busy: busyKey === "export",
|
|
7110
|
+
disabled: exportNothingChosen,
|
|
7111
|
+
"data-testid": "map-export-run",
|
|
7112
|
+
onClick: () => void runExport()
|
|
7113
|
+
}, T("导出")), h(Btn, { onClick: () => void openExportFolder() }, T("打开导出目录"))), exportFiles.length === 0
|
|
7114
|
+
? h("p", { className: "SPR_mapEdHint", "data-testid": "map-export-empty" }, T("还没有导出过。"))
|
|
7115
|
+
: h("div", { className: "SPR_mapEdExportResult", "data-testid": "map-export-result" }, h("span", { className: "SPR_mapEdLabel" }, T("最近一次导出:{n0} 个文件", { n0: String(exportFiles.length) })), mainFile === undefined
|
|
7116
|
+
? null
|
|
7117
|
+
: h("div", { className: "SPR_mapEdCardRow" }, h("a", {
|
|
7118
|
+
className: "SPR_btn",
|
|
7119
|
+
"data-primary": "true",
|
|
7120
|
+
"data-testid": "map-export-download",
|
|
7121
|
+
href: exportUrlOf(mainFile),
|
|
7122
|
+
download: baseNameOf(mainFile),
|
|
7123
|
+
// 与别处的「下载」按钮同款:`<a>` 当按钮用,去掉下划线
|
|
7124
|
+
style: { textDecoration: "none" }
|
|
7125
|
+
}, T("下载 {n0}", { n0: baseNameOf(mainFile) })), canSaveAs
|
|
7126
|
+
? h(Btn, { "data-testid": "map-export-save-as", onClick: () => void saveAsExport(mainFile) }, T("另存为…"))
|
|
7127
|
+
: null), h("p", { className: "SPR_mapEdHint" }, canSaveAs
|
|
7128
|
+
? T("下载走浏览器(默认进它的下载目录);想自己挑位置就点「另存为…」。")
|
|
7129
|
+
: T("下载走浏览器:文件会进它的下载目录(想每次都自己挑位置,在浏览器里打开「下载前询问保存位置」)。")), h("ul", { className: "SPR_mapEdFiles", "data-testid": "map-export-files" }, listedFiles.map((file) => h("li", { key: file }, h("a", { href: exportUrlOf(file), download: baseNameOf(file), "data-testid": `map-export-file-${baseNameOf(file)}` }, file), isZip(file) ? h("span", { className: "SPR_mapEdTsBadge", "data-anim": "true" }, T("打包,含全部内容")) : null))), h("p", { className: "SPR_mapEdHint", "data-testid": "map-export-path" }, T("文件都在 {n0}", { n0: view.exportPath === "" ? "—" : String(view.exportPath) }))));
|
|
7130
|
+
/**
|
|
7131
|
+
* 图层卡:一张列表管三件事 —— 改名字、换顺序、删掉;最上面一行固定是「标记层」。
|
|
7132
|
+
*
|
|
7133
|
+
* 名字是宿主的字段(`saveMapDoc({ layers: [{ id, name }] })`),所以改名走一次结构补丁、
|
|
7134
|
+
* 回来重读视图。标记列表放在同一张卡里:点一行就能改名 / 定位 / 删掉。
|
|
7135
|
+
*
|
|
7136
|
+
* 列表**从上往下列**(最后添加的层在最上):画布上就是这个叠放顺序,反向列会让人点错。
|
|
7137
|
+
*/
|
|
7138
|
+
const layerRows = [...layers].map((layer, index) => ({ layer, index })).reverse();
|
|
7139
|
+
const markers = view === null || view.markers === undefined ? [] : view.markers;
|
|
7140
|
+
const smallBtn = (key, label, title, onClick, disabled) => h("button", { key, type: "button", className: "SPR_mapEdMiniBtn", title, "aria-label": title, disabled: disabled === true, onClick }, label);
|
|
7141
|
+
const layersCard = h("div", { className: "SPR_mapEdCard", "data-testid": "map-layers-card" }, cardHead(T("图层")), h("p", { className: "SPR_mapEdHint" }, T("点名字可以改名,右边可以换顺序或删掉")), h("div", { className: "SPR_mapEdLayerList" }, h("div", { className: "SPR_mapEdLayerRow", "data-testid": "map-marker-layer-row" }, h("span", { className: "SPR_mapEdLayerIdx" }, "●"), h("span", { className: "SPR_mapEdLayerName", style: { cursor: "default" } }, T("标记层")), h("span", { className: "SPR_mapEdMarkerAt" }, T("{n0} 个标记", { n0: String(markers.length) })), smallBtn("marker", T("标记"), T("标记"), () => setTool("marker"), false)), layerRows.map(({ layer, index }) => {
|
|
7142
|
+
const editing = layerDraft !== null && layerDraft.id === layer.id;
|
|
7143
|
+
return h("div", { key: layer.id, className: "SPR_mapEdLayerRow", "data-on": index === safeLayerIndex ? "true" : undefined }, h("span", { className: "SPR_mapEdLayerIdx" }, String(index + 1)), editing
|
|
7144
|
+
? h("input", {
|
|
7145
|
+
className: "SPR_mapEdLayerNameInput",
|
|
7146
|
+
autoFocus: true,
|
|
7147
|
+
value: layerDraft.value,
|
|
7148
|
+
"data-testid": `map-layer-name-${index}`,
|
|
7149
|
+
onChange: (event) => setLayerDraft({ id: layer.id, value: event.target.value }),
|
|
7150
|
+
onBlur: () => void commitLayerName(layer.id, layerDraft.value),
|
|
7151
|
+
onKeyDown: (event) => {
|
|
7152
|
+
if (event.key === "Enter") {
|
|
7153
|
+
event.preventDefault();
|
|
7154
|
+
event.currentTarget.blur();
|
|
7155
|
+
}
|
|
7156
|
+
else if (event.key === "Escape") {
|
|
7157
|
+
setLayerDraft(null);
|
|
7158
|
+
}
|
|
7159
|
+
}
|
|
7160
|
+
})
|
|
7161
|
+
: h("button", {
|
|
7162
|
+
type: "button",
|
|
7163
|
+
className: "SPR_mapEdLayerName",
|
|
7164
|
+
"data-testid": `map-layer-pick-${index}`,
|
|
7165
|
+
title: T("点名字可以改名,右边可以换顺序或删掉"),
|
|
7166
|
+
onClick: () => setLayerIndex(index),
|
|
7167
|
+
onDoubleClick: () => setLayerDraft({ id: layer.id, value: layer.name })
|
|
7168
|
+
}, layer.name), smallBtn("up", "↑", T("上移一层"), () => void saveDoc({ moveLayer: { id: layer.id, toIndex: index + 1 } }, T("已换图层顺序")), index >= layers.length - 1), smallBtn("down", "↓", T("下移一层"), () => void saveDoc({ moveLayer: { id: layer.id, toIndex: index - 1 } }, T("已换图层顺序")), index <= 0), smallBtn("remove", "×", T("删掉当前这一层"), () => void saveDoc({ removeLayerId: layer.id }, T("已删掉这一层")), layers.length <= 1));
|
|
7169
|
+
})), h("div", { className: "SPR_mapEdCardRow" }, h(Btn, { onClick: () => void saveDoc({ addLayer: { name: T("图层 {n0}", { n0: String(layers.length + 1) }) } }, T("已加一层")) }, T("加一层")), h(Btn, { onClick: () => void clearLayer() }, T("清空当前图层")), h("label", { className: "SPR_mapEdCheck" }, h("input", { type: "checkbox", "data-testid": "map-single-layer", checked: single === true, onChange: (event) => setSingle(event.target.checked) }), T("只看这一层"))), h("div", { className: "SPR_mapEdMarkerList", "data-testid": "map-marker-list" }, markers.length === 0
|
|
7170
|
+
? h("p", { className: "SPR_mapEdHint" }, T("还没有标记。选「标记」工具,在地图上点一格。"))
|
|
7171
|
+
: markers.map((marker) => h("div", { key: marker.id, className: "SPR_mapEdMarkerRow", "data-on": marker.id === markerSel ? "true" : undefined, "data-testid": `map-marker-${marker.n}` }, h("span", { className: "SPR_mapEdMarkerDot" }, String(marker.n)), h("input", {
|
|
7172
|
+
className: "SPR_mapEdMarkerName",
|
|
7173
|
+
"aria-label": T("标记名字"),
|
|
7174
|
+
placeholder: T("标记 {n0}", { n0: String(marker.n) }),
|
|
7175
|
+
value: markerDraft !== null && markerDraft.id === marker.id ? markerDraft.value : marker.name,
|
|
7176
|
+
onFocus: () => setMarkerSel(marker.id),
|
|
7177
|
+
onChange: (event) => setMarkerDraft({ id: marker.id, value: event.target.value }),
|
|
7178
|
+
onBlur: () => {
|
|
7179
|
+
if (markerDraft !== null && markerDraft.id === marker.id)
|
|
7180
|
+
void commitMarkerName(marker.id, markerDraft.value);
|
|
7181
|
+
},
|
|
7182
|
+
onKeyDown: (event) => {
|
|
7183
|
+
if (event.key === "Enter") {
|
|
7184
|
+
event.preventDefault();
|
|
7185
|
+
event.currentTarget.blur();
|
|
7186
|
+
}
|
|
7187
|
+
}
|
|
7188
|
+
}), h("span", { className: "SPR_mapEdMarkerAt" }, `(${marker.r},${marker.c})`), smallBtn("go", T("定位"), T("定位"), () => {
|
|
7189
|
+
setMarkerSel(marker.id);
|
|
7190
|
+
centerOnCell(marker.r, marker.c);
|
|
7191
|
+
}, false), smallBtn("drop", T("删掉"), T("删掉"), () => void markerOp({ kind: "marker", op: "remove", id: marker.id }, true), false)))));
|
|
7192
|
+
const settingsCard = h("div", { className: "SPR_mapEdCard" }, cardHead(T("设置")), row(T("地图大小"), h("div", { className: "SPR_mapEdPair" }, h(NumField, { label: T("宽"), value: view.cols, min: 1, max: 512, onChange: (value) => void applyMapSize(value, view.rows) }), h("span", { className: "SPR_mapEdTimes" }, "×"), h(NumField, { label: T("高"), value: view.rows, min: 1, max: 512, onChange: (value) => void applyMapSize(view.cols, value) })), T("单位是格。改大只是多出空地;改小会丢掉范围外的格子(可撤销)")), row(T("动画速度"), h("select", {
|
|
7193
|
+
className: "SPR_mapEdSelect",
|
|
7194
|
+
"data-testid": "map-anim-speed",
|
|
7195
|
+
value: speedValue,
|
|
7196
|
+
onChange: (event) => setAnimFps(Number(event.target.value))
|
|
7197
|
+
}, speedOptions.map(([value, label]) => h("option", { key: value, value }, `${label} · ${value} 帧/秒`))), T("只影响会动的素材(水、翻页图这类)")), h("label", { className: "SPR_mapEdCheck" }, h("input", { type: "checkbox", checked: showGrid === true, onChange: (event) => setShowGrid(event.target.checked) }), T("网格线")), h("div", { className: "SPR_mapEdHelp" }, h("h5", null, T("帮助")), h("p", null, T("左键拖动=用当前工具画;空格拖动或中键拖动=平移;滚轮=缩放;右键=橡皮。")), h("p", null, T("调色板里点一下选一块图当笔刷,按住 Shift 或 Ctrl 可以多选,「一键生成」会用这些图块。")), h("p", null, T("地图四周是接上的:自动连接会把上下、左右两边接起来。画布拖不出地图 —— 拖到边就停,地图左上角对齐后不会再乱动;图外那片空白画不上。"))), h("div", { className: "SPR_mapEdCardRow" }, h(Btn, { onClick: () => void withApi(() => api.revealMapProject({ projectId: view.id })) }, T("在访达中打开项目目录")), h(Btn, { primary: true, on: approvedAll === true, onClick: () => void markWholeModuleSeen() }, T("整个模块看过了"))));
|
|
7198
|
+
const genTiles = multi.length > 0 ? multi : brush === null ? [] : [brush.index];
|
|
7199
|
+
const genCard = h("div", { className: "SPR_mapEdCard" }, cardHead(T("一键生成")), h("div", { className: "SPR_mapEdRadios" }, [
|
|
7200
|
+
["random", T("随机铺满")],
|
|
7201
|
+
["maze", T("迷宫")],
|
|
7202
|
+
["continent", T("大陆")]
|
|
7203
|
+
].map(([value, label]) => h("label", { key: value, className: "SPR_mapEdRadio" }, h("input", { type: "radio", name: "map-gen-kind", checked: genKind === value, onChange: () => setGenKind(value) }), label))), h("p", { className: "SPR_mapEdHint" }, genTiles.length === 0
|
|
7204
|
+
? T("用的图块:还没选。在左边点一下选一块,按住 Shift 或 Ctrl 可以多选。")
|
|
7205
|
+
: T("用的图块:{n0}", { n0: genTiles.join("、") })), h("p", { className: "SPR_mapEdHint" }, genKind === "maze"
|
|
7206
|
+
? T("迷宫:按顺序取两块,第一块当墙,第二块当路。")
|
|
7207
|
+
: genKind === "continent"
|
|
7208
|
+
? T("大陆:按顺序取最多四块当四种地貌(水下 / 海面 / 草地 / 雪地)。")
|
|
7209
|
+
: T("随机铺满:在选中的图块里均匀随机。")), h("div", { className: "SPR_mapEdCardRow" }, h(NumField, { label: T("种子"), value: genSeed, onChange: (value) => setGenSeed(value) }), h(Btn, { onClick: () => setGenSeed(Math.floor(Math.random() * 1000000)) }, T("换一组")), h(Btn, { primary: true, busy: busyKey === "gen", onClick: () => void runGenerate() }, T("生成"))));
|
|
7210
|
+
const openCardNode = openCard === "assets"
|
|
7211
|
+
? assetsCard
|
|
7212
|
+
: openCard === "export"
|
|
7213
|
+
? exportCard
|
|
7214
|
+
: openCard === "layers"
|
|
7215
|
+
? layersCard
|
|
7216
|
+
: openCard === "settings"
|
|
7217
|
+
? settingsCard
|
|
7218
|
+
: openCard === "gen"
|
|
7219
|
+
? genCard
|
|
7220
|
+
: null;
|
|
7221
|
+
const canvas = h("canvas", {
|
|
7222
|
+
ref: bindCanvas,
|
|
7223
|
+
className: "SPR_mapEdCanvas",
|
|
7224
|
+
"data-testid": "map-canvas",
|
|
7225
|
+
onPointerDown,
|
|
7226
|
+
onPointerMove,
|
|
7227
|
+
onPointerUp,
|
|
7228
|
+
onPointerLeave: () => {
|
|
7229
|
+
strokeRef.current = null;
|
|
7230
|
+
currentStroke.current = null;
|
|
7231
|
+
setHover(null);
|
|
7232
|
+
void flushOps();
|
|
7233
|
+
},
|
|
7234
|
+
// ⚠️ 少了 onPointerCancel:指针被系统取消(触摸 / 手写笔被打断、指针捕获丢失)
|
|
7235
|
+
// 时 `strokeRef` 不清,之后**在没按键的情况下**一次普通 pointermove 就会继续涂抹,
|
|
7236
|
+
// 而且每段还各算一步撤销。`onPointerLeave` 兜不住「留在画布内被取消」这种。
|
|
7237
|
+
onPointerCancel: () => {
|
|
7238
|
+
strokeRef.current = null;
|
|
7239
|
+
currentStroke.current = null;
|
|
7240
|
+
setHover(null);
|
|
7241
|
+
void flushOps();
|
|
7242
|
+
},
|
|
7243
|
+
onContextMenu: (event) => event.preventDefault()
|
|
7244
|
+
});
|
|
7245
|
+
// 工具小标签:挂在面板根节点下、`position:fixed`,所以不会被任何祖先的 overflow 裁掉。
|
|
7246
|
+
const toolTipNode = toolTip === null
|
|
7247
|
+
? null
|
|
7248
|
+
: h("div", {
|
|
7249
|
+
className: "SPR_mapEdTip",
|
|
7250
|
+
role: "tooltip",
|
|
7251
|
+
"data-tip": toolTip.name,
|
|
7252
|
+
style: { left: `${toolTip.x}px`, top: `${toolTip.y}px` }
|
|
7253
|
+
}, h("div", { className: "SPR_mapEdTipName" }, toolTip.name, toolTip.shortcut === null ? null : h("span", { className: "SPR_mapEdTipKey" }, toolTip.shortcut)), h("div", { className: "SPR_mapEdTipDesc" }, toolTip.desc));
|
|
7254
|
+
return shell(h("div", { className: "SPR_mapEdRoot" }, topBar, openCardNode === null ? null : h("div", { className: "SPR_mapEdCardWrap" }, openCardNode), h("div", { className: "SPR_mapEdBody" }, side, h("div", { className: "SPR_mapEdStage", ref: stageRef }, canvas, truncated === true ? h("div", { className: "SPR_mapEdToast" }, T("缩得太小,放大一点。")) : null, view.busy === true ? h("div", { className: "SPR_mapEdToast", "data-busy": "true" }, T("任务进行中…")) : null)), h("div", { className: "SPR_mapEdFoot" }, notice === null ? null : h("div", { className: `SPR_notice SPR_notice-${notice.kind}` }, notice.text), planWarnings.length === 0
|
|
7255
|
+
? null
|
|
7256
|
+
: h("ul", { className: "SPR_mapEdWarnings" }, planWarnings.map((text, index) => h("li", { key: index }, text))), h("span", { className: "SPR_mapEdSpacer" }), single === true || activeLayer === null
|
|
7257
|
+
? null
|
|
7258
|
+
: h("span", { className: "SPR_mapEdFootText" }, T("第 {n0} 层 / 共 {n1} 层", { n0: String(safeLayerIndex + 1), n1: String(layers.length) }))),
|
|
7259
|
+
// 隐藏的图源:canvas 拿它们当 drawImage 的源(避免再建一份缓存)
|
|
7260
|
+
h("div", { style: { display: "none" } }, tilesets.map((entry) => h("img", {
|
|
7261
|
+
key: entry.id,
|
|
7262
|
+
"data-tileset": entry.id,
|
|
7263
|
+
ref: (node) => {
|
|
7264
|
+
imageRefs.current[entry.id] = node;
|
|
7265
|
+
},
|
|
7266
|
+
src: `${assetBase}${entry.file}`,
|
|
7267
|
+
alt: "",
|
|
7268
|
+
onLoad: () => setImagesReady((value) => value + 1),
|
|
7269
|
+
// ⚠️ 只挂 onLoad 不挂 onError 的话,素材图 404 / 解码失败时
|
|
7270
|
+
// `imagesReady` 永远不递增,这张素材的格子**一条都不画**:
|
|
7271
|
+
// 画布静默空白、界面零提示(只有调试钩子的 noImage 看得到)。
|
|
7272
|
+
onError: () => {
|
|
7273
|
+
setImagesReady((value) => value + 1);
|
|
7274
|
+
setNotice({ kind: "error", text: T("素材图加载失败:{n0}(试试重新上传这张图)", { n0: entry.name }) });
|
|
7275
|
+
}
|
|
7276
|
+
}))), toolTipNode, nameDialog));
|
|
4374
7277
|
}
|
|
4375
7278
|
// ── 模块②:图片生成 ─────────────────────────────────────────────────
|
|
4376
7279
|
/** 模块②的 pending key:整批生成、单张重生成、抠像、上传、新建任务。 */
|
|
@@ -6181,11 +9084,16 @@ window.__ModuleLoader__.load({
|
|
|
6181
9084
|
return invoke();
|
|
6182
9085
|
return tasks.run(feedback.key, feedback.label, invoke);
|
|
6183
9086
|
};
|
|
6184
|
-
const create =
|
|
6185
|
-
const
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
9087
|
+
const create = async () => {
|
|
9088
|
+
const name = askNewName(T("新图片任务的名字"), T("图片 {n0}", { n0: new Date().toLocaleString("zh-CN", { hour12: false }) }));
|
|
9089
|
+
if (name === null)
|
|
9090
|
+
return;
|
|
9091
|
+
await run(async () => {
|
|
9092
|
+
const created = await api.createImageJob({ name });
|
|
9093
|
+
await refresh();
|
|
9094
|
+
setJobId(created.jobId);
|
|
9095
|
+
}, T("已新建图片任务"), { key: K_IMG_CREATE, label: T("正在新建任务…") });
|
|
9096
|
+
};
|
|
6189
9097
|
const saveJob = (patch) => run(() => api.saveImageJob({ jobId: job.id, ...patch }), T("已保存"));
|
|
6190
9098
|
const del = async () => {
|
|
6191
9099
|
if (job === null)
|
|
@@ -6252,7 +9160,7 @@ window.__ModuleLoader__.load({
|
|
|
6252
9160
|
if (suffixDraft !== (job.suffix ?? ""))
|
|
6253
9161
|
void saveJob({ suffix: suffixDraft });
|
|
6254
9162
|
}
|
|
6255
|
-
}), h("div", { className: "SPR_fields" }, h(GlobalModelField, { label: T("生图模型"), value: globalConfig?.arkModel ?? settingsDraft.model }), h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("尺寸")), h("input", { className: "SPR_input", value: settingsDraft.size ?? "", onChange: (event) => setSettingsDraft({ ...settingsDraft, size: event.target.value }), onBlur: () => void saveJob({ settings: settingsDraft }) })), h(NumField, { label: T("生成张数(1~8)"), value: settingsDraft.count ?? 1, min: 1, max: 8, onChange: (v) => { setSettingsDraft({ ...settingsDraft, count: v }); void saveJob({ settings: { ...settingsDraft, count: v } }); } })), h("div", { className: "SPR_toolbar" }, h(BusyBtn, {
|
|
9163
|
+
}), h("div", { className: "SPR_fields" }, h(GlobalModelField, { label: T("生图模型"), value: globalConfig?.imageModel ?? globalConfig?.arkModel ?? settingsDraft.model }), h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("尺寸")), h("input", { className: "SPR_input", value: settingsDraft.size ?? "", onChange: (event) => setSettingsDraft({ ...settingsDraft, size: event.target.value }), onBlur: () => void saveJob({ settings: settingsDraft }) })), h(NumField, { label: T("生成张数(1~8)"), value: settingsDraft.count ?? 1, min: 1, max: 8, onChange: (v) => { setSettingsDraft({ ...settingsDraft, count: v }); void saveJob({ settings: { ...settingsDraft, count: v } }); } })), h("div", { className: "SPR_toolbar" }, h(BusyBtn, {
|
|
6256
9164
|
primary: true,
|
|
6257
9165
|
busy: tasks.has(K_IMG_JOB),
|
|
6258
9166
|
busyText: T("正在生成 {n0} 张…", { n0: settingsDraft.count ?? 1 }),
|
|
@@ -6281,6 +9189,12 @@ window.__ModuleLoader__.load({
|
|
|
6281
9189
|
: h("div", { className: "SPR_grid" }, (job.items ?? []).map((item, index) => {
|
|
6282
9190
|
const itemKey = K_IMG_ITEM(index);
|
|
6283
9191
|
const itemBusy = item.status === "running" || tasks.has(itemKey);
|
|
9192
|
+
// 生成的原图(未抠像时就是唯一产物)也要能存下来:
|
|
9193
|
+
// 之前只有「抠像结果」给了下载链接,抠像关掉后整张卡片
|
|
9194
|
+
// 只剩 通过 / 重新生成 / 删除,用户只能右键另存。
|
|
9195
|
+
const rawExt = typeof item.file === "string" && item.file.includes(".")
|
|
9196
|
+
? item.file.slice(item.file.lastIndexOf(".") + 1).toLowerCase()
|
|
9197
|
+
: "png";
|
|
6284
9198
|
// 整批生成时,还没轮到的那些也要盖住(否则旧图看着像「没反应」)
|
|
6285
9199
|
const waiting = item.status !== "running" && tasks.has(K_IMG_JOB);
|
|
6286
9200
|
const keyingNow = item.status !== "running" && tasks.has(K_IMG_KEY);
|
|
@@ -6297,7 +9211,9 @@ window.__ModuleLoader__.load({
|
|
|
6297
9211
|
approved: item.approved === true,
|
|
6298
9212
|
disabled: overlay || item.status !== "ready",
|
|
6299
9213
|
onToggle: () => void run(() => api.saveImageJob({ jobId: job.id, index, approved: item.approved !== true }), item.approved === true ? T("已取消通过") : T("已标记通过"))
|
|
6300
|
-
}), item.
|
|
9214
|
+
}), item.file !== undefined
|
|
9215
|
+
? h("a", { className: "SPR_btn", href: `${job.assetBase}${item.file}`, download: `image-${index + 1}.${rawExt}`, style: { textDecoration: "none" } }, T("下载原图"))
|
|
9216
|
+
: null, item.keyedFile !== undefined
|
|
6301
9217
|
? h("a", { className: "SPR_btn", href: `${job.assetBase}${item.keyedFile}`, download: `keyed-${index + 1}.png`, style: { textDecoration: "none" } }, T("下载 PNG"))
|
|
6302
9218
|
: null, item.source === "generated"
|
|
6303
9219
|
? h(BusyBtn, {
|
|
@@ -6447,11 +9363,16 @@ window.__ModuleLoader__.load({
|
|
|
6447
9363
|
}
|
|
6448
9364
|
return value;
|
|
6449
9365
|
};
|
|
6450
|
-
const create =
|
|
6451
|
-
const
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
9366
|
+
const create = async () => {
|
|
9367
|
+
const name = askNewName(T("新序列帧任务的名字"), T("序列帧 {n0}", { n0: new Date().toLocaleString("zh-CN", { hour12: false }) }));
|
|
9368
|
+
if (name === null)
|
|
9369
|
+
return;
|
|
9370
|
+
await run(async () => {
|
|
9371
|
+
const created = await api.createSequenceJob({ name });
|
|
9372
|
+
await refresh();
|
|
9373
|
+
setJobId(created.jobId);
|
|
9374
|
+
}, T("已新建序列帧任务"), { key: K_SEQ_CREATE, label: T("正在新建任务…") });
|
|
9375
|
+
};
|
|
6455
9376
|
const saveJob = (patch) => run(() => api.saveSequenceJob({ jobId: job.id, ...patch }), undefined);
|
|
6456
9377
|
const del = async () => {
|
|
6457
9378
|
if (job === null)
|
|
@@ -6876,7 +9797,13 @@ window.__ModuleLoader__.load({
|
|
|
6876
9797
|
return null;
|
|
6877
9798
|
const sem = job.semantics ?? { errors: [], warnings: [], ok: true, ready: false, confirmed: false, count: 0 };
|
|
6878
9799
|
const names = parts.map((part) => part.name);
|
|
6879
|
-
const patch = (name, fields) => void run(() =>
|
|
9800
|
+
const patch = (name, fields) => void run(async () => {
|
|
9801
|
+
const result = await api.setRigSemantics({ jobId: job.id, parts: [{ name, ...fields }], by: "human" });
|
|
9802
|
+
if (result?.ok === false) {
|
|
9803
|
+
throw new Error((result.errors ?? []).map((issue) => issue.message).join(";") || T("语义校验失败"));
|
|
9804
|
+
}
|
|
9805
|
+
return result;
|
|
9806
|
+
}, T("已更新「{n0}」的语义", { n0: name }), activeKey);
|
|
6880
9807
|
const anchorField = (part, key, index) => h(NumField, {
|
|
6881
9808
|
key: `${part.name}:${key}:${index}`,
|
|
6882
9809
|
label: T("{n0}{n1}", { n0: key === "proximal" ? T("近端") : T("远端"), n1: index === 0 ? "x" : "y" }),
|
|
@@ -7443,7 +10370,7 @@ window.__ModuleLoader__.load({
|
|
|
7443
10370
|
label: "",
|
|
7444
10371
|
value: entry.chain,
|
|
7445
10372
|
min: 1,
|
|
7446
|
-
max:
|
|
10373
|
+
max: 1,
|
|
7447
10374
|
step: 1,
|
|
7448
10375
|
onChange: (value) => write([{ name: entry.name, bone: entry.bone, target: entry.target, chain: value, bendPositive: entry.bendPositive, weight: entry.weight }], T("已改「{n0}」的链长", { n0: entry.name }))
|
|
7449
10376
|
})), h("td", null, h(Btn, {
|
|
@@ -8534,6 +11461,9 @@ window.__ModuleLoader__.load({
|
|
|
8534
11461
|
* ⚠️ 必须**按模块分开**:共用一个标志的话,用户在骨骼动画那边勾了
|
|
8535
11462
|
* 「不再提示」,进 45° 地图地块时弹窗就再也不出现了 —— 两个模块的
|
|
8536
11463
|
* 实验性说明内容完全不同,那样等于静默漏掉一次告知。
|
|
11464
|
+
*
|
|
11465
|
+
* 只有 `rig` / `tile` 两格:模块⑥「地图编辑器」已经不是实验性功能,
|
|
11466
|
+
* 它没有弹窗,也就不需要这一格。
|
|
8537
11467
|
*/
|
|
8538
11468
|
const experimentalGateMuted = { rig: false, tile: false };
|
|
8539
11469
|
/**
|
|
@@ -8592,6 +11522,7 @@ window.__ModuleLoader__.load({
|
|
|
8592
11522
|
onClose
|
|
8593
11523
|
});
|
|
8594
11524
|
}
|
|
11525
|
+
// 模块⑥「地图编辑器」已经没有实验性弹窗了(它不是实验性功能)。
|
|
8595
11526
|
/**
|
|
8596
11527
|
* 模块④的主体界面。
|
|
8597
11528
|
*
|
|
@@ -8729,13 +11660,18 @@ window.__ModuleLoader__.load({
|
|
|
8729
11660
|
const label = RIG_BUSY_LABEL[feedback] ?? (feedback.startsWith("rig:relayout") ? T("正在重新定位…") : T("正在处理…"));
|
|
8730
11661
|
return tasks.run(feedback, label, invoke);
|
|
8731
11662
|
};
|
|
8732
|
-
const createJob =
|
|
8733
|
-
const
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
11663
|
+
const createJob = async () => {
|
|
11664
|
+
const name = askNewName(T("新骨骼动画任务的名字"), T("新骨骼动画任务"));
|
|
11665
|
+
if (name === null)
|
|
11666
|
+
return;
|
|
11667
|
+
await run(async () => {
|
|
11668
|
+
const created = await api.createRigJob({ name });
|
|
11669
|
+
await refresh();
|
|
11670
|
+
setJobId(created.jobId);
|
|
11671
|
+
setStage("parts");
|
|
11672
|
+
return created;
|
|
11673
|
+
}, T("已新建骨骼动画任务"), K_RIG_CREATE);
|
|
11674
|
+
};
|
|
8739
11675
|
const deleteJob = async () => {
|
|
8740
11676
|
if (job === null)
|
|
8741
11677
|
return;
|
|
@@ -8805,7 +11741,7 @@ window.__ModuleLoader__.load({
|
|
|
8805
11741
|
return h("div", { className: "SPR_rigPanel" },
|
|
8806
11742
|
// 弹窗是 position:fixed,放在这个滚动容器里也照样盖住整个工作台,
|
|
8807
11743
|
// 不必为此把 RigModule 再包一层 Fragment。
|
|
8808
|
-
gateOpen ? h(RigExperimentalDialog, { onClose: closeGate }) : null, h(ExperimentalBar, null), h("div", { className: "SPR_toolbar" }, h("span", { className: "SPR_refRow" }, T("生图模型")), h("span", { className: "SPR_badge" }, globalConfig?.arkModel ?? job?.settings?.model ?? T("未配置")), h("span", { className: "SPR_refRow" }, T("(模型在「设置 → 游戏素材大师」里改)")), h("span", { className: "SPR_spacer" }), headerButtons), notice !== null
|
|
11744
|
+
gateOpen ? h(RigExperimentalDialog, { onClose: closeGate }) : null, h(ExperimentalBar, null), h("div", { className: "SPR_toolbar" }, h("span", { className: "SPR_refRow" }, T("生图模型")), h("span", { className: "SPR_badge" }, globalConfig?.imageModel ?? globalConfig?.arkModel ?? job?.settings?.model ?? T("未配置")), h("span", { className: "SPR_refRow" }, T("(模型在「设置 → 游戏素材大师」里改)")), h("span", { className: "SPR_spacer" }), headerButtons), notice !== null
|
|
8809
11745
|
? h("div", { className: "SPR_notice", "data-kind": notice.kind === "error" ? "error" : "info" }, notice.text, h(Btn, { onClick: () => setNotice(null) }, T("关闭")))
|
|
8810
11746
|
: null, h("div", { className: "SPR_modules" }, RIG_STAGES.map((entry) => {
|
|
8811
11747
|
const info = job === null ? { status: "empty" } : rigStageOf(job, entry.key);
|
|
@@ -8978,9 +11914,18 @@ window.__ModuleLoader__.load({
|
|
|
8978
11914
|
const api = props?.api;
|
|
8979
11915
|
const [config, setConfig] = React.useState(null);
|
|
8980
11916
|
const [arkKey, setArkKey] = React.useState("");
|
|
11917
|
+
const [customKey, setCustomKey] = React.useState("");
|
|
8981
11918
|
const [minimaxKey, setMinimaxKey] = React.useState("");
|
|
8982
11919
|
const [notice, setNotice] = React.useState(null);
|
|
8983
11920
|
const [testing, setTesting] = React.useState(null);
|
|
11921
|
+
/**
|
|
11922
|
+
* ComfyUI 工作流草稿。
|
|
11923
|
+
*
|
|
11924
|
+
* ⚠️ 不能像别的文本框那样「每敲一个字就 patch 一次」:一份工作流 JSON 几 KB,
|
|
11925
|
+
* 每个字符都往返一次会明显卡;而且中途的**非法 JSON** 存进去之后,
|
|
11926
|
+
* 下一次生成要在几十秒后才报错。所以用本地草稿,失焦 / 点保存才提交。
|
|
11927
|
+
*/
|
|
11928
|
+
const [workflowDraft, setWorkflowDraft] = React.useState(null);
|
|
8984
11929
|
const load = React.useCallback(async () => {
|
|
8985
11930
|
if (api === undefined)
|
|
8986
11931
|
return;
|
|
@@ -9051,9 +11996,41 @@ window.__ModuleLoader__.load({
|
|
|
9051
11996
|
void patch(values);
|
|
9052
11997
|
};
|
|
9053
11998
|
const usingCompshare = compshareModelId !== undefined && config.minimaxModel === compshareModelId;
|
|
9054
|
-
|
|
11999
|
+
/**
|
|
12000
|
+
* 生图后端。`ark` 与 `custom` 互斥,两组配置同时保留、只由这个开关决定用哪一组
|
|
12001
|
+
* —— 来回切不会丢任何一边的 Key 和参数。
|
|
12002
|
+
*/
|
|
12003
|
+
const imageProvider = config.imageProvider === "custom" ? "custom" : "ark";
|
|
12004
|
+
const protocols = config.customProtocols ?? [];
|
|
12005
|
+
const protocolInfo = protocols.find((entry) => entry.id === config.customProtocol);
|
|
12006
|
+
const customProtocol = config.customProtocol ?? "openai";
|
|
12007
|
+
const workflowNow = workflowDraft === null ? config.customWorkflow ?? "" : workflowDraft;
|
|
12008
|
+
const workflowDirty = workflowDraft !== null && workflowDraft !== (config.customWorkflow ?? "");
|
|
12009
|
+
/**
|
|
12010
|
+
* 切换协议时顺手换地址:只有当**当前地址还停在另一个协议的默认值**时才换,
|
|
12011
|
+
* 手动改过的地址一律不动(与 MiniMax 切「优云智算版」同一套判断)。
|
|
12012
|
+
* 不这么做的话,用户从 OpenAI 切到 ComfyUI 会得到一个指向 api.openai.com 的
|
|
12013
|
+
* ComfyUI 配置 —— 点测试才报「连不上」,中间没有任何提示。
|
|
12014
|
+
*/
|
|
12015
|
+
const onProtocolChange = (nextProtocol) => {
|
|
12016
|
+
const values = { customProtocol: nextProtocol };
|
|
12017
|
+
const knownDefaults = protocols.map((entry) => entry.baseUrl);
|
|
12018
|
+
const target = protocols.find((entry) => entry.id === nextProtocol);
|
|
12019
|
+
if (target !== undefined && (config.customBaseUrl === "" || knownDefaults.includes(config.customBaseUrl))) {
|
|
12020
|
+
values.customBaseUrl = target.baseUrl;
|
|
12021
|
+
}
|
|
12022
|
+
void patch(values);
|
|
12023
|
+
};
|
|
12024
|
+
return h("section", { className: "SPR_settings" }, h("h2", { style: { margin: 0, fontSize: 15 } }, T("游戏素材大师")), h("p", { className: "SPR_hint" }, T("配置生图 / 生视频的模型与整条流水线的默认参数。Key 只保存在本机 DSH 数据目录下的 game-material-master/config.json(真实路径见文末「数据位置」),界面里始终脱敏显示。")), notice !== null
|
|
9055
12025
|
? h("div", { className: "SPR_note", "data-kind": notice.kind }, notice.text)
|
|
9056
|
-
: null, h("div", { className: "SPR_settingsGroup" }, h("h3", null, T("
|
|
12026
|
+
: null, h("div", { className: "SPR_settingsGroup" }, h("h3", null, T("生图后端")), h("p", null, T("八方向图、图片生成、骨骼动画、45°地图地块的生图都走这里选的后端;图生视频(MiniMax)不受影响。")), h("div", { className: "SPR_fields" }, h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("当前使用")), h("select", {
|
|
12027
|
+
className: "SPR_input",
|
|
12028
|
+
"data-testid": "cfg-image-provider",
|
|
12029
|
+
value: imageProvider,
|
|
12030
|
+
onChange: (event) => void patch({ imageProvider: event.target.value })
|
|
12031
|
+
}, h("option", { value: "ark" }, T("火山方舟 Seedream(云端,开箱即用)")), h("option", { value: "custom" }, T("自定义生图模型(OpenAI / ComfyUI / SD WebUI)"))))), h("p", { className: "SPR_hint" }, T("当前生效:{n0}", { n0: config.imageProviderSummary ?? "" })), config.imageProviderBlocker
|
|
12032
|
+
? h("div", { className: "SPR_note", "data-kind": "error" }, T("还不能开跑:{n0}", { n0: config.imageProviderBlocker }))
|
|
12033
|
+
: h("div", { className: "SPR_note", "data-kind": "ok" }, T("后端已就绪,可以开跑。"))), h("div", { className: "SPR_settingsGroup" }, h("h3", null, T("火山方舟(生图)"), imageProvider === "ark" ? h("span", { className: "SPR_badge" }, T("当前使用")) : null), h("p", null, config.ffmpeg?.ok === true ? T("ffmpeg 可用:{n0}", { n0: config.ffmpeg.version }) : T("ffmpeg 不可用:{n0}", { n0: config.ffmpeg?.error ?? T("未知") })), h("div", { className: "SPR_keyRow" }, h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("API Key {n0}", { n0: config.arkApiKeySet ? T("(已配置 {n0})", { n0: config.arkApiKeyHint }) : T("(未配置)") })), h("input", {
|
|
9057
12034
|
className: "SPR_input",
|
|
9058
12035
|
type: "password",
|
|
9059
12036
|
placeholder: config.arkApiKeySet ? T("留空表示不修改") : T("粘贴 ARK_API_KEY"),
|
|
@@ -9095,7 +12072,136 @@ window.__ModuleLoader__.load({
|
|
|
9095
12072
|
await run(() => api.testArk(), (value) => T("连接正常:{n0} 返回 {n1} 字节图片", { n0: value.model, n1: value.bytes }));
|
|
9096
12073
|
setTesting(null);
|
|
9097
12074
|
}
|
|
9098
|
-
}, T("测试连接(会真实生成 1 张 1K 小图,产生少量费用)")))),
|
|
12075
|
+
}, T("测试连接(会真实生成 1 张 1K 小图,产生少量费用)")))),
|
|
12076
|
+
/**
|
|
12077
|
+
* 自定义生图后端。
|
|
12078
|
+
*
|
|
12079
|
+
* 三种协议共用一套表单,只有「高级参数」和「工作流」按协议显示——
|
|
12080
|
+
* 每个协议单独一块的话,用户切换协议时会看到完全换了一套界面,
|
|
12081
|
+
* 反而不知道哪些是共通的。
|
|
12082
|
+
*/
|
|
12083
|
+
h("div", { className: "SPR_settingsGroup" }, h("h3", null, T("自定义生图模型"), imageProvider === "custom" ? h("span", { className: "SPR_badge" }, T("当前使用")) : null), h("p", null, T("填「主机根地址」即可,具体端点由插件按协议拼;本地服务通常不需要 API Key。")), h("div", { className: "SPR_fields" }, h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("协议")), h("select", {
|
|
12084
|
+
className: "SPR_input",
|
|
12085
|
+
"data-testid": "cfg-custom-protocol",
|
|
12086
|
+
value: customProtocol,
|
|
12087
|
+
onChange: (event) => onProtocolChange(event.target.value)
|
|
12088
|
+
}, protocols.length > 0
|
|
12089
|
+
? protocols.map((entry) => h("option", { key: entry.id, value: entry.id }, entry.label))
|
|
12090
|
+
: [
|
|
12091
|
+
h("option", { key: "openai", value: "openai" }, "OpenAI API"),
|
|
12092
|
+
h("option", { key: "comfyui", value: "comfyui" }, "ComfyUI API"),
|
|
12093
|
+
h("option", { key: "sdwebui", value: "sdwebui" }, "Stable Diffusion WebUI API")
|
|
12094
|
+
])), h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, "Base URL"), h("input", {
|
|
12095
|
+
className: "SPR_input",
|
|
12096
|
+
"data-testid": "cfg-custom-base-url",
|
|
12097
|
+
value: config.customBaseUrl ?? "",
|
|
12098
|
+
placeholder: protocolInfo?.baseUrl ?? "",
|
|
12099
|
+
onChange: (event) => void patch({ customBaseUrl: event.target.value })
|
|
12100
|
+
})), h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, customProtocol === "sdwebui" ? T("模型名(SD WebUI 忽略,模型由服务端决定)") : T("模型名")), h("input", {
|
|
12101
|
+
className: "SPR_input",
|
|
12102
|
+
"data-testid": "cfg-custom-model",
|
|
12103
|
+
value: config.customModel ?? "",
|
|
12104
|
+
disabled: customProtocol === "sdwebui",
|
|
12105
|
+
placeholder: customProtocol === "comfyui" ? T("可不填,由工作流决定") : "gpt-image-1",
|
|
12106
|
+
onChange: (event) => void patch({ customModel: event.target.value })
|
|
12107
|
+
})), h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("输出尺寸(宽x高)")), h("input", {
|
|
12108
|
+
className: "SPR_input",
|
|
12109
|
+
"data-testid": "cfg-custom-size",
|
|
12110
|
+
value: config.customSize ?? "",
|
|
12111
|
+
placeholder: "1024x1024",
|
|
12112
|
+
onChange: (event) => void patch({ customSize: event.target.value })
|
|
12113
|
+
}))), h("p", { className: "SPR_hint" }, T("请求端点:{n0}", { n0: protocolInfo?.hint ?? "" })), h("div", { className: "SPR_keyRow" }, h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("API Key {n0}", { n0: config.customApiKeySet ? T("(已配置 {n0})", { n0: config.customApiKeyHint }) : T("(未配置,本地服务可以留空)") })), h("input", {
|
|
12114
|
+
className: "SPR_input",
|
|
12115
|
+
type: "password",
|
|
12116
|
+
placeholder: config.customApiKeySet ? T("留空表示不修改") : T("粘贴 API Key(A1111 的 user:pass 也认)"),
|
|
12117
|
+
value: customKey,
|
|
12118
|
+
onChange: (event) => setCustomKey(event.target.value)
|
|
12119
|
+
})), h(Btn, { onClick: () => run(async () => { await api.saveConfig({ customApiKey: customKey }); setCustomKey(""); }, T("自定义后端 Key 已保存")) }, T("保存 Key")), h(Btn, { disabled: !config.customApiKeySet, onClick: () => run(() => api.saveConfig({ clearCustomApiKey: true }), T("已清除自定义后端 Key")) }, T("清除"))),
|
|
12120
|
+
/**
|
|
12121
|
+
* 高级参数:OpenAI 协议不认这些(它只有 prompt / size / n),
|
|
12122
|
+
* 所以那一档不显示,免得用户以为调了有用。
|
|
12123
|
+
*/
|
|
12124
|
+
customProtocol === "sdwebui" || customProtocol === "comfyui"
|
|
12125
|
+
? h("div", { className: "SPR_fields" }, h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("负面提示词")), h("input", {
|
|
12126
|
+
className: "SPR_input",
|
|
12127
|
+
value: config.customNegativePrompt ?? "",
|
|
12128
|
+
placeholder: customProtocol === "comfyui" ? T("走 {{negative_prompt}} 占位符") : "",
|
|
12129
|
+
onChange: (event) => void patch({ customNegativePrompt: event.target.value })
|
|
12130
|
+
})), h(NumField, {
|
|
12131
|
+
label: T("采样步数"),
|
|
12132
|
+
value: config.customSteps ?? 28,
|
|
12133
|
+
min: 1,
|
|
12134
|
+
max: 150,
|
|
12135
|
+
onChange: (value) => void patch({ customSteps: value })
|
|
12136
|
+
}), h(NumField, {
|
|
12137
|
+
label: T("CFG / 引导强度"),
|
|
12138
|
+
value: config.customCfgScale ?? 7,
|
|
12139
|
+
min: 0,
|
|
12140
|
+
max: 30,
|
|
12141
|
+
onChange: (value) => void patch({ customCfgScale: value })
|
|
12142
|
+
}), h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("采样器")), h("input", {
|
|
12143
|
+
className: "SPR_input",
|
|
12144
|
+
value: config.customSampler ?? "",
|
|
12145
|
+
placeholder: "DPM++ 2M Karras",
|
|
12146
|
+
onChange: (event) => void patch({ customSampler: event.target.value })
|
|
12147
|
+
})), customProtocol === "sdwebui"
|
|
12148
|
+
? h(NumField, {
|
|
12149
|
+
label: T("图生图重绘强度(0~1)"),
|
|
12150
|
+
value: config.customDenoising ?? 0.65,
|
|
12151
|
+
min: 0,
|
|
12152
|
+
max: 1,
|
|
12153
|
+
step: 0.05,
|
|
12154
|
+
onChange: (value) => void patch({ customDenoising: value })
|
|
12155
|
+
})
|
|
12156
|
+
: null, h(NumField, {
|
|
12157
|
+
label: T("随机种子(-1 = 每次随机)"),
|
|
12158
|
+
value: config.customSeed ?? -1,
|
|
12159
|
+
min: -1,
|
|
12160
|
+
max: 2147483647,
|
|
12161
|
+
onChange: (value) => void patch({ customSeed: value })
|
|
12162
|
+
}))
|
|
12163
|
+
: null,
|
|
12164
|
+
// 超时对所有协议都有效(云端 OpenAI 也可能很慢),所以放在条件块外面。
|
|
12165
|
+
h(NumField, {
|
|
12166
|
+
label: T("请求超时(毫秒,本地模型建议给足)"),
|
|
12167
|
+
value: config.customTimeoutMs ?? 300000,
|
|
12168
|
+
min: 10000,
|
|
12169
|
+
max: 3600000,
|
|
12170
|
+
onChange: (value) => void patch({ customTimeoutMs: value })
|
|
12171
|
+
}),
|
|
12172
|
+
/**
|
|
12173
|
+
* ComfyUI 的工作流。必须整段粘贴 API 格式的 JSON —— 从界面导出的
|
|
12174
|
+
* 「工作流」格式(带 nodes / links 的那份)不是 API 格式,提交会直接 400。
|
|
12175
|
+
*/
|
|
12176
|
+
customProtocol === "comfyui"
|
|
12177
|
+
? h("div", null, h("p", { className: "SPR_hint" }, T("工作流(在 ComfyUI 里点「导出(API)」,把那份 JSON 整段粘贴)。可用占位符:{{prompt}} {{negative_prompt}} {{width}} {{height}} {{seed}} {{steps}} {{cfg}} {{sampler}} {{denoising}} {{model}} {{image}};一个都不写就原样跑你保存的工作流。")), h("textarea", {
|
|
12178
|
+
className: "SPR_area",
|
|
12179
|
+
"data-testid": "cfg-custom-workflow",
|
|
12180
|
+
placeholder: '{"3":{"class_type":"KSampler","inputs":{"seed":"{{seed}}","steps":"{{steps}}","cfg":"{{cfg}}","sampler_name":"{{sampler}}","denoise":"{{denoising}}","model":["4",0],"positive":["6",0],"negative":["7",0],"latent_image":["5",0]}},"6":{"class_type":"CLIPTextEncode","inputs":{"text":"{{prompt}}","clip":["4",1]}}}',
|
|
12181
|
+
value: workflowNow,
|
|
12182
|
+
onChange: (event) => setWorkflowDraft(event.target.value)
|
|
12183
|
+
}), h("div", { className: "SPR_toolbar" }, h(Btn, {
|
|
12184
|
+
disabled: !workflowDirty,
|
|
12185
|
+
onClick: () => run(async () => {
|
|
12186
|
+
await api.saveConfig({ customWorkflow: workflowNow });
|
|
12187
|
+
setWorkflowDraft(null);
|
|
12188
|
+
}, T("工作流已保存"))
|
|
12189
|
+
}, workflowDirty ? T("保存工作流") : T("工作流已保存")), h(Btn, {
|
|
12190
|
+
onClick: () => {
|
|
12191
|
+
setWorkflowDraft("");
|
|
12192
|
+
void patch({ customWorkflow: "" });
|
|
12193
|
+
}
|
|
12194
|
+
}, T("清空"))))
|
|
12195
|
+
: null, h("div", { className: "SPR_toolbar" }, h(BusyBtn, {
|
|
12196
|
+
busy: testing === "custom",
|
|
12197
|
+
busyText: T("正在生成测试图…"),
|
|
12198
|
+
disabled: testing !== null || config.customImageBlocker != null,
|
|
12199
|
+
onClick: async () => {
|
|
12200
|
+
setTesting("custom");
|
|
12201
|
+
await run(() => api.testCustomImage(), (value) => T("连接正常:{n0} 返回 {n1} 字节图片", { n0: value.provider, n1: value.bytes }));
|
|
12202
|
+
setTesting(null);
|
|
12203
|
+
}
|
|
12204
|
+
}, T("测试连接(会真实生成 1 张测试图,产生少量费用)")))), h("div", { className: "SPR_settingsGroup" }, h("h3", null, T("MiniMax(图生视频)")), h("p", null, T("视频阶段使用图生视频(I2V)。建议用 MiniMax-Hailuo-02,镜头稳定性最好。")), h("div", { className: "SPR_keyRow" }, h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, T("API Key {n0}", { n0: config.minimaxApiKeySet ? T("(已配置 {n0})", { n0: config.minimaxApiKeyHint }) : T("(未配置)") })), h("input", {
|
|
9099
12205
|
className: "SPR_input",
|
|
9100
12206
|
type: "password",
|
|
9101
12207
|
placeholder: config.minimaxApiKeySet ? T("留空表示不修改") : T("粘贴 MiniMax API Key"),
|
|
@@ -9237,7 +12343,7 @@ window.__ModuleLoader__.load({
|
|
|
9237
12343
|
onChange: (event) => toggleFeature(entry.key, event.target.checked)
|
|
9238
12344
|
}), h("span", { className: "SPR_featureText" }, h("span", { className: "SPR_featureTitle" }, entry.title, entry.experimental === true ? h("span", { className: "SPR_expTag" }, T("实验性")) : null), h("span", { className: "SPR_featureHint" }, entry.hint)), h("span", { className: "SPR_featureState" }, isHidden ? T("已隐藏") : T("显示中")));
|
|
9239
12345
|
})), hiddenNow.length === 0
|
|
9240
|
-
? h("p", { className: "SPR_hint" }, T("
|
|
12346
|
+
? h("p", { className: "SPR_hint" }, T("当前功能全部可见。"))
|
|
9241
12347
|
: h("p", { className: "SPR_hint" }, T("已隐藏 {n0} 个功能:{n1}。隐藏的模块在对话里同样不可调用。", {
|
|
9242
12348
|
n0: hiddenNow.length,
|
|
9243
12349
|
n1: MODULES.filter((entry) => hiddenNow.includes(entry.key)).map((entry) => entry.title).join("、")
|
|
@@ -9277,6 +12383,7 @@ window.__ModuleLoader__.load({
|
|
|
9277
12383
|
getConfig: () => call("getConfig"),
|
|
9278
12384
|
saveConfig: (payload) => call("saveConfig", payload),
|
|
9279
12385
|
testArk: () => call("testArk"),
|
|
12386
|
+
testCustomImage: () => call("testCustomImage"),
|
|
9280
12387
|
testMinimax: () => call("testMinimax"),
|
|
9281
12388
|
listProjects: () => call("listProjects"),
|
|
9282
12389
|
createProject: (payload) => call("createProject", payload),
|
|
@@ -9291,6 +12398,8 @@ window.__ModuleLoader__.load({
|
|
|
9291
12398
|
saveSettings: (payload) => call("saveSettings", payload),
|
|
9292
12399
|
setApproved: (payload) => call("setApproved", payload),
|
|
9293
12400
|
revealProject: (payload) => call("revealProject", payload),
|
|
12401
|
+
uploadVideo: (payload) => call("uploadVideo", payload),
|
|
12402
|
+
exportImages: (payload) => call("exportImages", payload),
|
|
9294
12403
|
runImage: (payload) => call("runImage", payload),
|
|
9295
12404
|
runImages: (payload) => call("runImages", payload),
|
|
9296
12405
|
setImageMode: (payload) => call("setImageMode", payload),
|
|
@@ -9393,7 +12502,28 @@ window.__ModuleLoader__.load({
|
|
|
9393
12502
|
saveTileMapCells: (payload) => call("saveTileMapCells", payload),
|
|
9394
12503
|
runTileExport: (payload) => call("runTileExport", payload),
|
|
9395
12504
|
cancelTileJob: (payload) => call("cancelTileJob", payload),
|
|
9396
|
-
revealTileProject: (payload) => call("revealTileProject", payload)
|
|
12505
|
+
revealTileProject: (payload) => call("revealTileProject", payload),
|
|
12506
|
+
// 地图编辑器(模块六):全本地,没有一步收费
|
|
12507
|
+
listMapProjects: () => call("listMapProjects"),
|
|
12508
|
+
createMapProject: (payload) => call("createMapProject", { lang: activeLang(), ...payload }),
|
|
12509
|
+
getMapProject: (payload) => call("getMapProject", { lang: activeLang(), ...payload }),
|
|
12510
|
+
saveMapProject: (payload) => call("saveMapProject", payload),
|
|
12511
|
+
deleteMapProject: (payload) => call("deleteMapProject", payload),
|
|
12512
|
+
importMapTileset: (payload) => call("importMapTileset", payload),
|
|
12513
|
+
importSampleTileset: (payload) => call("importSampleTileset", payload),
|
|
12514
|
+
saveMapTileset: (payload) => call("saveMapTileset", payload),
|
|
12515
|
+
removeMapTileset: (payload) => call("removeMapTileset", payload),
|
|
12516
|
+
saveMapDoc: (payload) => call("saveMapDoc", payload),
|
|
12517
|
+
applyMapOps: (payload) => call("applyMapOps", payload),
|
|
12518
|
+
mapUndo: (payload) => call("mapUndo", payload),
|
|
12519
|
+
mapRedo: (payload) => call("mapRedo", payload),
|
|
12520
|
+
mapPlan: (payload) => call("mapPlan", payload),
|
|
12521
|
+
runMapGenerate: (payload) => call("runMapGenerate", payload),
|
|
12522
|
+
runMapPreview: (payload) => call("runMapPreview", payload),
|
|
12523
|
+
runMapExport: (payload) => call("runMapExport", payload),
|
|
12524
|
+
cancelMapJob: (payload) => call("cancelMapJob", payload),
|
|
12525
|
+
setMapApproved: (payload) => call("setMapApproved", payload),
|
|
12526
|
+
revealMapProject: (payload) => call("revealMapProject", payload)
|
|
9397
12527
|
};
|
|
9398
12528
|
// ── 深链接:会话里的链接点一下切到本插件页面 ─────────────────────
|
|
9399
12529
|
// 拦截器与生命周期绑定:插件停止 / 更新时监听器一定被摘掉。
|
|
@@ -9439,7 +12569,14 @@ window.__ModuleLoader__.load({
|
|
|
9439
12569
|
bundleModule.exports.GAME_STUDIO_PANEL_ID = GAME_STUDIO_PANEL_ID;
|
|
9440
12570
|
// 仅测试用把手:三个模块组件在工厂闭包里,脚本要能拿出来单独渲染
|
|
9441
12571
|
// (见 scripts/verify-feedback.mjs)。运行时没有任何调用点。
|
|
9442
|
-
|
|
12572
|
+
/**
|
|
12573
|
+
* 给自检用的把手。
|
|
12574
|
+
*
|
|
12575
|
+
* `MAP_*` 那几个是**只读的坐标函数**:`verify-map-client.mjs` 拿宿主
|
|
12576
|
+
* `mapgeom` / `mapdoc` 的真实现做黄金对照逐点比对 —— 界面复刻的那部分几何
|
|
12577
|
+
* 必须有守门的,否则「预览与导出错位」会以静默的方式回来。
|
|
12578
|
+
*/
|
|
12579
|
+
bundleModule.exports.__test = { StudioPanel, TileModule, ImageModule, SequenceModule, RigSemanticsPanel, MapModule, MAP_pointToCell, MAP_cellAnchor, MAP_cellTopLeft, MAP_lineCells, usePendingTasks, LoadingOverlay, MediaBox, BusyBtn, BusyBadge, NumField, ZoomableImage, CSS, subscribeIntent, parseIntents, openStudioIntent, OPEN_QUERY_KEY, StudioGlyph, StudioGlyphIcon, publishHiddenModules, useHiddenModules, visibleModulesOf, normalizeHiddenKeys, ConfigSection };
|
|
9443
12580
|
return bundleModule.exports;
|
|
9444
12581
|
}
|
|
9445
12582
|
});
|