topotopo 0.4.0 → 0.5.1
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/NOTICE +10 -10
- package/README.md +460 -117
- package/dist/cli.js +327 -147
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/bake.d.ts +14 -3
- package/dist/core/bake.js +153 -4
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +76 -3
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +203 -3
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +7 -0
- package/dist/core/materials.js +45 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scene.js +2 -1
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +14 -1
- package/dist/core/snippet-lib.js +39 -13
- package/dist/core/tangents.d.ts +2 -0
- package/dist/core/tangents.js +5 -1
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +10 -0
- package/dist/core/topology.js +168 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +4 -18
- package/dist/core/uv.js +35 -188
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +61 -0
- package/dist/core/uvreport.js +207 -143
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +66 -62
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +80 -2
- package/dist/inspect.js +265 -30
- package/dist/io/common.d.ts +25 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +134 -47
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +148 -13
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +786 -143
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +56 -27
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +198 -103
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +151 -47
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +51 -3
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +21 -9
- package/dist/nodes/curves.js +433 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +12 -38
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.js +16 -19
- package/dist/nodes/index.d.ts +1 -0
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/material.js +89 -24
- package/dist/nodes/measure.js +43 -17
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.js +4 -2
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +6 -2
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +5 -1
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +57 -5
- package/dist/render/preview.d.ts +17 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +74 -5
- package/dist/render/raster.js +527 -143
- package/dist/render/texview.d.ts +6 -0
- package/dist/render/texview.js +27 -0
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +27 -7
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +5 -1
- package/dist/viewer/app/guides.js +122 -0
- package/dist/viewer/app/keymap.js +6 -3
- package/dist/viewer/app/layers.js +4 -4
- package/dist/viewer/app/main.js +185 -52
- package/dist/viewer/app/markers.js +60 -0
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +176 -52
- package/dist/viewer/app/scene.js +30 -5
- package/dist/viewer/app/select.js +4 -3
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +65 -7
- package/dist/viewer/app/vars.js +47 -0
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +23 -10
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +14 -9
- package/dist/viewer/server.js +266 -28
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/{gallery → web}/bake.d.ts +4 -4
- package/dist/{gallery → web}/bake.js +24 -15
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -118
- package/dist/workspace.js +358 -460
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +2 -1
- package/kernels/pkg-simd/README.md +2 -1
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +13 -8
- package/dist/gallery/app/gallery.css +0 -100
- package/dist/gallery/app/gallery.js +0 -80
- package/dist/gallery/cli.d.ts +0 -4
- package/dist/gallery/cli.js +0 -157
- package/dist/gallery/library.d.ts +0 -124
- package/dist/gallery/library.js +0 -366
- package/dist/gallery/pages.d.ts +0 -94
- package/dist/gallery/pages.js +0 -148
- package/dist/gallery/server.d.ts +0 -21
- package/dist/gallery/server.js +0 -391
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/dist/mcp/library.d.ts +0 -12
- package/dist/mcp/library.js +0 -159
- package/shelf/index.json +0 -190
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## The cook record of a TopoTopo package and the one freshness rule, ported from TopoTopo byte for byte
|
|
4
|
+
## (PROTOCOL.md in the TopoTopo repository: contentSha, listings, the import options, freshness). It uses no editor
|
|
5
|
+
## class, so the CI check (tools/check.gd) and the tests run it outside the editor.
|
|
6
|
+
|
|
7
|
+
const SCHEMA := 1
|
|
8
|
+
const FOR := "godot"
|
|
9
|
+
## The record, relative to the package folder.
|
|
10
|
+
const RECORD := ".topotopo/godot.json"
|
|
11
|
+
## A file a cook is writing.
|
|
12
|
+
const PART := ".topotopo-part"
|
|
13
|
+
## The package's TopoTopo folders, which Godot should not import (each holds an empty .gdignore).
|
|
14
|
+
const HIDDEN := ["graphs", "assets", "inputs", "exports", "versions", "packages"]
|
|
15
|
+
## Files hashed as they are, by their name (contentSha rule 1).
|
|
16
|
+
const BINARY := ["png", "jpg", "jpeg", "webp", "gif", "avif", "bmp", "tga", "tif", "tiff", "exr", "hdr", "dds", "ktx",
|
|
17
|
+
"ktx2", "glb", "bin", "bgeo", "sc", "usdc", "usdz", "fbx", "abc", "vdb", "r16", "r32", "raw", "wasm", "ttf", "otf",
|
|
18
|
+
"woff", "woff2", "zip", "gz", "7z", "pdf", "mp4", "webm", "wav", "ogg", "mp3"]
|
|
19
|
+
## The files engines write beside ours, which listings leave out.
|
|
20
|
+
const ENGINE_FILES := ["import", "uid", "translation", "uasset"]
|
|
21
|
+
## The import options' defaults (package_importer.gd).
|
|
22
|
+
const DEFAULTS := {"outputs/folder": "outputs", "outputs/per_output_folders": true, "outputs/skip": "", "instances/mode": 0}
|
|
23
|
+
|
|
24
|
+
## Hashes kept while a file's time and size stay the same: abs path -> [mtime, size, sha, hashed_at].
|
|
25
|
+
var _memo := {}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# ------------------------------------------------------------------------------------------------------- hashing
|
|
29
|
+
|
|
30
|
+
static func sha256(bytes: PackedByteArray) -> String:
|
|
31
|
+
var ctx := HashingContext.new()
|
|
32
|
+
ctx.start(HashingContext.HASH_SHA256)
|
|
33
|
+
if bytes.size():
|
|
34
|
+
ctx.update(bytes)
|
|
35
|
+
return ctx.finish().hex_encode()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## A file's content as contentSha reads it: a text file with every CR LF read as LF; a binary format by its name, or a
|
|
39
|
+
## file with a NUL byte in its first 8000 bytes, as it is.
|
|
40
|
+
static func text_content(name: String, bytes: PackedByteArray) -> PackedByteArray:
|
|
41
|
+
if BINARY.has(name.get_extension().to_lower()):
|
|
42
|
+
return bytes
|
|
43
|
+
if bytes.slice(0, mini(bytes.size(), 8000)).find(0) >= 0:
|
|
44
|
+
return bytes
|
|
45
|
+
var i := bytes.find(13)
|
|
46
|
+
if i < 0:
|
|
47
|
+
return bytes
|
|
48
|
+
var out := PackedByteArray()
|
|
49
|
+
var start := 0
|
|
50
|
+
while i >= 0:
|
|
51
|
+
if i + 1 < bytes.size() and bytes[i + 1] == 10:
|
|
52
|
+
out.append_array(bytes.slice(start, i))
|
|
53
|
+
start = i + 1
|
|
54
|
+
i = bytes.find(13, i + 1)
|
|
55
|
+
out.append_array(bytes.slice(start))
|
|
56
|
+
return out
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## TopoTopo's contentSha: the SHA-256 (lowercase hex) of a file's content read the way version control reads text.
|
|
60
|
+
static func content_sha(name: String, bytes: PackedByteArray) -> String:
|
|
61
|
+
return sha256(text_content(name, bytes))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## contentSha of a file on disk ("" when it is not there), from the memo while its time and size are the same.
|
|
65
|
+
func file_content_sha(abs_path: String) -> String:
|
|
66
|
+
return _hashed(abs_path, false)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## SHA-256 of a file's bytes ("" when it is not there), from the memo while its time and size are the same.
|
|
70
|
+
func file_raw_sha(abs_path: String) -> String:
|
|
71
|
+
return _hashed(abs_path, true)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
func _hashed(abs_path: String, raw: bool) -> String:
|
|
75
|
+
if not FileAccess.file_exists(abs_path):
|
|
76
|
+
return ""
|
|
77
|
+
var key := ("raw:" if raw else "txt:") + abs_path
|
|
78
|
+
var mtime := FileAccess.get_modified_time(abs_path)
|
|
79
|
+
var size := FileAccess.get_size(abs_path)
|
|
80
|
+
var m = _memo.get(key)
|
|
81
|
+
# a file changed in the second its hash was taken may change again unseen (times have whole seconds): hash it again
|
|
82
|
+
if m != null and m[0] == mtime and m[1] == size and mtime + 1 < m[3]:
|
|
83
|
+
return m[2]
|
|
84
|
+
var now := Time.get_unix_time_from_system()
|
|
85
|
+
var sha := ""
|
|
86
|
+
if raw or BINARY.has(abs_path.get_extension().to_lower()):
|
|
87
|
+
sha = FileAccess.get_sha256(abs_path)
|
|
88
|
+
else:
|
|
89
|
+
var bytes := FileAccess.get_file_as_bytes(abs_path)
|
|
90
|
+
if bytes.is_empty() and FileAccess.get_open_error() != OK:
|
|
91
|
+
return ""
|
|
92
|
+
sha = content_sha(abs_path, bytes)
|
|
93
|
+
_memo[key] = [mtime, size, sha, now]
|
|
94
|
+
return sha
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
func forget() -> void:
|
|
98
|
+
_memo.clear()
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# ------------------------------------------------------------------------------------------------------- listings
|
|
102
|
+
|
|
103
|
+
## A folder's listing: every file below it, as a path relative to it with forward slashes, sorted; names starting with
|
|
104
|
+
## "." left out, the files engines write beside ours and *.topotopo-part too. A folder that is not there lists nothing.
|
|
105
|
+
static func listing(dir: String) -> PackedStringArray:
|
|
106
|
+
var out := PackedStringArray()
|
|
107
|
+
_walk_listing(dir, "", 0, out)
|
|
108
|
+
out.sort()
|
|
109
|
+
return out
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
static func _walk_listing(dir: String, rel: String, depth: int, out: PackedStringArray) -> void:
|
|
113
|
+
var d := DirAccess.open(dir)
|
|
114
|
+
if d == null:
|
|
115
|
+
return
|
|
116
|
+
d.include_hidden = true
|
|
117
|
+
d.include_navigational = false
|
|
118
|
+
for f in d.get_files():
|
|
119
|
+
if f.begins_with(".") or ENGINE_FILES.has(f.get_extension().to_lower()) or f.ends_with(PART):
|
|
120
|
+
continue
|
|
121
|
+
out.append(f if rel == "" else rel + "/" + f)
|
|
122
|
+
if depth >= 32:
|
|
123
|
+
return
|
|
124
|
+
for sub in d.get_directories():
|
|
125
|
+
if sub.begins_with("."):
|
|
126
|
+
continue
|
|
127
|
+
_walk_listing(dir.path_join(sub), sub if rel == "" else rel + "/" + sub, depth + 1, out)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
static func same_set(a, b: PackedStringArray) -> bool:
|
|
131
|
+
if not (a is Array or a is PackedStringArray) or a.size() != b.size():
|
|
132
|
+
return false
|
|
133
|
+
var x := PackedStringArray(a)
|
|
134
|
+
x.sort()
|
|
135
|
+
for i in x.size():
|
|
136
|
+
if x[i] != b[i]:
|
|
137
|
+
return false
|
|
138
|
+
return true
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
# --------------------------------------------------------------------------------------------------------- paths
|
|
142
|
+
|
|
143
|
+
## A record's path of a file (relative to the package folder, or absolute) as an absolute path.
|
|
144
|
+
static func abs_of(dir: String, rel: String) -> String:
|
|
145
|
+
if rel.is_absolute_path():
|
|
146
|
+
return rel.simplify_path()
|
|
147
|
+
return dir.path_join(rel).simplify_path()
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## A res:// path in the project at `project` (absolute) as an absolute path.
|
|
151
|
+
static func res_to_abs(project: String, res: String) -> String:
|
|
152
|
+
var rest := res.trim_prefix("res://")
|
|
153
|
+
return project if rest == "" else project.path_join(rest).simplify_path()
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
## An absolute path inside the project as res://… ("" when it is outside).
|
|
157
|
+
static func abs_to_res(project: String, abs_path: String) -> String:
|
|
158
|
+
var p := abs_path.replace("\\", "/").simplify_path()
|
|
159
|
+
var root := project.replace("\\", "/").simplify_path().trim_suffix("/")
|
|
160
|
+
var same := p == root if OS.get_name() != "Windows" else p.to_lower() == root.to_lower()
|
|
161
|
+
if same:
|
|
162
|
+
return "res://"
|
|
163
|
+
var head := p.substr(0, root.length() + 1)
|
|
164
|
+
var inside := head == root + "/" if OS.get_name() != "Windows" else head.to_lower() == (root + "/").to_lower()
|
|
165
|
+
return "res://" + p.substr(root.length() + 1) if inside else ""
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
## A res:// path normalised: "." and ".." resolved, no doubled or trailing slash ("" when it leaves the project).
|
|
169
|
+
static func normal_res(res: String) -> String:
|
|
170
|
+
var parts := PackedStringArray()
|
|
171
|
+
for p in res.trim_prefix("res://").replace("\\", "/").split("/"):
|
|
172
|
+
if p == "" or p == ".":
|
|
173
|
+
continue
|
|
174
|
+
if p == "..":
|
|
175
|
+
if parts.is_empty():
|
|
176
|
+
return ""
|
|
177
|
+
parts.remove_at(parts.size() - 1)
|
|
178
|
+
else:
|
|
179
|
+
parts.append(p)
|
|
180
|
+
return "res://" + "/".join(parts)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
# ---------------------------------------------------------------------------------------------- import options
|
|
184
|
+
|
|
185
|
+
## The options as the record holds and compares them, from a .topo's import options (`params`: the keys of
|
|
186
|
+
## <id>.topo.import [params]; a missing key takes its default): {folder, instancing, per_output_folders, skip}, or
|
|
187
|
+
## {"error": why} for a folder outside the project.
|
|
188
|
+
static func options_from_params(params: Dictionary, topo_res: String, project: String) -> Dictionary:
|
|
189
|
+
var folder_text = params.get("outputs/folder", DEFAULTS["outputs/folder"])
|
|
190
|
+
if typeof(folder_text) != TYPE_STRING:
|
|
191
|
+
folder_text = DEFAULTS["outputs/folder"]
|
|
192
|
+
var folder := ""
|
|
193
|
+
if folder_text.begins_with("res://"):
|
|
194
|
+
folder = normal_res(folder_text)
|
|
195
|
+
elif folder_text.is_absolute_path():
|
|
196
|
+
folder = abs_to_res(project, folder_text)
|
|
197
|
+
if folder != "":
|
|
198
|
+
folder = normal_res(folder)
|
|
199
|
+
else:
|
|
200
|
+
folder = normal_res(topo_res.get_base_dir() + "/" + folder_text)
|
|
201
|
+
if folder == "":
|
|
202
|
+
return {"error": "the output folder %s is outside the Godot project: Godot names files by res:// paths" % folder_text}
|
|
203
|
+
var per = params.get("outputs/per_output_folders", DEFAULTS["outputs/per_output_folders"])
|
|
204
|
+
var skip_text = params.get("outputs/skip", DEFAULTS["outputs/skip"])
|
|
205
|
+
var skip := PackedStringArray()
|
|
206
|
+
for s in String(skip_text).split(","):
|
|
207
|
+
var id := s.strip_edges()
|
|
208
|
+
if id != "" and not skip.has(id):
|
|
209
|
+
skip.append(id)
|
|
210
|
+
skip.sort()
|
|
211
|
+
var mode = params.get("instances/mode", DEFAULTS["instances/mode"])
|
|
212
|
+
var expand: bool = (typeof(mode) == TYPE_INT and mode == 1) or (typeof(mode) == TYPE_FLOAT and int(mode) == 1) or (typeof(mode) == TYPE_STRING and mode == "Expand")
|
|
213
|
+
return {"folder": folder, "instancing": "expand" if expand else "packed", "per_output_folders": per if typeof(per) == TYPE_BOOL else true, "skip": skip}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
## The [params] of a .topo's import file (<id>.topo.import); {} when it has none.
|
|
217
|
+
static func import_params(topo_abs: String) -> Dictionary:
|
|
218
|
+
var cf := ConfigFile.new()
|
|
219
|
+
if cf.load(topo_abs + ".import") != OK or not cf.has_section("params"):
|
|
220
|
+
return {}
|
|
221
|
+
var out := {}
|
|
222
|
+
for k in cf.get_section_keys("params"):
|
|
223
|
+
out[k] = cf.get_value("params", k)
|
|
224
|
+
return out
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
static func same_options(a, b: Dictionary) -> bool:
|
|
228
|
+
if typeof(a) != TYPE_DICTIONARY:
|
|
229
|
+
return false
|
|
230
|
+
if String(a.get("folder", "")) != b.folder or String(a.get("instancing", "")) != b.instancing:
|
|
231
|
+
return false
|
|
232
|
+
if typeof(a.get("per_output_folders")) != TYPE_BOOL or a.per_output_folders != b.per_output_folders:
|
|
233
|
+
return false
|
|
234
|
+
return _id_set(a.get("skip", [])) == _id_set(b.skip)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
static func _id_set(list) -> PackedStringArray:
|
|
238
|
+
var out := PackedStringArray()
|
|
239
|
+
if list is Array or list is PackedStringArray:
|
|
240
|
+
for s in list:
|
|
241
|
+
if not out.has(String(s)):
|
|
242
|
+
out.append(String(s))
|
|
243
|
+
out.sort()
|
|
244
|
+
return out
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
# ------------------------------------------------------------------------------------------------------- records
|
|
248
|
+
|
|
249
|
+
## A package's record: {"record": Dictionary or null (none), "error": why it cannot be read, or ""}.
|
|
250
|
+
static func read_record(dir: String) -> Dictionary:
|
|
251
|
+
var file := dir.path_join(RECORD)
|
|
252
|
+
if not FileAccess.file_exists(file):
|
|
253
|
+
return {"record": null, "error": ""}
|
|
254
|
+
var text := FileAccess.get_file_as_string(file).trim_prefix("")
|
|
255
|
+
var json := JSON.new()
|
|
256
|
+
if json.parse(text) != OK:
|
|
257
|
+
return {"record": null, "error": "%s: %s (line %d)" % [file, json.get_error_message(), json.get_error_line()]}
|
|
258
|
+
var raw = json.data
|
|
259
|
+
if typeof(raw) != TYPE_DICTIONARY or not (typeof(raw.get("schema")) == TYPE_FLOAT or typeof(raw.get("schema")) == TYPE_INT):
|
|
260
|
+
return {"record": null, "error": "%s is not a cook record (it has no \"schema\")" % file}
|
|
261
|
+
return {"record": raw, "error": ""}
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
## "0.4.0" against "0.10.1": the dot-separated numbers (the leading digits of each part), a missing part 0.
|
|
265
|
+
static func compare_versions(a: String, b: String) -> int:
|
|
266
|
+
var x := _version_parts(a)
|
|
267
|
+
var y := _version_parts(b)
|
|
268
|
+
for i in maxi(x.size(), y.size()):
|
|
269
|
+
var d: int = (x[i] if i < x.size() else 0) - (y[i] if i < y.size() else 0)
|
|
270
|
+
if d != 0:
|
|
271
|
+
return d
|
|
272
|
+
return 0
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
static func _version_parts(v: String) -> Array:
|
|
276
|
+
var out := []
|
|
277
|
+
for p in v.split("."):
|
|
278
|
+
var digits := ""
|
|
279
|
+
for c in p:
|
|
280
|
+
if c >= "0" and c <= "9":
|
|
281
|
+
digits += c
|
|
282
|
+
else:
|
|
283
|
+
break
|
|
284
|
+
out.append(digits.to_int() if digits != "" else 0)
|
|
285
|
+
return out
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
static func _sorted_keys(d) -> Array:
|
|
289
|
+
if typeof(d) != TYPE_DICTIONARY:
|
|
290
|
+
return []
|
|
291
|
+
var keys: Array = d.keys()
|
|
292
|
+
keys.sort()
|
|
293
|
+
return keys
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
static func _fresh(state: String, why: String, path: String, text: String, note := "") -> Dictionary:
|
|
297
|
+
return {"state": state, "why": why, "path": path, "note": note, "text": text}
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
## The one definition of freshness (PROTOCOL.md "Freshness"), checked in this order; the first rule that applies decides:
|
|
301
|
+
## 1. no record: never cooked; 2. a newer schema: stale (update the addon); another schema or flavour: stale;
|
|
302
|
+
## 3. other options; 4. a source missing or changed; 5. a folder's listing changed; 6. an output file missing or
|
|
303
|
+
## changed: stale; 7. the installed TopoTopo (`installed`, "" when none is found) newer than the record's: stale
|
|
304
|
+
## (older: the note "update_topotopo"); 8. an output failed: failed; 9. ok.
|
|
305
|
+
## `dir`: the package folder, `project`: the Godot project folder (both absolute); `options` as options_from_params.
|
|
306
|
+
func freshness(dir: String, record, options: Dictionary, project: String, installed: String) -> Dictionary:
|
|
307
|
+
if record == null:
|
|
308
|
+
return _fresh("never_cooked", "record", "", "never cooked")
|
|
309
|
+
var schema := int(record.get("schema", 0))
|
|
310
|
+
if schema > SCHEMA:
|
|
311
|
+
return _fresh("stale", "newer_schema", "", "the record has schema %d, newer than this addon reads (%d): update the addon (topotopo godot setup <project>)" % [schema, SCHEMA])
|
|
312
|
+
if schema != SCHEMA or record.get("for") != FOR:
|
|
313
|
+
return _fresh("stale", "schema", "", "the record is of another kind (schema %d, for %s)" % [schema, record.get("for")])
|
|
314
|
+
if not same_options(record.get("options"), options):
|
|
315
|
+
return _fresh("stale", "options", "", "the import options changed since the last cook")
|
|
316
|
+
var sources = record.get("sources", {})
|
|
317
|
+
for rel in _sorted_keys(sources):
|
|
318
|
+
var now := file_content_sha(abs_of(dir, rel))
|
|
319
|
+
if now == "":
|
|
320
|
+
return _fresh("stale", "source", rel, "%s is missing" % rel)
|
|
321
|
+
if now != String(sources[rel]):
|
|
322
|
+
return _fresh("stale", "source", rel, "%s changed after the last cook" % rel)
|
|
323
|
+
var folders = record.get("folders", {})
|
|
324
|
+
for folder in _sorted_keys(folders):
|
|
325
|
+
if not same_set(folders[folder], listing(abs_of(dir, folder))):
|
|
326
|
+
return _fresh("stale", "folder", folder, "%s/ holds other files than at the last cook" % folder)
|
|
327
|
+
var outputs = record.get("outputs", {})
|
|
328
|
+
for id in _sorted_keys(outputs):
|
|
329
|
+
var files = outputs[id].get("files", {}) if typeof(outputs[id]) == TYPE_DICTIONARY else {}
|
|
330
|
+
for file in _sorted_keys(files):
|
|
331
|
+
var now := file_raw_sha(res_to_abs(project, file))
|
|
332
|
+
if now == "":
|
|
333
|
+
return _fresh("stale", "output", file, "%s is missing" % file)
|
|
334
|
+
if now != String(files[file]):
|
|
335
|
+
return _fresh("stale", "output", file, "%s was changed after the last cook" % file)
|
|
336
|
+
var note := ""
|
|
337
|
+
if installed != "":
|
|
338
|
+
var c := compare_versions(installed, String(record.get("topotopo", "")))
|
|
339
|
+
if c > 0:
|
|
340
|
+
return _fresh("stale", "version", "", "cooked with TopoTopo %s; %s is installed" % [record.get("topotopo"), installed])
|
|
341
|
+
if c < 0:
|
|
342
|
+
note = "update_topotopo"
|
|
343
|
+
var failed := []
|
|
344
|
+
for id in _sorted_keys(outputs):
|
|
345
|
+
if typeof(outputs[id]) == TYPE_DICTIONARY and outputs[id].get("state") == "failed":
|
|
346
|
+
failed.append(id)
|
|
347
|
+
if failed.size():
|
|
348
|
+
return _fresh("failed", "failed", failed[0], "%s %s did not cook" % ["output" if failed.size() == 1 else "outputs", ", ".join(failed)], note)
|
|
349
|
+
return _fresh("ok", "", "", "cooked, current", note)
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
## The output files a record lists (res://), outputs in id order, files in key order.
|
|
353
|
+
static func output_files(record) -> PackedStringArray:
|
|
354
|
+
var out := PackedStringArray()
|
|
355
|
+
if typeof(record) != TYPE_DICTIONARY:
|
|
356
|
+
return out
|
|
357
|
+
var outputs = record.get("outputs", {})
|
|
358
|
+
for id in _sorted_keys(outputs):
|
|
359
|
+
if typeof(outputs[id]) == TYPE_DICTIONARY:
|
|
360
|
+
for f in _sorted_keys(outputs[id].get("files", {})):
|
|
361
|
+
out.append(f)
|
|
362
|
+
return out
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
# ------------------------------------------------------------------------------------------------ Godot's scan
|
|
366
|
+
|
|
367
|
+
## Every .topo Godot's scan of a project sees (absolute paths, sorted): names starting with "." are not seen, a folder
|
|
368
|
+
## holding .gdignore and a folder below the root holding project.godot are not entered.
|
|
369
|
+
static func find_topos(project: String) -> PackedStringArray:
|
|
370
|
+
var out := PackedStringArray()
|
|
371
|
+
_walk_project(project, 0, out)
|
|
372
|
+
return out
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
static func _walk_project(dir: String, depth: int, out: PackedStringArray) -> void:
|
|
376
|
+
var d := DirAccess.open(dir)
|
|
377
|
+
if d == null:
|
|
378
|
+
return
|
|
379
|
+
d.include_hidden = true
|
|
380
|
+
d.include_navigational = false
|
|
381
|
+
var files := d.get_files()
|
|
382
|
+
if depth > 0 and (files.has(".gdignore") or files.has("project.godot")):
|
|
383
|
+
return
|
|
384
|
+
var names := Array(files)
|
|
385
|
+
names.sort()
|
|
386
|
+
for f in names:
|
|
387
|
+
if not f.begins_with(".") and f.length() > 5 and f.ends_with(".topo"):
|
|
388
|
+
out.append(dir.path_join(f))
|
|
389
|
+
if depth >= 64:
|
|
390
|
+
return
|
|
391
|
+
var subs := Array(d.get_directories())
|
|
392
|
+
subs.sort()
|
|
393
|
+
for s in subs:
|
|
394
|
+
if not s.begins_with("."):
|
|
395
|
+
_walk_project(dir.path_join(s), depth + 1, out)
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
static func _holds_topo(dir: String) -> bool:
|
|
399
|
+
var d := DirAccess.open(dir)
|
|
400
|
+
if d == null:
|
|
401
|
+
return false
|
|
402
|
+
d.include_hidden = true
|
|
403
|
+
for f in d.get_files():
|
|
404
|
+
if f.length() > 5 and f.ends_with(".topo"):
|
|
405
|
+
return true
|
|
406
|
+
return false
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
## A .topo that is a published copy, not a package: beside a version.json, in a topotopo-packages/ folder, or in the
|
|
410
|
+
## versions/ or packages/ folder of a package (a folder holding a .topo).
|
|
411
|
+
static func is_published_copy(topo_abs: String) -> bool:
|
|
412
|
+
var dir := topo_abs.get_base_dir()
|
|
413
|
+
if FileAccess.file_exists(dir.path_join("version.json")):
|
|
414
|
+
return true
|
|
415
|
+
var d := dir
|
|
416
|
+
while true:
|
|
417
|
+
var up := d.get_base_dir()
|
|
418
|
+
if up == d or up == "":
|
|
419
|
+
return false
|
|
420
|
+
var name := d.get_file().to_lower()
|
|
421
|
+
if name == "topotopo-packages":
|
|
422
|
+
return true
|
|
423
|
+
if (name == "versions" or name == "packages") and _holds_topo(up):
|
|
424
|
+
return true
|
|
425
|
+
d = up
|
|
426
|
+
return false
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
## The package's TopoTopo folders Godot imports (no .gdignore): "graphs/" …
|
|
430
|
+
static func exposed(dir: String) -> PackedStringArray:
|
|
431
|
+
var out := PackedStringArray()
|
|
432
|
+
for h in HIDDEN:
|
|
433
|
+
if DirAccess.dir_exists_absolute(dir.path_join(h)) and not FileAccess.file_exists(dir.path_join(h).path_join(".gdignore")):
|
|
434
|
+
out.append(h + "/")
|
|
435
|
+
return out
|