feat: 建立关卡工坊并整理项目目录

- 加入 Godot 基础试玩、画风展示和通孔验证场景
- 支持自由放球、多层叠放、墙壁、锥口球洞及固定 +5 m/s 定向加速方块
- 保存 Blender 源资产、模型导出、资源制作脚本和关卡编辑存档逻辑
- 按七类目录归档工程,集中 zsh 启动入口并补充 AGENTS.md 文件索引
- 同步设计规则、依赖锁定、验证报告和目录迁移记录

验证:目录迁移后的资源导入与四个场景加载通过;本次提交前检查暂存内容,未重复运行整套物理测试。
This commit is contained in:
Yanchen
2026-11-16 11:12:21 +08:00
parent 151993e6df
commit 39ff1fd7b4
233 changed files with 147900 additions and 152 deletions
+94
View File
@@ -0,0 +1,94 @@
extends RefCounted
var lib
var chutes: Array
var entity_ids: Array=[]
func _init(library, chute_ids: Array) -> void:
lib=library;chutes=chute_ids
var registry=JSON.parse_string(FileAccess.get_file_as_string("res://assets/collections/storybook/entities.json"))
for group in ["interactive","nonInteractive"]:
for item in registry[group]:entity_ids.append(item.id)
func valid_vector(value: Variant) -> bool:
if not value is Array or value.size()!=3:return false
for n in value:
if not (n is float or n is int) or not is_finite(float(n)):return false
return true
func overlaps(a: Dictionary,b: Dictionary) -> bool:
var ab: AABB=lib.record_bounds(a);var bb: AABB=lib.record_bounds(b)
var extent: Vector3=ab.end.min(bb.end)-ab.position.max(bb.position)
return extent.x>.001 and extent.y>.001 and extent.z>.001
func validate(data: Variant) -> String:
if not data is Dictionary:return "关卡文件必须是 JSON 对象"
var version=data.get("schemaVersion")
if not (version is int or version is float):return "缺少关卡版本"
if (version!=1 and version!=2) or data.get("assetFamily")!="railbound_inspired":return "关卡版本或资产系列不匹配"
if not data.get("pieces") is Array or not data.get("balls") is Array or not data.get("entities",[]) is Array:return "缺少积木、实体或铁球数据"
var legacy: bool=data.schemaVersion==1
if legacy and (not valid_vector(data.get("goal")) or not data.get("entities",[]).is_empty()):return "旧版洞口或实体数据无效"
var ids: Array=[];var decoded: Array=[]
for group in ["pieces","entities"]:
for r in data.get(group,[]):
var allowed: Array=chutes if group=="pieces" else entity_ids
if not r is Dictionary or r.get("kind") not in allowed or not valid_vector(r.get("position")):return "无效的方块类型或坐标"
if not r.get("id") is String or r.id.is_empty() or r.id in ids:return "方块编号缺失或重复"
if not (r.get("quarter") is float or r.get("quarter") is int):return "无效的旋转值"
if r.quarter!=int(r.quarter) or r.quarter<0 or r.quarter>3:return "旋转必须为 0 / 90 / 180 / 270 度"
if r.kind!="goal_hole" and (r.position[0]!=round(r.position[0]) or r.position[2]!=round(r.position[2]) or r.position[1]*2!=round(r.position[1]*2)):return "积木坐标必须对齐网格"
var d={"id":r.id,"kind":r.kind,"position":lib.vector(r.position),"quarter":int(r.quarter)}
for other in decoded:
if overlaps(d,other):return "关卡中有重叠方块"
decoded.append(d);ids.append(r.id)
var ball_ids: Array=[]
for b in data.balls:
if not b is Dictionary or not b.get("id") is String or b.id.is_empty() or b.id in ball_ids:return "铁球编号缺失或重复"
if legacy:
if b.get("pieceId") not in ids:return "旧版铁球起点引用无效"
if not (b.get("pathT") is float or b.get("pathT") is int) or not is_finite(float(b.pathT)) or b.pathT<0 or b.pathT>1:return "旧版起点位置必须位于槽内"
var r: Dictionary=decoded[ids.find(b.pieceId)]
if not (b.get("branch") is float or b.get("branch") is int) or b.branch!=int(b.branch) or b.branch<0 or b.branch>=lib.catalog[r.kind].upperPaths.size():return "旧版起点分支无效"
else:
if not valid_vector(b.get("position")):return "铁球球心坐标无效"
if b.get("ballTypeId","iron_ball")!="iron_ball":return "未知的小球类型"
if b.has("launchDirection") and not valid_vector(b.launchDirection):return "初速度方向无效"
ball_ids.append(b.id)
return ""
func array_from(v: Vector3) -> Array:
return [v.x,v.y,v.z]
func normalize(data: Dictionary) -> Dictionary:
var records: Array=[]
for r in data.pieces+data.get("entities",[]):
var record={"id":r.id,"kind":r.kind,"position":lib.vector(r.position),"quarter":int(r.quarter)}
# Obsolete per-block speedGain fields are intentionally discarded on load.
records.append(record)
var balls: Array=[]
if data.schemaVersion==1:
for b in data.balls:
var record: Dictionary={}
for r in records:
if r.id==b.pieceId:record=r;break
var basis:=Basis(Vector3.UP,-int(record.quarter)*PI/2)
var position: Vector3=lib.record_center(record)+basis*lib.ball_on_surface(record.kind,float(b.pathT),int(b.branch))
var direction: Vector3=basis*lib.path_tangent(record.kind,float(b.pathT),int(b.branch))
if direction.y>0:direction=-direction
balls.append({"id":b.id,"ballTypeId":"iron_ball","position":array_from(position),"launchDirection":array_from(direction.normalized())})
var goal_id: String="legacy_goal"
while records.any(func(r):return r.id==goal_id):goal_id+="_"
records.append({"id":goal_id,"kind":"goal_hole","position":lib.vector(data.goal),"quarter":0})
else:
for b in data.balls:
balls.append({"id":b.id,"ballTypeId":"iron_ball","position":array_from(lib.vector(b.position)),"launchDirection":array_from(lib.vector(b.get("launchDirection",[1,0,0])))})
return {"records":records,"balls":balls}
func encode(records: Array,balls: Array,title: String) -> Dictionary:
var pieces: Array=[];var entities: Array=[]
for r in records:
var item={"id":r.id,"kind":r.kind,"position":array_from(r.position),"quarter":r.quarter}
if r.kind in chutes:pieces.append(item)
else:entities.append(item)
return {"schemaVersion":2,"assetFamily":"railbound_inspired","title":title,"pieces":pieces,"entities":entities,"balls":balls.duplicate(true)}