@defold-typescript/types 0.39.0 → 0.41.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/api-availability.json +4024 -716
- package/api-migrations.json +27 -0
- package/api-signatures.json +18118 -10264
- package/api-targets.json +448 -11
- package/examples/translations.json +619 -148
- package/fixtures/messages_doc.json +96 -0
- package/generated/b2d.d.ts +680 -4
- package/generated/b2d_body.d.ts +29 -103
- package/generated/b2d_chain.d.ts +5 -6
- package/generated/b2d_fixture.d.ts +34 -38
- package/generated/b2d_joint.d.ts +503 -25
- package/generated/b2d_shape.d.ts +199 -14
- package/generated/b2d_world.d.ts +57 -63
- package/generated/buffer.d.ts +33 -29
- package/generated/builtin-messages.d.ts +7 -1
- package/generated/bullet3d.d.ts +91 -0
- package/generated/bullet3d_collision_object.d.ts +433 -0
- package/generated/bullet3d_constraint.d.ts +818 -0
- package/generated/bullet3d_rigid_body.d.ts +429 -0
- package/generated/bullet3d_shape.d.ts +123 -0
- package/generated/bullet3d_world.d.ts +492 -0
- package/generated/camera.d.ts +31 -34
- package/generated/collectionfactory.d.ts +26 -27
- package/generated/collectionproxy.d.ts +22 -6
- package/generated/compute.d.ts +12 -238
- package/generated/crash.d.ts +24 -10
- package/generated/editor-vm/http.d.ts +90 -7
- package/generated/editor-vm/image.d.ts +7 -7
- package/generated/editor-vm/json.d.ts +11 -0
- package/generated/editor-vm/localization.d.ts +7 -7
- package/generated/editor-vm/tilemap_tiles.d.ts +56 -10
- package/generated/editor-vm/zip.d.ts +28 -0
- package/generated/editor.d.ts +1496 -430
- package/generated/factory.d.ts +21 -25
- package/generated/font.d.ts +64 -22
- package/generated/go.d.ts +243 -186
- package/generated/graphics.d.ts +374 -84
- package/generated/gui.d.ts +282 -492
- package/generated/html5.d.ts +5 -3
- package/generated/http.d.ts +31 -36
- package/generated/image.d.ts +127 -85
- package/generated/json.d.ts +34 -16
- package/generated/kinds/gui-script.d.ts +8 -0
- package/generated/kinds/render-script.d.ts +8 -0
- package/generated/kinds/script.d.ts +8 -0
- package/generated/label.d.ts +77 -7
- package/generated/liveupdate.d.ts +13 -10
- package/generated/material.d.ts +312 -360
- package/generated/model.d.ts +72 -42
- package/generated/particlefx.d.ts +19 -28
- package/generated/physics.d.ts +378 -144
- package/generated/profiler.d.ts +14 -24
- package/generated/render.d.ts +294 -297
- package/generated/resource.d.ts +753 -641
- package/generated/socket.d.ts +131 -134
- package/generated/sound.d.ts +65 -34
- package/generated/sprite.d.ts +39 -17
- package/generated/sys.d.ts +237 -182
- package/generated/tilemap.d.ts +21 -16
- package/generated/timer.d.ts +34 -21
- package/generated/versions/defold-1.12.4/b2d_body.d.ts +0 -7
- package/generated/versions/defold-1.12.4/buffer.d.ts +18 -17
- package/generated/versions/defold-1.12.4/camera.d.ts +23 -23
- package/generated/versions/defold-1.12.4/collectionfactory.d.ts +21 -19
- package/generated/versions/defold-1.12.4/collectionproxy.d.ts +2 -2
- package/generated/versions/defold-1.12.4/crash.d.ts +2 -2
- package/generated/versions/defold-1.12.4/factory.d.ts +15 -16
- package/generated/versions/defold-1.12.4/go.d.ts +15 -17
- package/generated/versions/defold-1.12.4/gui.d.ts +111 -193
- package/generated/versions/defold-1.12.4/html5.d.ts +4 -2
- package/generated/versions/defold-1.12.4/http.d.ts +4 -15
- package/generated/versions/defold-1.12.4/image.d.ts +38 -46
- package/generated/versions/defold-1.12.4/index.d.ts +2 -0
- package/generated/versions/defold-1.12.4/json.d.ts +10 -6
- package/generated/versions/defold-1.12.4/label.d.ts +2 -3
- package/generated/versions/defold-1.12.4/liveupdate.d.ts +5 -3
- package/generated/versions/defold-1.12.4/model.d.ts +34 -13
- package/generated/versions/defold-1.12.4/particlefx.d.ts +2 -5
- package/generated/versions/defold-1.12.4/physics.d.ts +82 -78
- package/generated/versions/defold-1.12.4/profiler.d.ts +3 -6
- package/generated/versions/defold-1.12.4/render.d.ts +160 -132
- package/generated/versions/defold-1.12.4/resource.d.ts +212 -209
- package/generated/versions/defold-1.12.4/socket.d.ts +45 -61
- package/generated/versions/defold-1.12.4/sound.d.ts +11 -11
- package/generated/versions/defold-1.12.4/sprite.d.ts +24 -6
- package/generated/versions/defold-1.12.4/sys.d.ts +45 -68
- package/generated/versions/defold-1.12.4/tilemap.d.ts +18 -11
- package/generated/versions/defold-1.12.4/timer.d.ts +5 -3
- package/generated/versions/defold-1.12.4/vmath.d.ts +5 -26
- package/generated/versions/defold-1.12.4/window.d.ts +1 -16
- package/generated/versions/defold-1.13.0/b2d_body.d.ts +10 -55
- package/generated/versions/defold-1.13.0/b2d_fixture.d.ts +25 -25
- package/generated/versions/defold-1.13.0/b2d_shape.d.ts +188 -5
- package/generated/versions/defold-1.13.0/b2d_world.d.ts +16 -10
- package/generated/versions/defold-1.13.0/buffer.d.ts +18 -17
- package/generated/versions/defold-1.13.0/camera.d.ts +27 -27
- package/generated/versions/defold-1.13.0/collectionfactory.d.ts +21 -19
- package/generated/versions/defold-1.13.0/collectionproxy.d.ts +2 -2
- package/generated/versions/defold-1.13.0/compute.d.ts +1 -70
- package/generated/versions/defold-1.13.0/crash.d.ts +2 -2
- package/generated/versions/defold-1.13.0/editor-vm/tilemap_tiles.d.ts +3 -3
- package/generated/versions/defold-1.13.0/editor.d.ts +34 -24
- package/generated/versions/defold-1.13.0/factory.d.ts +15 -16
- package/generated/versions/defold-1.13.0/go.d.ts +15 -17
- package/generated/versions/defold-1.13.0/graphics.d.ts +121 -37
- package/generated/versions/defold-1.13.0/gui.d.ts +111 -193
- package/generated/versions/defold-1.13.0/html5.d.ts +4 -2
- package/generated/versions/defold-1.13.0/http.d.ts +4 -15
- package/generated/versions/defold-1.13.0/image.d.ts +38 -46
- package/generated/versions/defold-1.13.0/index.d.ts +2 -0
- package/generated/versions/defold-1.13.0/json.d.ts +10 -6
- package/generated/versions/defold-1.13.0/label.d.ts +2 -3
- package/generated/versions/defold-1.13.0/liveupdate.d.ts +7 -5
- package/generated/versions/defold-1.13.0/material.d.ts +69 -107
- package/generated/versions/defold-1.13.0/model.d.ts +34 -13
- package/generated/versions/defold-1.13.0/particlefx.d.ts +2 -5
- package/generated/versions/defold-1.13.0/physics.d.ts +82 -78
- package/generated/versions/defold-1.13.0/profiler.d.ts +3 -6
- package/generated/versions/defold-1.13.0/render.d.ts +160 -132
- package/generated/versions/defold-1.13.0/resource.d.ts +217 -210
- package/generated/versions/defold-1.13.0/socket.d.ts +45 -61
- package/generated/versions/defold-1.13.0/sound.d.ts +11 -11
- package/generated/versions/defold-1.13.0/sprite.d.ts +24 -6
- package/generated/versions/defold-1.13.0/sys.d.ts +45 -68
- package/generated/versions/defold-1.13.0/tilemap.d.ts +18 -11
- package/generated/versions/defold-1.13.0/timer.d.ts +5 -3
- package/generated/versions/defold-1.13.0/vmath.d.ts +5 -26
- package/generated/versions/defold-1.13.0/window.d.ts +1 -16
- package/generated/versions/defold-1.13.1/b2d.d.ts +33 -0
- package/generated/versions/defold-1.13.1/b2d_body.d.ts +636 -0
- package/generated/versions/defold-1.13.1/b2d_chain.d.ts +106 -0
- package/generated/versions/defold-1.13.1/b2d_fixture.d.ts +157 -0
- package/generated/versions/defold-1.13.1/b2d_joint.d.ts +823 -0
- package/generated/versions/defold-1.13.1/b2d_shape.d.ts +400 -0
- package/generated/versions/defold-1.13.1/b2d_world.d.ts +320 -0
- package/generated/versions/defold-1.13.1/buffer.d.ts +189 -0
- package/generated/versions/defold-1.13.1/camera.d.ts +303 -0
- package/generated/versions/defold-1.13.1/collectionfactory.d.ts +151 -0
- package/generated/versions/defold-1.13.1/collectionproxy.d.ts +93 -0
- package/generated/versions/defold-1.13.1/compute.d.ts +237 -0
- package/generated/versions/defold-1.13.1/crash.d.ts +143 -0
- package/generated/versions/defold-1.13.1/editor-vm/http.d.ts +56 -0
- package/generated/versions/defold-1.13.1/editor-vm/image.d.ts +48 -0
- package/generated/versions/defold-1.13.1/editor-vm/json.d.ts +10 -0
- package/generated/versions/defold-1.13.1/editor-vm/localization.d.ts +42 -0
- package/generated/versions/defold-1.13.1/editor-vm/tilemap_tiles.d.ts +80 -0
- package/generated/versions/defold-1.13.1/editor-vm/zip.d.ts +10 -0
- package/generated/versions/defold-1.13.1/editor-vm/zlib.d.ts +24 -0
- package/generated/versions/defold-1.13.1/editor.d.ts +1121 -0
- package/generated/versions/defold-1.13.1/factory.d.ts +124 -0
- package/generated/versions/defold-1.13.1/font.d.ts +81 -0
- package/generated/versions/defold-1.13.1/go.d.ts +1107 -0
- package/generated/versions/defold-1.13.1/graphics.d.ts +411 -0
- package/generated/versions/defold-1.13.1/gui.d.ts +2353 -0
- package/generated/versions/defold-1.13.1/html5.d.ts +55 -0
- package/generated/versions/defold-1.13.1/http.d.ts +77 -0
- package/generated/versions/defold-1.13.1/image.d.ts +131 -0
- package/generated/versions/defold-1.13.1/index.d.ts +57 -0
- package/generated/versions/defold-1.13.1/json.d.ts +80 -0
- package/generated/versions/defold-1.13.1/kinds/editor-script.d.ts +14 -0
- package/generated/versions/defold-1.13.1/label.d.ts +93 -0
- package/generated/versions/defold-1.13.1/liveupdate.d.ts +142 -0
- package/generated/versions/defold-1.13.1/material.d.ts +408 -0
- package/generated/versions/defold-1.13.1/model.d.ts +272 -0
- package/generated/versions/defold-1.13.1/msg.d.ts +10 -0
- package/generated/versions/defold-1.13.1/particlefx.d.ts +163 -0
- package/generated/versions/defold-1.13.1/physics.d.ts +559 -0
- package/generated/versions/defold-1.13.1/profiler.d.ts +235 -0
- package/generated/versions/defold-1.13.1/render.d.ts +1190 -0
- package/generated/versions/defold-1.13.1/resource.d.ts +1523 -0
- package/generated/versions/defold-1.13.1/socket.d.ts +784 -0
- package/generated/versions/defold-1.13.1/sound.d.ts +292 -0
- package/generated/versions/defold-1.13.1/sprite.d.ts +175 -0
- package/generated/versions/defold-1.13.1/sys.d.ts +678 -0
- package/generated/versions/defold-1.13.1/tilemap.d.ts +208 -0
- package/generated/versions/defold-1.13.1/timer.d.ts +125 -0
- package/generated/versions/defold-1.13.1/types.d.ts +61 -0
- package/generated/versions/defold-1.13.1/vmath.d.ts +774 -0
- package/generated/versions/defold-1.13.1/window.d.ts +183 -0
- package/generated/versions/defold-1.13.1/zlib.d.ts +41 -0
- package/generated/vmath.d.ts +6 -26
- package/generated/window.d.ts +71 -71
- package/identity-vocabulary.json +561 -0
- package/index.d.ts +8 -0
- package/package.json +13 -2
- package/scripts/example-store-io.ts +12 -1
- package/scripts/extension-goldens.ts +1 -0
- package/scripts/fidelity-baseline.json +146 -46
- package/scripts/generate-api-availability.ts +90 -12
- package/scripts/generate-api-signatures.ts +14 -3
- package/scripts/import-defold-release.ts +85 -24
- package/scripts/prose-constants.ts +157 -0
- package/scripts/regen.ts +396 -78
- package/scripts/shared-handle-methods.ts +53 -0
- package/scripts/signature-store-fs.ts +1 -0
- package/scripts/sync-api-docs.ts +16 -5
- package/src/api-availability.ts +0 -0
- package/src/api-doc.ts +201 -3
- package/src/api-identity.ts +252 -0
- package/src/component-properties.d.ts +33 -0
- package/src/core-types.ts +28 -3
- package/src/correction-pins.ts +49 -0
- package/src/custom-messages.d.ts +4 -3
- package/src/doc-comment.ts +139 -23
- package/src/doc-corrections.ts +108 -0
- package/src/editor-vm-globals.d.ts +5 -2
- package/src/emit-dts.ts +2474 -281
- package/src/emit-messages.ts +52 -0
- package/src/engine-globals.d.ts +2 -2
- package/src/example-store.ts +125 -14
- package/src/field-correction-coverage.ts +204 -0
- package/src/fnv1a.ts +16 -0
- package/src/go-overloads.d.ts +33 -13
- package/src/index-base-table.ts +145 -0
- package/src/index-slot-classifications.ts +588 -0
- package/src/index.ts +39 -2
- package/src/library-index-slot-classifications.ts +332 -0
- package/src/lifecycle.ts +61 -199
- package/src/luals-type-expr.ts +354 -0
- package/src/msg-overloads.d.ts +0 -1
- package/src/param-correction-provenance.ts +64 -0
- package/src/return-correction-provenance.ts +58 -16
- package/src/script-api.ts +3 -1
- package/src/sys-overloads.d.ts +48 -0
- package/src/vmath-overloads.d.ts +27 -1
- package/src/window-event-guard.d.ts +6 -9
- package/url-parameters.json +1 -2
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"b2d.fixture.set_shape": [
|
|
15
15
|
{
|
|
16
16
|
"sourceHash": "ff836b80569f5d30",
|
|
17
|
-
"ts": "const body = b2d.get_body(\"#collisionobject\");\nif (body !== undefined) {\n const circle = b2d.fixture.get_shape(body, 1);\n
|
|
17
|
+
"ts": "const body = b2d.get_body(\"#collisionobject\");\nif (body !== undefined) {\n const circle = b2d.fixture.get_shape(body, 1);\n const radius = \"radius\" in circle ? circle.radius : undefined;\n b2d.fixture.set_shape(body, 1, { type: b2d.shape.SHAPE_TYPE_CIRCLE, radius: radius ?? 16, center: vmath.vector3(24, 0, 0) }, true);\n b2d.fixture.set_shape(body, 2, { type: b2d.shape.SHAPE_TYPE_EDGE, v1: vmath.vector3(-32, 0, 0), v2: vmath.vector3(32, 0, 0) });\n}"
|
|
18
18
|
}
|
|
19
19
|
],
|
|
20
20
|
"b2d.shape.set_shape": [
|
|
21
21
|
{
|
|
22
22
|
"sourceHash": "f31970e9ebb8d446",
|
|
23
|
-
"ts": "const body = b2d.get_body(\"#collisionobject\");\nif (body !== undefined) {\n const circle = b2d.shape.get_shape(body, 1);\n
|
|
23
|
+
"ts": "const body = b2d.get_body(\"#collisionobject\");\nif (body !== undefined) {\n const circle = b2d.shape.get_shape(body, 1);\n const radius = \"radius\" in circle ? circle.radius : undefined;\n b2d.shape.set_shape(body, 1, { type: b2d.shape.SHAPE_TYPE_CIRCLE, radius: radius ?? 16, center: vmath.vector3(24, 0, 0) }, true);\n b2d.shape.set_shape(body, 2, { type: b2d.shape.SHAPE_TYPE_SEGMENT, v1: vmath.vector3(-32, 0, 0), v2: vmath.vector3(32, 0, 0) });\n}"
|
|
24
24
|
}
|
|
25
25
|
],
|
|
26
26
|
"buffer.copy_buffer": [
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"buffer.copy_stream": [
|
|
33
33
|
{
|
|
34
34
|
"sourceHash": "359ea94639622db5",
|
|
35
|
-
"ts": "// How to update a texture of a sprite:\nconst srcbuffer = resource.get_buffer(\"/src.bufferc\");\nconst dstbuffer = resource.get_buffer(\"/dst.bufferc\");\n\n// copy entire stream\nconst srcstream = buffer.get_stream(srcbuffer, hash(\"xyz\"));\nconst dststream = buffer.get_stream(dstbuffer, hash(\"xyz\"));\nbuffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length);"
|
|
35
|
+
"ts": "// How to update a texture of a sprite:\nconst srcbuffer = resource.get_buffer(\"/src.bufferc\");\nconst dstbuffer = resource.get_buffer(\"/dst.bufferc\");\n\n// copy entire stream\nconst srcstream = buffer.get_stream(srcbuffer, hash(\"xyz\"));\nconst dststream = buffer.get_stream(dstbuffer, hash(\"xyz\"));\nbuffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length());"
|
|
36
36
|
}
|
|
37
37
|
],
|
|
38
38
|
"buffer.create": [
|
|
39
39
|
{
|
|
40
40
|
"sourceHash": "d83315970921bbc7",
|
|
41
|
-
"ts": "// How to create and initialize a buffer\nexport default defineScript({\n init(
|
|
41
|
+
"ts": "// How to create and initialize a buffer\nexport default defineScript({\n init() {\n const size = 128;\n const [width, height] = [size, size];\n const [r, g, b] = [0xff, 0x80, 0x10];\n const image = buffer.create(size * size, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n const imagestream = buffer.get_stream(image, hash(\"rgb\"));\n\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const index = y * width * 3 + x * 3;\n imagestream[index + 0] = r;\n imagestream[index + 1] = g;\n imagestream[index + 2] = b;\n }\n }\n return { image, imagestream };\n },\n});"
|
|
42
42
|
}
|
|
43
43
|
],
|
|
44
44
|
"buffer.get_metadata": [
|
|
@@ -53,6 +53,102 @@
|
|
|
53
53
|
"ts": "// How to set a metadata entry on a buffer\nconst buf = resource.get_buffer(\"/my.bufferc\");\n\n// create a new metadata entry with three floats\nbuffer.set_metadata(buf, hash(\"somefloats\"), [1.5, 3.2, 7.9], buffer.VALUE_TYPE_FLOAT32);\n// ...\n// update to a new set of values\nbuffer.set_metadata(buf, hash(\"somefloats\"), [-2.5, 10.0, 32.2], buffer.VALUE_TYPE_FLOAT32);"
|
|
54
54
|
}
|
|
55
55
|
],
|
|
56
|
+
"bullet3d.collision_object.get_shapes": [
|
|
57
|
+
{
|
|
58
|
+
"sourceHash": "253c074f6a45c615",
|
|
59
|
+
"ts": "// Enumerate the logical shapes attached to a collision object:\nexport default defineScript({\n init() {\n const object = bullet3d.get_collision_object(\"#collisionobject\");\n if (object === undefined) return;\n for (const shape of bullet3d.collision_object.get_shapes(object)) {\n const index = bullet3d.shape.get_index(shape);\n const data = bullet3d.shape.get_shape(shape);\n print(\"shape\", index, \"type\", data.type);\n }\n },\n});"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"bullet3d.collision_object.set_ccd_motion_threshold": [
|
|
63
|
+
{
|
|
64
|
+
"sourceHash": "0969c6cba121a215",
|
|
65
|
+
"ts": "// Enable continuous collision detection for a small, fast-moving body:\nexport default defineScript({\n init() {\n const body = bullet3d.get_rigid_body(\"#collisionobject\");\n if (body === undefined) return;\n bullet3d.collision_object.set_ccd_swept_sphere_radius(body, 0.25);\n bullet3d.collision_object.set_ccd_motion_threshold(body, 0.5);\n },\n});"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"bullet3d.collision_object.set_world_transform": [
|
|
69
|
+
{
|
|
70
|
+
"sourceHash": "23d7b59707855f9f",
|
|
71
|
+
"ts": "// Move a collision object while preserving its rotation:\nexport default defineScript({\n init() {\n const object = bullet3d.get_collision_object(\"#collisionobject\");\n if (object === undefined) return;\n const [position, rotation] = bullet3d.collision_object.get_world_transform(object);\n bullet3d.collision_object.set_world_transform(object, position.add(vmath.vector3(0, 5, 0)), rotation);\n bullet3d.collision_object.activate(object, true);\n },\n});"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"bullet3d.constraint.create_generic_6dof_spring": [
|
|
75
|
+
{
|
|
76
|
+
"sourceHash": "208db6534df9ca4a",
|
|
77
|
+
"ts": "// Create a spring that moves along its first linear axis:\nexport default defineScript({\n init() {\n const body_a = bullet3d.get_rigid_body(\"/body_a#collisionobject\");\n const body_b = bullet3d.get_rigid_body(\"/body_b#collisionobject\");\n let spring: bullet3d.constraint.btTypedConstraint | undefined;\n if (body_a !== undefined && body_b !== undefined) {\n spring = bullet3d.constraint.create_generic_6dof_spring(body_a, body_b, {\n frame_a_position: vmath.vector3(),\n frame_a_rotation: vmath.quat(),\n frame_b_position: vmath.vector3(),\n frame_b_rotation: vmath.quat(),\n });\n bullet3d.constraint.set_limit(spring, 1, -1, 1);\n bullet3d.constraint.enable_spring(spring, 1, true);\n bullet3d.constraint.set_spring_stiffness(spring, 1, 20);\n bullet3d.constraint.set_spring_damping(spring, 1, 0.5);\n bullet3d.constraint.set_spring_equilibrium_point(spring, 1, 0);\n }\n return { spring };\n },\n\n final(self) {\n if (self.spring !== undefined && bullet3d.constraint.is_valid(self.spring)) {\n bullet3d.constraint.destroy(self.spring);\n }\n },\n});"
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"bullet3d.constraint.create_hinge": [
|
|
81
|
+
{
|
|
82
|
+
"sourceHash": "76ffd570e08f0b18",
|
|
83
|
+
"ts": "// Create a motorized hinge with a 90-degree range:\nexport default defineScript({\n init() {\n const body_a = bullet3d.get_rigid_body(\"/door#collisionobject\");\n const body_b = bullet3d.get_rigid_body(\"/frame#collisionobject\");\n let hinge: bullet3d.constraint.btTypedConstraint | undefined;\n if (body_a !== undefined) {\n hinge = bullet3d.constraint.create_hinge(body_a, body_b, {\n frame_a_position: vmath.vector3(-0.5, 0, 0),\n frame_a_rotation: vmath.quat(),\n frame_b_position: vmath.vector3(0.5, 0, 0),\n frame_b_rotation: vmath.quat(),\n });\n bullet3d.constraint.set_hinge_limits(hinge, -math.pi / 4, math.pi / 4);\n bullet3d.constraint.set_hinge_motor(hinge, true, 1.5, 2.5);\n }\n return { hinge };\n },\n\n final(self) {\n if (self.hinge !== undefined && bullet3d.constraint.is_valid(self.hinge)) {\n bullet3d.constraint.destroy(self.hinge);\n }\n },\n});"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"bullet3d.constraint.create_point_to_point": [
|
|
87
|
+
{
|
|
88
|
+
"sourceHash": "91bc34d28899d0c1",
|
|
89
|
+
"ts": "// Join two bodies at matching local pivots and explicitly destroy the\n// constraint when the script is finalized:\nexport default defineScript({\n init() {\n const body_a = bullet3d.get_rigid_body(\"/body_a#collisionobject\");\n const body_b = bullet3d.get_rigid_body(\"/body_b#collisionobject\");\n let constraint: bullet3d.constraint.btTypedConstraint | undefined;\n if (body_a !== undefined) {\n constraint = bullet3d.constraint.create_point_to_point(body_a, body_b, {\n pivot_a: vmath.vector3(0.5, 0, 0),\n pivot_b: vmath.vector3(-0.5, 0, 0),\n });\n }\n return { constraint };\n },\n\n final(self) {\n if (self.constraint !== undefined && bullet3d.constraint.is_valid(self.constraint)) {\n bullet3d.constraint.destroy(self.constraint);\n }\n },\n});"
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"bullet3d.get_rigid_body": [
|
|
93
|
+
{
|
|
94
|
+
"sourceHash": "e09c75e81d50dd6c",
|
|
95
|
+
"ts": "const world = bullet3d.get_world();\nconst body = bullet3d.get_rigid_body(\"#collisionobject\");\nif (world !== undefined && body !== undefined && bullet3d.rigid_body.is_valid(body)) {\n bullet3d.rigid_body.apply_central_impulse(body, vmath.vector3(0, 10, 0));\n}\n\n// A trigger is a collision object, not a rigid body.\nconst trigger = bullet3d.get_collision_object(\"#trigger\");\nassert(trigger !== undefined && bullet3d.get_rigid_body(\"#trigger\") === undefined);"
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"bullet3d.rigid_body.apply_force": [
|
|
99
|
+
{
|
|
100
|
+
"sourceHash": "9f7182e8b1f12712",
|
|
101
|
+
"ts": "// Apply an upward force at the game object's current world position:\nexport default defineScript({\n init() {\n const body = bullet3d.get_rigid_body(\"#collisionobject\");\n if (body === undefined) return;\n const force = vmath.vector3(0, 100, 0);\n bullet3d.rigid_body.apply_force(body, force, go.get_world_position());\n },\n});"
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
"bullet3d.rigid_body.set_gravity": [
|
|
105
|
+
{
|
|
106
|
+
"sourceHash": "c790938f15458c40",
|
|
107
|
+
"ts": "// Give one body persistent custom gravity without discarding its other flags:\nexport default defineScript({\n init() {\n const body = bullet3d.get_rigid_body(\"#collisionobject\");\n if (body === undefined) return;\n let flags = bullet3d.rigid_body.get_flags(body);\n flags = bit.bor(flags, bullet3d.rigid_body.BT_DISABLE_WORLD_GRAVITY);\n bullet3d.rigid_body.set_flags(body, flags);\n bullet3d.rigid_body.set_gravity(body, vmath.vector3(0, 4, 0));\n },\n});"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"bullet3d.rigid_body.set_mass": [
|
|
111
|
+
{
|
|
112
|
+
"sourceHash": "6f1ffcb5da18e9db",
|
|
113
|
+
"ts": "// Change the mass of a dynamic collision object and inspect its recalculated inertia:\nexport default defineScript({\n init() {\n const body = bullet3d.get_rigid_body(\"#collisionobject\");\n if (body === undefined) return;\n bullet3d.rigid_body.set_mass(body, 5);\n print(\"local inertia\", bullet3d.rigid_body.get_local_inertia(body));\n },\n});"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"bullet3d.shape.set_shape": [
|
|
117
|
+
{
|
|
118
|
+
"sourceHash": "822278c5e2152e23",
|
|
119
|
+
"ts": "// Increase the dimensions of the first box shape by 50 percent for this instance:\nexport default defineScript({\n init() {\n const object = bullet3d.get_collision_object(\"#collisionobject\");\n if (object === undefined) return;\n const shape = bullet3d.collision_object.get_shape(object, 1);\n const data = bullet3d.shape.get_shape(shape);\n\n if (data.type === bullet3d.shape.SHAPE_TYPE_BOX && \"dimensions\" in data) {\n data.dimensions = data.dimensions.mul(1.5);\n bullet3d.shape.set_shape(shape, data);\n }\n },\n});"
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
"bullet3d.world.cast_ray_async": [
|
|
123
|
+
{
|
|
124
|
+
"sourceHash": "bcd124b063567325",
|
|
125
|
+
"ts": "// Queue a downward cast and inspect only the closest non-trigger hit:\nconst world = bullet3d.get_world();\nif (world !== undefined) {\n bullet3d.world.cast_ray_async(\n world,\n go.get_world_position(),\n vmath.vector3(0, -100, 0),\n (self, hits) => {\n const hit = hits[0];\n if (hit !== undefined) {\n print(\"hit\", hit.object);\n }\n },\n { include_triggers: false },\n 1,\n );\n}"
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"bullet3d.world.cast_ray_closest": [
|
|
129
|
+
{
|
|
130
|
+
"sourceHash": "e0695680d5f69806",
|
|
131
|
+
"ts": "// Cast downward and report the closest non-trigger hit:\nexport default defineScript({\n init() {\n const world = bullet3d.get_world();\n if (world === undefined) return;\n const origin = go.get_world_position();\n const translation = vmath.vector3(0, -100, 0);\n const filter = { include_triggers: false };\n\n const hit = bullet3d.world.cast_ray_closest(world, origin, translation, filter);\n if (hit !== undefined) {\n const distance = vmath.length(translation) * hit.fraction;\n print(\"hit\", hit.object, \"after\", distance, \"units\");\n }\n },\n});"
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
"bullet3d.world.contact_test": [
|
|
135
|
+
{
|
|
136
|
+
"sourceHash": "24e4e290d62e54f3",
|
|
137
|
+
"ts": "// Inspect current contacts for this collision object:\nexport default defineScript({\n update(self, dt) {\n const world = bullet3d.get_world();\n const object = bullet3d.get_collision_object(\"#collisionobject\");\n if (world === undefined || object === undefined) return;\n const filter = { include_triggers: false };\n const contacts = bullet3d.world.contact_test(world, object, filter);\n\n for (const contact of contacts) {\n if (contact.distance < 0) {\n print(\"penetration\", -contact.distance, \"against\", contact.object_b);\n }\n }\n },\n});"
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
"bullet3d.world.overlap_shape": [
|
|
141
|
+
{
|
|
142
|
+
"sourceHash": "2b15e4c9166eeb30",
|
|
143
|
+
"ts": "// Find non-trigger objects overlapping a two-unit sphere around this game object:\nexport default defineScript({\n init() {\n const world = bullet3d.get_world();\n if (world === undefined) return;\n const shape = {\n type: bullet3d.shape.SHAPE_TYPE_SPHERE,\n diameter: 2,\n position: go.get_world_position(),\n };\n const filter = { include_triggers: false };\n const overlaps = bullet3d.world.overlap_shape(world, shape, filter);\n\n for (const object of overlaps) {\n print(\"overlap\", object);\n }\n },\n});"
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"bullet3d.world.set_gravity": [
|
|
147
|
+
{
|
|
148
|
+
"sourceHash": "d97b405b0c249b8c",
|
|
149
|
+
"ts": "// Set gravity for the current collection's physics world:\nexport default defineScript({\n init() {\n const world = bullet3d.get_world();\n if (world !== undefined) {\n bullet3d.world.set_gravity(world, vmath.vector3(0, -9.81, 0));\n }\n },\n});"
|
|
150
|
+
}
|
|
151
|
+
],
|
|
56
152
|
"camera.get_cameras": [
|
|
57
153
|
{
|
|
58
154
|
"sourceHash": "d332d9320898b958",
|
|
@@ -62,13 +158,13 @@
|
|
|
62
158
|
"camera.screen_to_world": [
|
|
63
159
|
{
|
|
64
160
|
"sourceHash": "0738c074908495cb",
|
|
65
|
-
"ts": "// Place objects at the touch point with a random Z position, keeping them\n// within the visible view zone.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed) {\n const perspective_camera = msg.url(\"#perspective_camera\");\n const random_z = math.random(\n camera.get_near_z(perspective_camera) + 0.01,\n camera.get_far_z(perspective_camera) - 0.01,\n );\n const world_position = camera.screen_to_world(\n vmath.vector3(action.screen_x, action.screen_y, random_z),\n perspective_camera,\n );\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
161
|
+
"ts": "// Place objects at the touch point with a random Z position, keeping them\n// within the visible view zone.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed && action.screen_x !== undefined && action.screen_y !== undefined) {\n const perspective_camera = msg.url(\"#perspective_camera\");\n const random_z = math.random(\n camera.get_near_z(perspective_camera) + 0.01,\n camera.get_far_z(perspective_camera) - 0.01,\n );\n const world_position = camera.screen_to_world(\n vmath.vector3(action.screen_x, action.screen_y, random_z),\n perspective_camera,\n );\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
66
162
|
}
|
|
67
163
|
],
|
|
68
164
|
"camera.screen_xy_to_world": [
|
|
69
165
|
{
|
|
70
166
|
"sourceHash": "ff65335713fc5698",
|
|
71
|
-
"ts": "// Place objects at the touch point.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed) {\n const world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y);\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
167
|
+
"ts": "// Place objects at the touch point.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed && action.screen_x !== undefined && action.screen_y !== undefined) {\n const world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y);\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
72
168
|
}
|
|
73
169
|
],
|
|
74
170
|
"camera.world_to_screen": [
|
|
@@ -79,8 +175,12 @@
|
|
|
79
175
|
],
|
|
80
176
|
"collectionfactory.create": [
|
|
81
177
|
{
|
|
82
|
-
"sourceHash": "
|
|
83
|
-
"ts": "
|
|
178
|
+
"sourceHash": "1ba3a94b5d04c5a0",
|
|
179
|
+
"ts": "export default defineScript({\n init() {\n // Spawn a small group of enemies.\n const pos = vmath.vector3(100, 12.5, 0);\n const rot = vmath.quat_rotation_z(Math.PI / 2);\n const scale = 0.5;\n const props = new LuaMap<Hash, Record<string, unknown>>();\n props.set(hash(\"/enemy_leader\"), { health: 1000.0 });\n props.set(hash(\"/enemy_1\"), { health: 200.0 });\n props.set(hash(\"/enemy_2\"), { health: 400.0, color: hash(\"green\") });\n\n const enemy_ids = collectionfactory.create(\"#enemyfactory\", pos, rot, props, scale);\n // enemy_ids now map to the spawned instance ids:\n //\n // pprint(self.enemy_ids)\n //\n // DEBUG:SCRIPT:\n // {\n // hash: [/enemy_leader] = hash: [/collection0/enemy_leader],\n // hash: [/enemy_1] = hash: [/collection0/enemy_1],\n // hash: [/enemy_2] = hash: [/collection0/enemy_2]\n // }\n\n // Send \"attack\" message to the leader. First look up its instance id.\n const leader_id = enemy_ids.get(hash(\"/enemy_leader\"));\n if (leader_id !== undefined) {\n msg.post(leader_id, \"attack\");\n }\n return { enemy_ids };\n },\n});"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"sourceHash": "4a14456855350b8c",
|
|
183
|
+
"ts": "function delete_enemies(self: { enemy_ids: Hash[] }) {\n go.delete(self.enemy_ids);\n}"
|
|
84
184
|
}
|
|
85
185
|
],
|
|
86
186
|
"collectionfactory.load": [
|
|
@@ -157,14 +257,22 @@
|
|
|
157
257
|
],
|
|
158
258
|
"editor.bob": [
|
|
159
259
|
{
|
|
160
|
-
"sourceHash": "
|
|
161
|
-
"ts": "
|
|
260
|
+
"sourceHash": "2d2af2a8d67e6042",
|
|
261
|
+
"ts": "editor.bob({ help: true });"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"sourceHash": "daf12f556b1915ae",
|
|
265
|
+
"ts": "const opts = { archive: true, platform: editor.platform };\neditor.bob(opts, \"distclean\", \"resolve\", \"build\", \"bundle\");"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"sourceHash": "9e755fcbee26e790",
|
|
269
|
+
"ts": "const opts = {\n archive: true,\n platform: editor.platform,\n build_server: \"https://build.my-company.com\",\n settings: [\"test.ini\", \"headless.ini\"],\n};\neditor.bob(opts, \"distclean\", \"resolve\", \"build\");"
|
|
162
270
|
}
|
|
163
271
|
],
|
|
164
272
|
"editor.command": [
|
|
165
273
|
{
|
|
166
274
|
"sourceHash": "41caebab7bdd6774",
|
|
167
|
-
"ts": "// Print Git history for a file:\neditor.command({\n label: \"Git History\",\n query: { selection: { type: \"resource\", cardinality: \"one\" } },\n run: (opts) => {\n editor.execute(\"git\", \"log\", \"--follow\", `.${editor.get(opts.selection, \"path\")}`, {\n reload_resources: false,\n });\n },\n});"
|
|
275
|
+
"ts": "// Print Git history for a file:\neditor.command({\n label: \"Git History\",\n locations: [\"Assets\"],\n query: { selection: { type: \"resource\", cardinality: \"one\" } },\n run: (opts) => {\n editor.execute(\"git\", \"log\", \"--follow\", `.${editor.get(opts.selection, \"path\")}`, {\n reload_resources: false,\n });\n },\n});"
|
|
168
276
|
}
|
|
169
277
|
],
|
|
170
278
|
"editor.create_directory": [
|
|
@@ -175,8 +283,16 @@
|
|
|
175
283
|
],
|
|
176
284
|
"editor.create_resources": [
|
|
177
285
|
{
|
|
178
|
-
"sourceHash": "
|
|
179
|
-
"ts": "
|
|
286
|
+
"sourceHash": "dd9b866b84f9de49",
|
|
287
|
+
"ts": "editor.create_resources([\"/npc.go\"]);"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"sourceHash": "86faf70ca56cf8a6",
|
|
291
|
+
"ts": "editor.create_resources([\"/npc.go\", \"/levels/1.collection\", \"/levels/2.collection\"]);"
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
"sourceHash": "f29c4cbd5eb7bb65",
|
|
295
|
+
"ts": "editor.create_resources([{ 1: \"/npc.script\", 2: \"go.property('hp', 100)\" }]);"
|
|
180
296
|
}
|
|
181
297
|
],
|
|
182
298
|
"editor.delete_directory": [
|
|
@@ -187,14 +303,18 @@
|
|
|
187
303
|
],
|
|
188
304
|
"editor.execute": [
|
|
189
305
|
{
|
|
190
|
-
"sourceHash": "
|
|
191
|
-
"ts": "
|
|
306
|
+
"sourceHash": "d5e0db47ebda0546",
|
|
307
|
+
"ts": "editor.execute(\"mkdir\", \"new dir\");"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"sourceHash": "5044e4584bab1ea9",
|
|
311
|
+
"ts": "const status = editor.execute(\"git\", \"status\", \"--porcelain\", {\n reload_resources: false,\n out: \"capture\",\n});"
|
|
192
312
|
}
|
|
193
313
|
],
|
|
194
314
|
"editor.ui.use_memo": [
|
|
195
315
|
{
|
|
196
316
|
"sourceHash": "dac97ede337c4f69",
|
|
197
|
-
"ts": "function increment(n: unknown): number {\n return (n as number) + 1;\n}\n\nfunction makeListener(setCount: unknown) {\n return () => {\n (setCount as (update: unknown) => unknown)(increment);\n };\n}\n\nconst counterButton = editor.ui.component((props) => {\n const [count, setCount] = editor.ui.use_state((props as { count: unknown }).count);\n const onPressed = editor.ui.use_memo(makeListener, setCount);\n return editor.ui.button({\n text: tostring(count),\n on_pressed: onPressed,\n });\n});"
|
|
317
|
+
"ts": "function increment(n: unknown): number {\n return (n as number) + 1;\n}\n\nfunction makeListener(setCount: unknown) {\n return () => {\n (setCount as (update: unknown) => unknown)(increment);\n };\n}\n\nconst counterButton = editor.ui.component((props) => {\n const [count, setCount] = editor.ui.use_state((props as { count: unknown }).count);\n const onPressed = editor.ui.use_memo(makeListener, setCount) as () => void;\n return editor.ui.button({\n text: tostring(count),\n on_pressed: onPressed,\n });\n});"
|
|
198
318
|
}
|
|
199
319
|
],
|
|
200
320
|
"editor.ui.use_state": [
|
|
@@ -205,8 +325,12 @@
|
|
|
205
325
|
],
|
|
206
326
|
"factory.create": [
|
|
207
327
|
{
|
|
208
|
-
"sourceHash": "
|
|
209
|
-
"ts": "
|
|
328
|
+
"sourceHash": "df32ef57d1e2366e",
|
|
329
|
+
"ts": "export default defineScript({\n init(self) {\n // create a new game object and provide property values\n const created = factory.create(\"#factory\", undefined, undefined, { my_value: 1 });\n // communicate with the object\n msg.post(created, \"hello\");\n },\n});"
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
"sourceHash": "981a4891837250a9",
|
|
333
|
+
"ts": "go.property(\"my_value\", 0);\n\nexport default defineScript({\n init(self) {\n // do something with self.my_value which is now one\n },\n});"
|
|
210
334
|
}
|
|
211
335
|
],
|
|
212
336
|
"factory.load": [
|
|
@@ -230,7 +354,7 @@
|
|
|
230
354
|
"final": [
|
|
231
355
|
{
|
|
232
356
|
"sourceHash": "ebc3cae218af001a",
|
|
233
|
-
"ts": "export default defineScript({\n final(self) {\n // report finalization\n msg.post(\"my_friend_instance\", \"im_dead\", { my_stats: self.some_value });\n },\n});"
|
|
357
|
+
"ts": "export default defineScript({\n init() {\n return { some_value: 0 };\n },\n\n final(self) {\n // report finalization\n msg.post(\"my_friend_instance\", \"im_dead\", { my_stats: self.some_value });\n },\n});"
|
|
234
358
|
}
|
|
235
359
|
],
|
|
236
360
|
"font.add_font": [
|
|
@@ -251,6 +375,12 @@
|
|
|
251
375
|
"ts": "const font_hash = hash(\"/assets/fonts/roboto.fontc\");\nconst ttf_hash = hash(\"/assets/fonts/Roboto/Roboto-Bold.ttf\");\nfont.remove_font(font_hash, ttf_hash);"
|
|
252
376
|
}
|
|
253
377
|
],
|
|
378
|
+
"font.set_style": [
|
|
379
|
+
{
|
|
380
|
+
"sourceHash": "ec2d9af51ad582c9",
|
|
381
|
+
"ts": "font.set_style(\"/fonts/ui.fontc\", \"link:hover\", \"<color=#66b3ff><outline color=#000000 size=1><shake amplitude=0.2>\");"
|
|
382
|
+
}
|
|
383
|
+
],
|
|
254
384
|
"go.animate": [
|
|
255
385
|
{
|
|
256
386
|
"sourceHash": "c4fc72e0b8812778",
|
|
@@ -297,8 +427,36 @@
|
|
|
297
427
|
],
|
|
298
428
|
"go.get": [
|
|
299
429
|
{
|
|
300
|
-
"sourceHash": "
|
|
301
|
-
"ts": "
|
|
430
|
+
"sourceHash": "bf6bc560db059a69",
|
|
431
|
+
"ts": "go.property(\"speed\", 50);"
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
"sourceHash": "6c13a2e33f4f0c98",
|
|
435
|
+
"ts": "const speed = go.get(\"#player\", \"speed\");"
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
"sourceHash": "decf402c4b246359",
|
|
439
|
+
"ts": "// the glsl indices are 0-based\nconst url = msg.url(\"#mesh\");\ngo.get(url, \"example\", { index: 1 }); // the first vector4 in the array: example[0]\ngo.get(url, \"example\", { index: 16 }); // the last vector4 in the array: example[15]\ngo.get(url, \"example.x\", { index: 1 }); // an element of a vector4: example[0].x"
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
"sourceHash": "cd59aaeb4278cdfc",
|
|
443
|
+
"ts": "const url = msg.url(\"#mesh\");\ngo.get(url, \"example\"); // => [vector4, vector4, ...]\ngo.get(url, \"example.x\"); // => [number1, number2, ...]"
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
"sourceHash": "4b5cae0c647b3381",
|
|
447
|
+
"ts": "// get the resource of a certain gui font\nconst font_hash = go.get(\"#gui\", \"fonts\", { key: \"system_font_BIG\" });"
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
"sourceHash": "ecf8c97d1bcaf7d3",
|
|
451
|
+
"ts": "// Addressing the first level of a component:\ngo.get(\"#particlefx\", \"material\", { keys: [\"cone_emitter\"] });"
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
"sourceHash": "df724fc6773a584b",
|
|
455
|
+
"ts": "// Note: no built-in component supports this yet, but a custom one could.\ngo.get(\"#my_component\", \"some_property\", { keys: [\"root\", \"child_node\"] });"
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
"sourceHash": "3ba93bc03f7948cc",
|
|
459
|
+
"ts": "const url = msg.url(\"#mesh\");\n// get all vector4's in the constant array\ngo.get(url, \"example\"); // => [vector4, vector4, ...]\n// get all elements of the vector4's from an array\ngo.get(url, \"example.x\"); // => [number1, number2, ...]"
|
|
302
460
|
}
|
|
303
461
|
],
|
|
304
462
|
"go.get_id": [
|
|
@@ -411,12 +569,48 @@
|
|
|
411
569
|
{
|
|
412
570
|
"sourceHash": "96e6079cda36fa54",
|
|
413
571
|
"ts": "// This example defines a property \"health\" in a script. The health is decreased\n// whenever someone sends a \"take_damage\" message to the script.\n\n// The payload of your own message id, declared once for the whole program\n// (usually in a .d.ts of its own).\ndeclare global {\n interface CustomMessages {\n take_damage: { damage: number };\n }\n}\n\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // `go.property(\"health\", 100)` registration from this field, and only this\n // field types the property onto `self`.\n properties: { health: 100 },\n\n init(self) {\n // prints 100 to the output\n print(self.health);\n },\n\n on_message(self, message_id, message) {\n if (isMessage(message_id, message, \"take_damage\")) {\n self.health = self.health - message.damage;\n print(`Ouch! My health is now: ${self.health}`);\n }\n },\n});"
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
"sourceHash": "94d9f68e3db7056c",
|
|
575
|
+
"ts": "// This example defines a property \"health\" in a script. The health is decreased\n// whenever someone sends a \"take_damage\" message to the script.\n\n// The payload of your own message id, declared once for the whole program\n// (usually in a .d.ts of its own).\ndeclare global {\n interface CustomMessages {\n take_damage: { damage: number };\n }\n}\n\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // `go.property(\"health\", 100)` registration from this field, and only this\n // field types the property onto `self`.\n properties: { health: 100 },\n\n init(self) {\n // prints 100 to the output\n print(self.health);\n },\n\n on_message(self, message_id, message) {\n if (isMessage(message_id, message, \"take_damage\")) {\n self.health = self.health - message.damage;\n print(`Ouch! My health is now: ${self.health}`);\n }\n },\n});"
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
"sourceHash": "a56e7919856fdf57",
|
|
579
|
+
"ts": "// Text properties can contain UTF-8 and newline characters:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registrations from this field, and only this field types them onto `self`.\n properties: { player_name: \"Player One\", dialogue: \"First line\\nSecond line\" },\n});"
|
|
414
580
|
}
|
|
415
581
|
],
|
|
416
582
|
"go.set": [
|
|
417
583
|
{
|
|
418
|
-
"sourceHash": "
|
|
419
|
-
"ts": "
|
|
584
|
+
"sourceHash": "bf6bc560db059a69",
|
|
585
|
+
"ts": "go.property(\"speed\", 50);"
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
"sourceHash": "dcb0970a052d80a0",
|
|
589
|
+
"ts": "go.set(\"#player\", \"speed\", 100);"
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
"sourceHash": "150af4281adacf42",
|
|
593
|
+
"ts": "// the glsl indices are 0-based\nconst url = msg.url(\"#mesh\");\ngo.set(url, \"example\", vmath.vector4(1, 1, 1, 1), { index: 1 }); // example[0] = v\ngo.set(url, \"example\", vmath.vector4(2, 2, 2, 2), { index: 16 }); // example[15] = v\ngo.set(url, \"example.x\", 7, { index: 1 }); // example[0].x = 7"
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
"sourceHash": "fb7b5aefbb9fad4b",
|
|
597
|
+
"ts": "// set the first two vector4's in the array\n// if the array has more than two elements in the array they will not be set\nconst url = msg.url(\"#mesh\");\ngo.set(url, \"example\", [vmath.vector4(1, 1, 1, 1), vmath.vector4(2, 2, 2, 2)]);"
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
"sourceHash": "ea5b1b6430458d24",
|
|
601
|
+
"ts": "go.property(\"big_font\", resource.font());\n\nfunction set_named_font(self: { big_font: Hash }) {\n go.set(\"#gui\", \"fonts\", self.big_font, { key: \"system_font_BIG\" });\n}"
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
"sourceHash": "bb73335ad4c5f1fe",
|
|
605
|
+
"ts": "go.property(\"my_material\", resource.material());\n\nfunction set_sub_component_material(self: { my_material: Hash }) {\n go.set(\"#particlefx\", \"material\", self.my_material, { keys: [\"cone_emitter\"] });\n}"
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
"sourceHash": "2a68fe57bedcd5c1",
|
|
609
|
+
"ts": "// Note: no built-in component supports this yet, but a custom one could.\nconst some_value = 1;\ngo.set(\"#my_component\", \"some_property\", some_value, { keys: [\"root\", \"child_node\"] });"
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
"sourceHash": "54eab9a4ddd280ac",
|
|
613
|
+
"ts": "go.property(\"big_font\", resource.font());\n\nfunction set_named_font(self: { big_font: Hash }) {\n go.set(\"#gui\", \"fonts\", self.big_font, { key: \"system_font_BIG\" });\n}"
|
|
420
614
|
}
|
|
421
615
|
],
|
|
422
616
|
"go.set_parent": [
|
|
@@ -511,8 +705,12 @@
|
|
|
511
705
|
],
|
|
512
706
|
"gui.cancel_animations": [
|
|
513
707
|
{
|
|
514
|
-
"sourceHash": "
|
|
515
|
-
"ts": "
|
|
708
|
+
"sourceHash": "4887f66e427b7c8e",
|
|
709
|
+
"ts": "const node = gui.get_node(\"my_node\");\n// animate to new position\nconst pos = vmath.vector3(100, 100, 0);\ngui.animate(node, \"position\", pos, gui.EASING_LINEAR, 2);\n// ...\n// cancel animation of the x component.\ngui.cancel_animations(node, \"position.x\");"
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
"sourceHash": "62239db9b4ffcfec",
|
|
713
|
+
"ts": "const node = gui.get_node(\"my_node\");\n// animate to new position and scale\ngui.animate(node, \"position\", vmath.vector3(100, 100, 0), gui.EASING_LINEAR, 5);\ngui.animate(node, \"scale\", vmath.vector3(0.5), gui.EASING_LINEAR, 5);\n// ...\n// cancel positioning and scaling at once\ngui.cancel_animations(node);"
|
|
516
714
|
}
|
|
517
715
|
],
|
|
518
716
|
"gui.cancel_flipbook": [
|
|
@@ -571,14 +769,22 @@
|
|
|
571
769
|
],
|
|
572
770
|
"gui.new_texture": [
|
|
573
771
|
{
|
|
574
|
-
"sourceHash": "
|
|
575
|
-
"ts": "
|
|
772
|
+
"sourceHash": "b649d09aecc014e4",
|
|
773
|
+
"ts": "export default defineGuiScript({\n init(self) {\n const w = 200;\n const h = 300;\n\n // A nice orange. String with the RGB values.\n const orange = String.fromCharCode(0xff, 0x80, 0x10);\n\n // Create the texture. Repeat the color string for each pixel.\n const [ok, reason] = gui.new_texture(\"orange_tx\", w, h, \"rgb\", orange.repeat(w * h));\n if (ok) {\n // Create a box node and apply the texture to it.\n const n = gui.new_box_node(vmath.vector3(200, 200, 0), vmath.vector3(w, h, 0));\n gui.set_texture(n, \"orange_tx\");\n } else {\n // Could not create texture for some reason...\n if (reason === gui.RESULT_TEXTURE_ALREADY_EXISTS) {\n // ...\n } else {\n // ...\n }\n }\n },\n});"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
"sourceHash": "3279c780ce37ad44",
|
|
777
|
+
"ts": "const size = 4;\nconst pos = vmath.vector3(200, 200, 0);\nconst path = \"/assets/images/logo_4x4.astc\";\nconst [data] = sys.load_resource(path);\nif (data !== undefined) {\n const n = gui.new_box_node(pos, vmath.vector3(size, size, 0));\n // size is read from the .astc buffer\n // flip is not supported\n gui.new_texture(path, 0, 0, \"astc\", data, false);\n gui.set_texture(n, path);\n}"
|
|
576
778
|
}
|
|
577
779
|
],
|
|
578
780
|
"gui.play_flipbook": [
|
|
579
781
|
{
|
|
580
|
-
"sourceHash": "
|
|
581
|
-
"ts": "
|
|
782
|
+
"sourceHash": "766767de34e4e6a2",
|
|
783
|
+
"ts": "function anim_callback(self: unknown, node: unknown) {\n // Take action after animation has played.\n}\n\nexport default defineGuiScript({\n init(self) {\n // Create a new node and set the texture to a flipbook animation\n const node = gui.get_node(\"button_node\");\n gui.set_texture(node, \"gui_sprites\");\n gui.play_flipbook(node, \"animated_button\");\n },\n});"
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
"sourceHash": "90aa26229f63af7e",
|
|
787
|
+
"ts": "// Create a new node and set the texture to a \"button.png\" from atlas\nconst node = gui.get_node(\"button_node\");\ngui.set_texture(node, \"gui_sprites\");\ngui.play_flipbook(node, \"button\");"
|
|
582
788
|
}
|
|
583
789
|
],
|
|
584
790
|
"gui.play_particlefx": [
|
|
@@ -596,17 +802,29 @@
|
|
|
596
802
|
"gui.screen_to_local": [
|
|
597
803
|
{
|
|
598
804
|
"sourceHash": "3e442324e48a7f04",
|
|
599
|
-
"ts": "// Animate a node to the pressed pointer position:\nexport default defineGuiScript({\n init() {\n msg.post(\".\", \"acquire_input_focus\");\n return { marker: gui.get_node(\"marker\") };\n },\n\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")
|
|
805
|
+
"ts": "// Animate a node to the pressed pointer position:\nexport default defineGuiScript({\n init() {\n msg.post(\".\", \"acquire_input_focus\");\n return { marker: gui.get_node(\"marker\") };\n },\n\n on_input(self, action_id, action) {\n if (\n action_id === hash(\"touch\") &&\n action.pressed &&\n action.screen_x !== undefined &&\n action.screen_y !== undefined\n ) {\n const screen_position = vmath.vector3(action.screen_x, action.screen_y, 0);\n const target_position = gui.screen_to_local(self.marker, screen_position);\n gui.animate(self.marker, gui.PROP_POSITION, target_position, gui.EASING_OUTQUAD, 0.2);\n return true;\n }\n },\n});"
|
|
600
806
|
}
|
|
601
807
|
],
|
|
602
808
|
"gui.set": [
|
|
603
809
|
{
|
|
604
|
-
"sourceHash": "
|
|
605
|
-
"ts": "
|
|
810
|
+
"sourceHash": "0b505e5f92fd4aff",
|
|
811
|
+
"ts": "const node = gui.get_node(\"my_box_node\");\nconst node_position = gui.get(node, \"position\") as Vector3;\ngui.set(node, \"position.x\", node_position.x + 128);"
|
|
606
812
|
},
|
|
607
813
|
{
|
|
608
|
-
"sourceHash": "
|
|
609
|
-
"ts": "
|
|
814
|
+
"sourceHash": "8ed6f5c059ba2496",
|
|
815
|
+
"ts": "const node = gui.get_node(\"my_box_node\");\ngui.set(node, \"rotation\", vmath.quat_rotation_z(math.rad(45)));\n// this is equivalent to:\ngui.set(node, \"euler.z\", 45);\n// or using the entire vector:\ngui.set(node, \"euler\", vmath.vector3(0, 0, 45));\n// or using the set_rotation\ngui.set_rotation(node, vmath.vector3(0, 0, 45));"
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
"sourceHash": "2a8317babd507565",
|
|
819
|
+
"ts": "const node = gui.get_node(\"my_box_node\");\ngui.set(node, \"tint\", vmath.vector4(1, 0, 0, 1));\n// matrix4 is also supported\ngui.set(node, \"light_matrix\", vmath.matrix4());\n// update a constant in an array at position 4. the array is specified in the shader as:\n// uniform vec4 tint_array[4]; // lua is 1 based, shader is 0 based\ngui.set(node, \"tint_array\", vmath.vector4(1, 0, 0, 1), { index: 4 });\n// update a matrix constant in an array at position 4. the array is specified in the shader as:\n// uniform mat4 light_matrix_array[4];\ngui.set(node, \"light_matrix_array\", vmath.matrix4(), { index: 4 });\n// update a sub-element in a constant\ngui.set(node, \"tint.x\", 1);\n// update a sub-element in an array constant at position 4\ngui.set(node, \"tint_array.x\", 1, { index: 4 });"
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
"sourceHash": "b52d73e25b02e93f",
|
|
823
|
+
"ts": "export default defineGuiScript({\n on_message(self, message_id, message) {\n if (message_id === hash(\"set_font\") && types.is_hash(message.font)) {\n gui.set(msg.url(), \"fonts\", message.font, { key: \"my_font_name\" });\n gui.set_font(gui.get_node(\"text\"), \"my_font_name\");\n } else if (message_id === hash(\"set_texture\") && types.is_hash(message.texture)) {\n gui.set(msg.url(), \"textures\", message.texture, { key: \"my_texture\" });\n gui.set_texture(gui.get_node(\"box\"), \"my_texture\");\n gui.play_flipbook(gui.get_node(\"box\"), \"logo_256\");\n }\n },\n});"
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
"sourceHash": "8e2e40668493072c",
|
|
827
|
+
"ts": "const atlas_params = {\n texture: \"/runtime.texturec\",\n animations: [{ id: \"runtime\", width: 1, height: 1, frames: [1] }],\n geometries: [{ vertices: [0, 0, 0, 1, 1, 1, 1, 0], uvs: [0, 0, 0, 1, 1, 1, 1, 0], indices: [0, 1, 2, 0, 2, 3] }],\n} satisfies Parameters<typeof resource.create_atlas>[1];\nconst atlas_id = resource.create_atlas(\"/runtime.texturesetc\", atlas_params);\ngui.set(msg.url(), \"textures\", atlas_id, { key: \"runtime_texture\" });\ngui.set_texture(gui.get_node(\"box\"), \"runtime_texture\");\n\n// Later, remove the GUI mapping before releasing the atlas resource.\ngui.set(msg.url(), \"textures\", undefined, { key: \"runtime_texture\" });\nresource.release(atlas_id);"
|
|
610
828
|
}
|
|
611
829
|
],
|
|
612
830
|
"gui.set_id": [
|
|
@@ -623,8 +841,12 @@
|
|
|
623
841
|
],
|
|
624
842
|
"gui.set_texture": [
|
|
625
843
|
{
|
|
626
|
-
"sourceHash": "
|
|
627
|
-
"ts": "
|
|
844
|
+
"sourceHash": "27917506578ef40c",
|
|
845
|
+
"ts": "const node = gui.get_node(\"box_node\");\ngui.set_texture(node, \"my_atlas\");\ngui.play_flipbook(node, \"image\");"
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
"sourceHash": "63abf329a2522305",
|
|
849
|
+
"ts": "const w = 200;\nconst h = 300;\n// A nice orange. String with the RGB values.\nconst orange = String.fromCharCode(0xff, 0x80, 0x10);\n// Create the texture. Repeat the color string for each pixel.\nconst [ok] = gui.new_texture(\"orange_tx\", w, h, \"rgb\", orange.repeat(w * h));\nif (ok) {\n const node = gui.get_node(\"box_node\");\n gui.set_texture(node, \"orange_tx\");\n}"
|
|
628
850
|
}
|
|
629
851
|
],
|
|
630
852
|
"gui.set_texture_data": [
|
|
@@ -636,7 +858,7 @@
|
|
|
636
858
|
"html5.run": [
|
|
637
859
|
{
|
|
638
860
|
"sourceHash": "03f87c9fc915512f",
|
|
639
|
-
"ts": "const res = html5.run(\"10 + 20\"); // returns the string \"30\"\nprint(res);\nconst res_num = tonumber(res); // convert to number\
|
|
861
|
+
"ts": "const res = html5.run(\"10 + 20\"); // returns the string \"30\"\nprint(res);\nconst res_num = tonumber(res); // convert to number\nif (res_num !== undefined) {\n print(res_num - 20); // prints 10\n}"
|
|
640
862
|
}
|
|
641
863
|
],
|
|
642
864
|
"html5.set_interaction_listener": [
|
|
@@ -648,25 +870,25 @@
|
|
|
648
870
|
"http.request": [
|
|
649
871
|
{
|
|
650
872
|
"sourceHash": "170c94c250c1ce49",
|
|
651
|
-
"ts": "function update_my_progress_bar(self: unknown, fraction: number) {\n // draw the progress bar at the given fraction\n}\n\n// Basic HTTP-GET request. The callback receives a table with the response\n// in the fields status, the response (the data) and headers (a table).\nexport default defineScript({\n init() {\n http.request(\n \"http://www.google.com\",\n \"GET\",\n (self, _id, response) => {\n if (response.bytes_total !== undefined) {\n update_my_progress_bar(self, response.bytes_received / response.bytes_total);\n } else {\n print(response.status);\n print(response.response);\n pprint(response.headers);\n }\n },\n undefined,\n undefined,\n { report_progress: true },\n );\n },\n});"
|
|
873
|
+
"ts": "function update_my_progress_bar(self: unknown, fraction: number) {\n // draw the progress bar at the given fraction\n}\n\n// Basic HTTP-GET request. The callback receives a table with the response\n// in the fields status, the response (the data) and headers (a table).\nexport default defineScript({\n init() {\n http.request(\n \"http://www.google.com\",\n \"GET\",\n (self, _id, response) => {\n if (response.bytes_received !== undefined && response.bytes_total !== undefined) {\n update_my_progress_bar(self, response.bytes_received / response.bytes_total);\n } else {\n print(response.status);\n print(response.response);\n pprint(response.headers);\n }\n },\n undefined,\n undefined,\n { report_progress: true },\n );\n },\n});"
|
|
652
874
|
}
|
|
653
875
|
],
|
|
654
876
|
"image.get_astc_header": [
|
|
655
877
|
{
|
|
656
878
|
"sourceHash": "adae89354a89050a",
|
|
657
|
-
"ts": "// How to get the block size and dimensions from a .astc file\nconst [s] = sys.load_resource(\"/assets/cat.astc\");\
|
|
879
|
+
"ts": "// How to get the block size and dimensions from a .astc file\nconst [s] = sys.load_resource(\"/assets/cat.astc\");\nif (s !== undefined) {\n const header = image.get_astc_header(s);\n pprint(s);\n}"
|
|
658
880
|
}
|
|
659
881
|
],
|
|
660
882
|
"image.load": [
|
|
661
883
|
{
|
|
662
884
|
"sourceHash": "d7c6b4708bd86c99",
|
|
663
|
-
"ts": "// How to load an image from an URL and create a GUI texture from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img = image.load(response.response);\n const tx = gui.new_texture(\"image_node\", img.width, img.height, img.type, img.buffer);\n});"
|
|
885
|
+
"ts": "// How to load an image from an URL and create a GUI texture from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img = response.response !== undefined ? image.load(response.response) : undefined;\n if (img !== undefined) {\n const tx = gui.new_texture(\"image_node\", img.width, img.height, img.type, img.buffer);\n }\n});"
|
|
664
886
|
}
|
|
665
887
|
],
|
|
666
888
|
"image.load_buffer": [
|
|
667
889
|
{
|
|
668
890
|
"sourceHash": "55649cadc660e25e",
|
|
669
|
-
"ts": "// Load an image from an URL as a buffer and create a texture resource from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img
|
|
891
|
+
"ts": "// Load an image from an URL as a buffer and create a texture resource from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img =\n response.response !== undefined\n ? image.load_buffer(response.response, { flip_vertically: true })\n : undefined;\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGBA;\n if (img !== undefined && format !== undefined) {\n const tparams = {\n width: img.width,\n height: img.height,\n type: graphics.TEXTURE_TYPE_2D,\n format,\n };\n\n const my_texture_id = resource.create_texture(\"/my_custom_texture.texturec\", tparams, img.buffer);\n // Apply the texture to a model\n go.set(\"/go1#model\", \"texture0\", my_texture_id);\n }\n});"
|
|
670
892
|
}
|
|
671
893
|
],
|
|
672
894
|
"init": [
|
|
@@ -677,26 +899,48 @@
|
|
|
677
899
|
],
|
|
678
900
|
"json.decode": [
|
|
679
901
|
{
|
|
680
|
-
"sourceHash": "
|
|
681
|
-
"ts": "
|
|
902
|
+
"sourceHash": "8dcdd6f81ef65528",
|
|
903
|
+
"ts": "export default defineScript({\n init() {\n const jsonstring = '{\"persons\":[{\"name\":\"John Doe\"},{\"name\":\"Darth Vader\"}]}';\n const data = json.decode(jsonstring);\n pprint(data);\n },\n});"
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
"sourceHash": "4cd6b13a31344b55",
|
|
907
|
+
"ts": "// {\n// persons = {\n// 1 = {\n// name = John Doe,\n// }\n// 2 = {\n// name = Darth Vader,\n// }\n// }\n// }"
|
|
682
908
|
}
|
|
683
909
|
],
|
|
684
910
|
"json.encode": [
|
|
685
911
|
{
|
|
686
|
-
"sourceHash": "
|
|
687
|
-
"ts": "
|
|
912
|
+
"sourceHash": "cd58784a46da5fcb",
|
|
913
|
+
"ts": "export default defineScript({\n init() {\n const tbl = {\n persons: [{ name: \"John Doe\" }, { name: \"Darth Vader\" }],\n };\n const jsonstring = json.encode(tbl);\n pprint(jsonstring);\n },\n});"
|
|
914
|
+
},
|
|
915
|
+
{
|
|
916
|
+
"sourceHash": "2bb4b4f7cdbb2f0f",
|
|
917
|
+
"ts": "// {\"persons\":[{\"name\":\"John Doe\"},{\"name\":\"Darth Vader\"}]}"
|
|
918
|
+
}
|
|
919
|
+
],
|
|
920
|
+
"label.get_layout_objects": [
|
|
921
|
+
{
|
|
922
|
+
"sourceHash": "cb0d030f627da4ea",
|
|
923
|
+
"ts": "const objects = label.get_layout_objects(\"#label\");\nfor (const object of objects) {\n if (object.type === \"link\") {\n print(object.attributes.get(\"src\"), object.text_offset, object.text_length);\n } else if (object.type === \"sprite\") {\n print(object.attributes.get(\"src\"), object.x, object.y, object.width, object.height);\n }\n}"
|
|
688
924
|
}
|
|
689
925
|
],
|
|
690
926
|
"label.get_text": [
|
|
691
927
|
{
|
|
692
928
|
"sourceHash": "f1c34d0aca8a07d9",
|
|
693
929
|
"ts": "export default defineScript({\n init(self) {\n const text = label.get_text(\"#label\");\n print(text);\n },\n});"
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
"sourceHash": "877de2c1daa19e58",
|
|
933
|
+
"ts": "export default defineScript({\n init() {\n const text = go.get<label.properties>()(\"#label\", \"text\");\n print(text);\n },\n});"
|
|
694
934
|
}
|
|
695
935
|
],
|
|
696
936
|
"label.set_text": [
|
|
697
937
|
{
|
|
698
938
|
"sourceHash": "0d47c9a209b0d646",
|
|
699
939
|
"ts": "export default defineScript({\n init(self) {\n label.set_text(\"#label\", \"Hello World!\");\n },\n});"
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
"sourceHash": "2ac0aeb70ccdc6bf",
|
|
943
|
+
"ts": "export default defineScript({\n init() {\n go.set<label.properties>()(\"#label\", \"text\", \"Hello World!\");\n },\n});"
|
|
700
944
|
}
|
|
701
945
|
],
|
|
702
946
|
"liveupdate.add_mount": [
|
|
@@ -711,12 +955,16 @@
|
|
|
711
955
|
],
|
|
712
956
|
"liveupdate.get_mounts": [
|
|
713
957
|
{
|
|
714
|
-
"sourceHash": "
|
|
715
|
-
"ts": "
|
|
958
|
+
"sourceHash": "5c7eede2122552e2",
|
|
959
|
+
"ts": "pprint(\"MOUNTS\", liveupdate.get_mounts());"
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
"sourceHash": "8f1c19f5a5d6e4b1",
|
|
963
|
+
"ts": "// DEBUG:SCRIPT: MOUNTS,\n// {\n// 1 = {\n// name = hash: [liveupdate],\n// uri = \"zip:/device/path/to/acchives/liveupdate.zip\",\n// priority = 5\n// },\n// 2 = {\n// name = hash: [_base],\n// uri = \"archive:build/default/game.dmanifest\",\n// priority = -10\n// }\n// }"
|
|
716
964
|
},
|
|
717
965
|
{
|
|
718
|
-
"sourceHash": "
|
|
719
|
-
"ts": "//
|
|
966
|
+
"sourceHash": "a93aeb64f6460957",
|
|
967
|
+
"ts": "// DEBUG:SCRIPT: MOUNTS,\n// {\n// 1 = {\n// name = \"liveupdate\",\n// uri = \"zip:/device/path/to/acchives/liveupdate.zip\",\n// priority = 5\n// },\n// 2 = {\n// name = \"_base\",\n// uri = \"archive:build/default/game.dmanifest\",\n// priority = -10\n// }\n// }"
|
|
720
968
|
}
|
|
721
969
|
],
|
|
722
970
|
"liveupdate.is_built_with_excluded_files": [
|
|
@@ -806,7 +1054,7 @@
|
|
|
806
1054
|
"model.get_mesh_enabled": [
|
|
807
1055
|
{
|
|
808
1056
|
"sourceHash": "b2f9e47a91bc3f12",
|
|
809
|
-
"ts": "// shared weapon data, e.g. required from your own module\nconst game = { data: { weapons: { Sword: { damage: 10 } } } };\n\nexport default defineScript({\n init(
|
|
1057
|
+
"ts": "// shared weapon data, e.g. required from your own module\nconst game = { data: { weapons: { Sword: { damage: 10 } } } };\n\nexport default defineScript({\n init() {\n if (model.get_mesh_enabled(\"#model\", \"Sword\")) {\n // set properties specific for the sword\n return { weapon_properties: game.data.weapons[\"Sword\"] };\n }\n return { weapon_properties: undefined };\n },\n});"
|
|
810
1058
|
}
|
|
811
1059
|
],
|
|
812
1060
|
"model.play_anim": [
|
|
@@ -835,8 +1083,12 @@
|
|
|
835
1083
|
],
|
|
836
1084
|
"msg.post": [
|
|
837
1085
|
{
|
|
838
|
-
"sourceHash": "
|
|
839
|
-
"ts": "
|
|
1086
|
+
"sourceHash": "3bb511425986efad",
|
|
1087
|
+
"ts": "msg.post(\"my_gameobject#my_sprite\", \"enable\");"
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
"sourceHash": "bb0ad09dd9648670",
|
|
1091
|
+
"ts": "const my_url = msg.url(\"my_gameobject#my_script\");\nconst params = { my_parameter: \"my_value\" };\nmsg.post(my_url, \"my_message\", params);"
|
|
840
1092
|
}
|
|
841
1093
|
],
|
|
842
1094
|
"msg.url": [
|
|
@@ -856,11 +1108,11 @@
|
|
|
856
1108
|
"on_input": [
|
|
857
1109
|
{
|
|
858
1110
|
"sourceHash": "86c70cf4ccb7381e",
|
|
859
|
-
"ts": "// This example demonstrates how a game object instance can be moved as a response to user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);\n }\n }\n },\n});"
|
|
1111
|
+
"ts": "// This example demonstrates how a game object instance can be moved as a response to user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3((action.value ?? 0) * self.max_speed, 0, 0);\n }\n }\n },\n});"
|
|
860
1112
|
},
|
|
861
1113
|
{
|
|
862
1114
|
"sourceHash": "cc835ea429adc693",
|
|
863
|
-
"ts": "export default defineGuiScript({\n on_input(self, action_id, action) {\n // check for input\n if (action_id === hash(\"my_action\")) {\n // take appropriate action\n self.my_value = action.value;\n }\n // consume input\n return true;\n },\n});"
|
|
1115
|
+
"ts": "export default defineGuiScript({\n init(): { my_value: number | undefined } {\n return { my_value: undefined };\n },\n\n on_input(self, action_id, action) {\n // check for input\n if (action_id === hash(\"my_action\")) {\n // take appropriate action\n self.my_value = action.value;\n }\n // consume input\n return true;\n },\n});"
|
|
864
1116
|
}
|
|
865
1117
|
],
|
|
866
1118
|
"on_message": [
|
|
@@ -870,17 +1122,17 @@
|
|
|
870
1122
|
},
|
|
871
1123
|
{
|
|
872
1124
|
"sourceHash": "9f37896589565629",
|
|
873
|
-
"ts": "// b.script — Script of instance \"b\":\nexport default defineScript({\n init() {\n // store the url of instance \"a\" for later use, by specifying undefined as socket we\n // automatically use our own socket\n return { a_url: msg.url(undefined, go.get_id(\"a\"), \"script\") };\n },\n\n on_message(self, message_id, message, sender) {\n // check message and sender\n if (message_id === hash(\"my_data\") && sender === self.a_url) {\n // use the data in some way\n self.important_value = message.important_value;\n }\n },\n});"
|
|
1125
|
+
"ts": "// b.script — Script of instance \"b\":\nexport default defineScript({\n init() {\n // store the url of instance \"a\" for later use, by specifying undefined as socket we\n // automatically use our own socket\n return { a_url: msg.url(undefined, go.get_id(\"a\"), \"script\"), important_value: 0 };\n },\n\n on_message(self, message_id, message, sender) {\n // check message and sender\n if (message_id === hash(\"my_data\") && sender === self.a_url && typeof message.important_value === \"number\") {\n // use the data in some way\n self.important_value = message.important_value;\n }\n },\n});"
|
|
874
1126
|
}
|
|
875
1127
|
],
|
|
876
1128
|
"on_reload": [
|
|
877
1129
|
{
|
|
878
1130
|
"sourceHash": "ba39c0b0d5170ccb",
|
|
879
|
-
"ts": "// This example demonstrates how to tweak the speed of a game object instance that is moved on user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved, this value is tweaked in the on_reload function below\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);\n }\n }\n },\n\n on_reload(self) {\n // edit this value and reload the script component\n self.max_speed = 100;\n },\n});"
|
|
1131
|
+
"ts": "// This example demonstrates how to tweak the speed of a game object instance that is moved on user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved, this value is tweaked in the on_reload function below\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3((action.value ?? 0) * self.max_speed, 0, 0);\n }\n }\n },\n\n on_reload(self) {\n // edit this value and reload the script component\n self.max_speed = 100;\n },\n});"
|
|
880
1132
|
},
|
|
881
1133
|
{
|
|
882
1134
|
"sourceHash": "e89fe0d0bd51ed98",
|
|
883
|
-
"ts": "export default defineGuiScript({\n on_reload(self) {\n // restore some color (or similar)\n gui.set_color(gui.get_node(\"my_node\"), self.my_original_color);\n },\n});"
|
|
1135
|
+
"ts": "export default defineGuiScript({\n init() {\n return { my_original_color: gui.get_color(gui.get_node(\"my_node\")) };\n },\n\n on_reload(self) {\n // restore some color (or similar)\n gui.set_color(gui.get_node(\"my_node\"), self.my_original_color);\n },\n});"
|
|
884
1136
|
}
|
|
885
1137
|
],
|
|
886
1138
|
"particlefx.play": [
|
|
@@ -910,19 +1162,37 @@
|
|
|
910
1162
|
"physics.get_gravity": [
|
|
911
1163
|
{
|
|
912
1164
|
"sourceHash": "b2b339f1ddd89a38",
|
|
913
|
-
"ts": "export default defineScript({\n init(self) {\n let gravity = physics.get_gravity();\n // Inverse gravity!\n gravity = -gravity;\n physics.set_gravity(gravity);\n },\n});"
|
|
1165
|
+
"ts": "export default defineScript({\n init(self) {\n let gravity = physics.get_gravity();\n // Inverse gravity!\n gravity = vmath.vector3(-gravity.x, -gravity.y, -gravity.z);\n physics.set_gravity(gravity);\n },\n});"
|
|
1166
|
+
}
|
|
1167
|
+
],
|
|
1168
|
+
"physics.get_group": [
|
|
1169
|
+
{
|
|
1170
|
+
"sourceHash": "c8144370669b125f",
|
|
1171
|
+
"ts": "function check_is_enemy(): boolean {\n const group = physics.get_group(\"#collisionobject\");\n return group === hash(\"enemy\");\n}"
|
|
1172
|
+
}
|
|
1173
|
+
],
|
|
1174
|
+
"physics.get_maskbit": [
|
|
1175
|
+
{
|
|
1176
|
+
"sourceHash": "8679181844a752a4",
|
|
1177
|
+
"ts": "function is_invincible(): boolean {\n // check if the collisionobject would collide with the \"bullet\" group\n const invincible = physics.get_maskbit(\"#collisionobject\", \"bullet\");\n return invincible;\n}"
|
|
1178
|
+
}
|
|
1179
|
+
],
|
|
1180
|
+
"physics.get_shape": [
|
|
1181
|
+
{
|
|
1182
|
+
"sourceHash": "82791cbb5f80661a",
|
|
1183
|
+
"ts": "function get_shape_meta() {\n const sphere = physics.get_shape(\"#collisionobject\", \"my_sphere_shape\");\n // returns a table with sphere.diameter\n return sphere;\n}"
|
|
914
1184
|
}
|
|
915
1185
|
],
|
|
916
1186
|
"physics.raycast": [
|
|
917
1187
|
{
|
|
918
1188
|
"sourceHash": "3e0c534d741f0120",
|
|
919
|
-
"ts": "function handle_result(hit: { fraction: number; position: Vector3; normal: Vector3; id: Hash; group: Hash; request_id: number }) {\n // act on the hit (see 'ray_cast_response')\n}\n\n// How to perform a ray cast synchronously:\nexport default defineScript({\n init(
|
|
1189
|
+
"ts": "function handle_result(hit: { fraction: number; position: Vector3; normal: Vector3; id: Hash; group: Hash; request_id: number }) {\n // act on the hit (see 'ray_cast_response')\n}\n\n// How to perform a ray cast synchronously:\nexport default defineScript({\n init() {\n return { groups: [hash(\"world\"), hash(\"enemy\")] };\n },\n\n update(self, dt) {\n // request ray cast\n const from = go.get_world_position();\n const to = vmath.vector3(from.x, from.y - 100, from.z);\n const results = physics.raycast(from, to, self.groups, { all: true });\n if (results !== undefined) {\n // with `all` set, the ray cast returns every hit as a list\n for (const result of Array.isArray(results) ? results : [results]) {\n handle_result(result);\n }\n }\n },\n});"
|
|
920
1190
|
}
|
|
921
1191
|
],
|
|
922
1192
|
"physics.raycast_async": [
|
|
923
1193
|
{
|
|
924
1194
|
"sourceHash": "746b7900ebaa1f10",
|
|
925
|
-
"ts": "// How to perform a ray cast asynchronously:\nexport default defineScript({\n init(
|
|
1195
|
+
"ts": "// How to perform a ray cast asynchronously:\nexport default defineScript({\n init() {\n return { my_groups: [hash(\"my_group1\"), hash(\"my_group2\")] };\n },\n\n update(self, dt) {\n // request ray cast\n const my_start = go.get_world_position();\n const my_end = vmath.vector3(my_start.x, my_start.y - 100, my_start.z);\n physics.raycast_async(my_start, my_end, self.my_groups);\n },\n\n on_message(self, message_id, message, sender) {\n // check for the response\n if (message_id === hash(\"ray_cast_response\")) {\n // act on the hit\n } else if (message_id === hash(\"ray_cast_missed\")) {\n // act on the miss\n }\n },\n});"
|
|
926
1196
|
}
|
|
927
1197
|
],
|
|
928
1198
|
"physics.set_event_listener": [
|
|
@@ -941,16 +1211,34 @@
|
|
|
941
1211
|
"ts": "export default defineScript({\n init(self) {\n // Set \"upside down\" gravity for this collection.\n physics.set_gravity(vmath.vector3(0, 10.0, 0));\n },\n});"
|
|
942
1212
|
}
|
|
943
1213
|
],
|
|
1214
|
+
"physics.set_group": [
|
|
1215
|
+
{
|
|
1216
|
+
"sourceHash": "c4125b51c18c0a63",
|
|
1217
|
+
"ts": "function change_collision_group() {\n physics.set_group(\"#collisionobject\", \"enemy\");\n}"
|
|
1218
|
+
}
|
|
1219
|
+
],
|
|
944
1220
|
"physics.set_hflip": [
|
|
945
1221
|
{
|
|
946
1222
|
"sourceHash": "71a627e46d2e651e",
|
|
947
|
-
"ts": "export default defineScript({\n init(
|
|
1223
|
+
"ts": "export default defineScript({\n init() {\n const fliph = true; // set on some condition\n physics.set_hflip(\"#collisionobject\", fliph);\n return { fliph };\n },\n});"
|
|
1224
|
+
}
|
|
1225
|
+
],
|
|
1226
|
+
"physics.set_maskbit": [
|
|
1227
|
+
{
|
|
1228
|
+
"sourceHash": "a4b238ed0887509f",
|
|
1229
|
+
"ts": "function make_invincible() {\n // no longer collide with the \"bullet\" group\n physics.set_maskbit(\"#collisionobject\", \"bullet\", false);\n}"
|
|
1230
|
+
}
|
|
1231
|
+
],
|
|
1232
|
+
"physics.set_shape": [
|
|
1233
|
+
{
|
|
1234
|
+
"sourceHash": "12a0293fcc2f7687",
|
|
1235
|
+
"ts": "function set_shape_data() {\n // set capsule shape data\n physics.set_shape(\"#collisionobject\", \"my_capsule_shape\", {\n type: physics.SHAPE_TYPE_CAPSULE,\n diameter: 10,\n height: 20,\n });\n\n // set sphere shape data\n physics.set_shape(\"#collisionobject\", \"my_sphere_shape\", {\n type: physics.SHAPE_TYPE_SPHERE,\n diameter: 10,\n });\n\n // set box shape data\n physics.set_shape(\"#collisionobject\", \"my_box_shape\", {\n type: physics.SHAPE_TYPE_BOX,\n dimensions: vmath.vector3(10, 10, 5),\n });\n}"
|
|
948
1236
|
}
|
|
949
1237
|
],
|
|
950
1238
|
"physics.set_vflip": [
|
|
951
1239
|
{
|
|
952
1240
|
"sourceHash": "7b5832955ec6635c",
|
|
953
|
-
"ts": "export default defineScript({\n init(
|
|
1241
|
+
"ts": "export default defineScript({\n init() {\n const flipv = true; // set on some condition\n physics.set_vflip(\"#collisionobject\", flipv);\n return { flipv };\n },\n});"
|
|
954
1242
|
}
|
|
955
1243
|
],
|
|
956
1244
|
"physics.update_mass": [
|
|
@@ -959,6 +1247,12 @@
|
|
|
959
1247
|
"ts": "physics.update_mass(\"#collisionobject\", 14);"
|
|
960
1248
|
}
|
|
961
1249
|
],
|
|
1250
|
+
"physics.wakeup": [
|
|
1251
|
+
{
|
|
1252
|
+
"sourceHash": "8bda507f7a5248c1",
|
|
1253
|
+
"ts": "export default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"test\") && action.pressed) {\n physics.wakeup(\"#collisionobject\");\n }\n },\n});"
|
|
1254
|
+
}
|
|
1255
|
+
],
|
|
962
1256
|
"profiler.dump_frame": [
|
|
963
1257
|
{
|
|
964
1258
|
"sourceHash": "54342e4fc710032d",
|
|
@@ -992,7 +1286,7 @@
|
|
|
992
1286
|
"profiler.recorded_frame_count": [
|
|
993
1287
|
{
|
|
994
1288
|
"sourceHash": "9d55df4a00c36560",
|
|
995
|
-
"ts": "// Show the last recorded frame\nconst recorded_frame_count = profiler.recorded_frame_count();\nprofiler.view_recorded_frame(recorded_frame_count);"
|
|
1289
|
+
"ts": "// Show the last recorded frame\nconst recorded_frame_count = profiler.recorded_frame_count();\nprofiler.view_recorded_frame({ frame: recorded_frame_count });"
|
|
996
1290
|
}
|
|
997
1291
|
],
|
|
998
1292
|
"profiler.scope_begin": [
|
|
@@ -1033,8 +1327,20 @@
|
|
|
1033
1327
|
],
|
|
1034
1328
|
"render.constant_buffer": [
|
|
1035
1329
|
{
|
|
1036
|
-
"sourceHash": "
|
|
1037
|
-
"ts": "
|
|
1330
|
+
"sourceHash": "16ded57baadade85",
|
|
1331
|
+
"ts": "const constants = render.constant_buffer();\nconstants.tint = vmath.vector4(1, 1, 1, 1);"
|
|
1332
|
+
},
|
|
1333
|
+
{
|
|
1334
|
+
"sourceHash": "d89056c8f1a576bb",
|
|
1335
|
+
"ts": "function draw_tinted(self: { my_pred: Opaque<\"render_predicate\"> }) {\n const constants = render.constant_buffer();\n constants.tint = vmath.vector4(1, 1, 1, 1);\n render.draw(self.my_pred, { constants });\n}"
|
|
1336
|
+
},
|
|
1337
|
+
{
|
|
1338
|
+
"sourceHash": "2c9cd28e1eb6e610",
|
|
1339
|
+
"ts": "const constants = render.constant_buffer();\nconstants.light_colors = [];\nconstants.light_colors[0] = vmath.vector4(1, 0, 0, 1);\nconstants.light_colors[1] = vmath.vector4(0, 1, 0, 1);\nconstants.light_colors[2] = vmath.vector4(0, 0, 1, 1);"
|
|
1340
|
+
},
|
|
1341
|
+
{
|
|
1342
|
+
"sourceHash": "d1c04a81200daf67",
|
|
1343
|
+
"ts": "const constants = render.constant_buffer();\nconstants.light_colors = [\n vmath.vector4(1, 0, 0, 1),\n vmath.vector4(0, 1, 0, 1),\n vmath.vector4(0, 0, 1, 1),\n];\n\n// Add more constants to the array\nconstants.light_colors[3] = vmath.vector4(1, 1, 1, 1);"
|
|
1038
1344
|
}
|
|
1039
1345
|
],
|
|
1040
1346
|
"render.delete_render_target": [
|
|
@@ -1058,19 +1364,35 @@
|
|
|
1058
1364
|
"render.disable_texture": [
|
|
1059
1365
|
{
|
|
1060
1366
|
"sourceHash": "77eefc5b608dd2e6",
|
|
1061
|
-
"ts": "export default defineRenderScript({\n update(self, dt) {\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n // done, disable the texture\n render.disable_texture(0);\n },\n});"
|
|
1367
|
+
"ts": "export default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n // done, disable the texture\n render.disable_texture(0);\n },\n});"
|
|
1062
1368
|
}
|
|
1063
1369
|
],
|
|
1064
1370
|
"render.dispatch_compute": [
|
|
1065
1371
|
{
|
|
1066
|
-
"sourceHash": "
|
|
1067
|
-
"ts": "export default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n scene_rt: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n };\n },\n\n update(self, dt) {\n render.set_compute(\"bloom\");\n render.enable_texture(0, self.backing_texture);\n render.enable_texture(1, self.scene_rt);\n render.dispatch_compute(128, 128, 1);\n render.set_compute();\n },\n})
|
|
1372
|
+
"sourceHash": "75d02543f0e1f325",
|
|
1373
|
+
"ts": "export default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n backing_texture: resource.get_texture_info(\"/main/backing.texturec\").handle,\n scene_rt: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n };\n },\n\n update(self, dt) {\n render.set_compute(\"bloom\");\n render.enable_texture(0, self.backing_texture);\n render.enable_texture(1, self.scene_rt);\n render.dispatch_compute(128, 128, 1);\n render.set_compute();\n },\n});"
|
|
1374
|
+
},
|
|
1375
|
+
{
|
|
1376
|
+
"sourceHash": "839cd1accd7a318c",
|
|
1377
|
+
"ts": "const constants = render.constant_buffer();\nconstants.tint = vmath.vector4(1, 1, 1, 1);\nrender.dispatch_compute(32, 32, 32, { constants });"
|
|
1068
1378
|
}
|
|
1069
1379
|
],
|
|
1070
1380
|
"render.draw": [
|
|
1071
1381
|
{
|
|
1072
|
-
"sourceHash": "
|
|
1073
|
-
"ts": "export default defineRenderScript({\n init() {\n // define a predicate matching anything with material tag \"my_tag\"\n return { my_pred: render.predicate([hash(\"my_tag\")]) };\n },\n\n update(self, dt) {\n // draw everything in the my_pred predicate\n render.draw(self.my_pred);\n
|
|
1382
|
+
"sourceHash": "5f241f4874a8bc1a",
|
|
1383
|
+
"ts": "export default defineRenderScript({\n init() {\n // define a predicate matching anything with material tag \"my_tag\"\n return { my_pred: render.predicate([hash(\"my_tag\")]) };\n },\n\n update(self, dt) {\n // draw everything in the my_pred predicate\n render.draw(self.my_pred);\n },\n});"
|
|
1384
|
+
},
|
|
1385
|
+
{
|
|
1386
|
+
"sourceHash": "50e774f222fef263",
|
|
1387
|
+
"ts": "function draw_tinted(self: { my_pred: Opaque<\"render_predicate\"> }) {\n const constants = render.constant_buffer();\n constants.tint = vmath.vector4(1, 1, 1, 1);\n render.draw(self.my_pred, { constants });\n}"
|
|
1388
|
+
},
|
|
1389
|
+
{
|
|
1390
|
+
"sourceHash": "19aaab03c8a4c8e7",
|
|
1391
|
+
"ts": "function draw_culled(self: { my_pred: Opaque<\"render_predicate\">; proj: Matrix4; view: Matrix4 }) {\n const frustum = self.proj.mul(self.view);\n render.draw(self.my_pred, { frustum });\n}"
|
|
1392
|
+
},
|
|
1393
|
+
{
|
|
1394
|
+
"sourceHash": "d1cbea5554766082",
|
|
1395
|
+
"ts": "function draw_culled(self: { my_pred: Opaque<\"render_predicate\">; proj: Matrix4; view: Matrix4 }) {\n const frustum = self.proj.mul(self.view);\n render.draw(self.my_pred, { frustum, frustum_planes: render.FRUSTUM_PLANES_ALL });\n}"
|
|
1074
1396
|
}
|
|
1075
1397
|
],
|
|
1076
1398
|
"render.draw_debug3d": [
|
|
@@ -1094,15 +1416,15 @@
|
|
|
1094
1416
|
"render.enable_texture": [
|
|
1095
1417
|
{
|
|
1096
1418
|
"sourceHash": "410c8dd98e44842a",
|
|
1097
|
-
"ts": "export default defineRenderScript({\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // disable target\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});"
|
|
1419
|
+
"ts": "export default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // disable target\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});"
|
|
1098
1420
|
},
|
|
1099
1421
|
{
|
|
1100
1422
|
"sourceHash": "dc0ea083dbea5fe1",
|
|
1101
|
-
"ts": "// Or enable a render target by resource id:\nexport default defineRenderScript({\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n render.draw(self.my_pred);\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, \"my_rt_resource\", graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});"
|
|
1423
|
+
"ts": "// Or enable a render target by resource id:\nexport default defineRenderScript({\n init() {\n return { my_pred: render.predicate([hash(\"my_tag\")]) };\n },\n\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n render.draw(self.my_pred);\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, \"my_rt_resource\", graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});"
|
|
1102
1424
|
},
|
|
1103
1425
|
{
|
|
1104
1426
|
"sourceHash": "49503c29f0de95f3",
|
|
1105
|
-
"ts": "// Or bind a texture handle directly:\nexport default defineRenderScript({\n update(self, dt) {\n // bind a texture to the texture unit 0\n render.enable_texture(0, self.my_texture_handle);\n // bind the same texture to a named sampler\n render.enable_texture(\"my_texture_sampler\", self.my_texture_handle);\n },\n});"
|
|
1427
|
+
"ts": "// Or bind a texture handle directly:\nexport default defineRenderScript({\n init() {\n return { my_texture_handle: resource.get_texture_info(\"/main/my_texture.texturec\").handle };\n },\n\n update(self, dt) {\n // bind a texture to the texture unit 0\n render.enable_texture(0, self.my_texture_handle);\n // bind the same texture to a named sampler\n render.enable_texture(\"my_texture_sampler\", self.my_texture_handle);\n },\n});"
|
|
1106
1428
|
}
|
|
1107
1429
|
],
|
|
1108
1430
|
"render.get_height": [
|
|
@@ -1150,15 +1472,23 @@
|
|
|
1150
1472
|
"render.render_target": [
|
|
1151
1473
|
{
|
|
1152
1474
|
"sourceHash": "0c72f5142a3a57da",
|
|
1153
|
-
"ts": "// How to create a new render target and draw to it:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const depth_params = {\n format: graphics.TEXTURE_FORMAT_DEPTH,\n width: render.get_window_width(),\n height: render.get_window_height(),\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params,\n [graphics.BUFFER_TYPE_DEPTH_BIT]: depth_params,\n }),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1475
|
+
"ts": "// How to create a new render target and draw to it:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const depth_params = {\n format: graphics.TEXTURE_FORMAT_DEPTH,\n width: render.get_window_width(),\n height: render.get_window_height(),\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params,\n [graphics.BUFFER_TYPE_DEPTH_BIT]: depth_params,\n }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1154
1476
|
},
|
|
1155
1477
|
{
|
|
1156
1478
|
"sourceHash": "271ca31f05e103b5",
|
|
1157
|
-
"ts": "// How to create a render target with multiple outputs:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [
|
|
1479
|
+
"ts": "// How to create a render target with multiple outputs:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // the engine registers the extra color attachments only when the driver supports them\n const color1 = graphics.BUFFER_TYPE_COLOR1_BIT;\n const color2 = graphics.BUFFER_TYPE_COLOR2_BIT;\n if (color1 === undefined || color2 === undefined) return undefined;\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [color1]: color_params_rgba,\n [color2]: color_params_float,\n }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n if (self === undefined) return;\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1158
1480
|
},
|
|
1159
1481
|
{
|
|
1160
1482
|
"sourceHash": "e39f13af5d65d01d",
|
|
1161
|
-
"ts": "// How to create a render target with multiple outputs:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR1_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR2_BIT]: color_params_float,\n }),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.
|
|
1483
|
+
"ts": "// How to create a render target with multiple outputs:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR1_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR2_BIT]: color_params_float,\n }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1484
|
+
},
|
|
1485
|
+
{
|
|
1486
|
+
"sourceHash": "582c319c90bcf7ad",
|
|
1487
|
+
"ts": "export default defineRenderScript({\n init() {\n if (graphics.BUFFER_TYPE_COLOR1_BIT === undefined) {\n // this devices does not support multiple color attachments\n }\n },\n});"
|
|
1488
|
+
},
|
|
1489
|
+
{
|
|
1490
|
+
"sourceHash": "eec69c97bf2815ed",
|
|
1491
|
+
"ts": "// How to create a new render target and draw to it:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const depth_params = {\n format: graphics.TEXTURE_FORMAT_DEPTH,\n width: render.get_window_width(),\n height: render.get_window_height(),\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n return {\n my_render_target: render.render_target({\n sample_count: 4,\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params,\n [graphics.BUFFER_TYPE_DEPTH_BIT]: depth_params,\n }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1162
1492
|
}
|
|
1163
1493
|
],
|
|
1164
1494
|
"render.set_blend_equation_separate": [
|
|
@@ -1181,8 +1511,12 @@
|
|
|
1181
1511
|
],
|
|
1182
1512
|
"render.set_camera": [
|
|
1183
1513
|
{
|
|
1184
|
-
"sourceHash": "
|
|
1185
|
-
"ts": "
|
|
1514
|
+
"sourceHash": "b107acc1597639c2",
|
|
1515
|
+
"ts": "function draw_through_camera(self: { my_pred: Opaque<\"render_predicate\"> }) {\n render.set_camera(\"main:/my_go#camera\");\n render.draw(self.my_pred);\n render.set_camera(undefined);\n}"
|
|
1516
|
+
},
|
|
1517
|
+
{
|
|
1518
|
+
"sourceHash": "4fc6efe0ea0a194d",
|
|
1519
|
+
"ts": "function draw_through_camera(self: { my_pred: Opaque<\"render_predicate\"> }) {\n // The camera frustum will take precedence over the frustum plane option in render.draw\n render.set_camera(\"main:/my_go#camera\", { use_frustum: true });\n // However, we can still customize the frustum planes regardless of the camera option!\n render.draw(self.my_pred, { frustum_planes: render.FRUSTUM_PLANES_ALL });\n render.set_camera();\n}"
|
|
1186
1520
|
}
|
|
1187
1521
|
],
|
|
1188
1522
|
"render.set_color_mask": [
|
|
@@ -1236,11 +1570,11 @@
|
|
|
1236
1570
|
"render.set_render_target": [
|
|
1237
1571
|
{
|
|
1238
1572
|
"sourceHash": "c6e25f5038d19bee",
|
|
1239
|
-
"ts": "// How to set a render target and draw to it and then switch back to the default render target\n// The render target defines the depth/stencil buffers as transient, when set_render_target is called the next time the buffers may be invalidated and allow for optimisations depending on driver support\nexport default defineRenderScript({\n update(self, dt) {\n // set render target so all drawing is done to it\n render.set_render_target(self.my_render_target, {\n transient: [graphics.BUFFER_TYPE_DEPTH_BIT, graphics.BUFFER_TYPE_STENCIL_BIT],\n });\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // set default render target. This also invalidates the depth and stencil buffers of the current target (self.my_render_target)\n // which can be an optimisation on some hardware\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});"
|
|
1573
|
+
"ts": "// How to set a render target and draw to it and then switch back to the default render target\n// The render target defines the depth/stencil buffers as transient, when set_render_target is called the next time the buffers may be invalidated and allow for optimisations depending on driver support\nexport default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // set render target so all drawing is done to it\n render.set_render_target(self.my_render_target, {\n transient: [graphics.BUFFER_TYPE_DEPTH_BIT, graphics.BUFFER_TYPE_STENCIL_BIT],\n });\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // set default render target. This also invalidates the depth and stencil buffers of the current target (self.my_render_target)\n // which can be an optimisation on some hardware\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});"
|
|
1240
1574
|
},
|
|
1241
1575
|
{
|
|
1242
1576
|
"sourceHash": "bb08db5e232c5b5e",
|
|
1243
|
-
"ts": "// Or set the render target by a render target resource identifier:\nexport default defineRenderScript({\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // reset the render target to the default backbuffer\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});"
|
|
1577
|
+
"ts": "// Or set the render target by a render target resource identifier:\nexport default defineRenderScript({\n init() {\n return { my_pred: render.predicate([hash(\"my_tag\")]) };\n },\n\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // reset the render target to the default backbuffer\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});"
|
|
1244
1578
|
}
|
|
1245
1579
|
],
|
|
1246
1580
|
"render.set_render_target_size": [
|
|
@@ -1270,7 +1604,7 @@
|
|
|
1270
1604
|
"render.set_view": [
|
|
1271
1605
|
{
|
|
1272
1606
|
"sourceHash": "7a30b4955abb3844",
|
|
1273
|
-
"ts": "// How to set the view and projection matrices according to\n// the values supplied by a camera.\nexport default defineRenderScript({\n init() {\n return {\n view: vmath.matrix4(),\n projection: vmath.matrix4(),\n };\n },\n\n update(self, dt) {\n // set the view to the stored view value\n render.set_view(self.view);\n // now we can draw with this view\n },\n\n on_message(self, message_id, message) {\n if (message_id === hash(\"set_view_projection\")) {\n // camera view and projection arrives here.\n self.view = message.view;\n self.projection = message.projection;\n }\n },\n});"
|
|
1607
|
+
"ts": "// How to set the view and projection matrices according to\n// the values supplied by a camera.\nexport default defineRenderScript({\n init() {\n return {\n view: vmath.matrix4(),\n projection: vmath.matrix4(),\n };\n },\n\n update(self, dt) {\n // set the view to the stored view value\n render.set_view(self.view);\n // now we can draw with this view\n },\n\n on_message(self, message_id, message) {\n if (\n message_id === hash(\"set_view_projection\") &&\n types.is_matrix4(message.view) &&\n types.is_matrix4(message.projection)\n ) {\n // camera view and projection arrives here.\n self.view = message.view;\n self.projection = message.projection;\n }\n },\n});"
|
|
1274
1608
|
}
|
|
1275
1609
|
],
|
|
1276
1610
|
"render.set_viewport": [
|
|
@@ -1282,29 +1616,29 @@
|
|
|
1282
1616
|
"resource.atlas": [
|
|
1283
1617
|
{
|
|
1284
1618
|
"sourceHash": "10e8e4948751ccc8",
|
|
1285
|
-
"ts": "// Load an atlas and set it to a sprite:\
|
|
1619
|
+
"ts": "// Load an atlas and set it to a sprite:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_atlas: resource.atlas(\"/atlas.atlas\") },\n\n init(self) {\n go.set(\"#sprite\", \"image\", self.my_atlas);\n },\n});"
|
|
1286
1620
|
},
|
|
1287
1621
|
{
|
|
1288
1622
|
"sourceHash": "46638db8e246e1ed",
|
|
1289
|
-
"ts": "// Load an atlas and set it to a gui:\
|
|
1623
|
+
"ts": "// Load an atlas and set it to a gui:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_atlas: resource.atlas(\"/atlas.atlas\") },\n\n init(self) {\n go.set(\"#gui\", \"textures\", self.my_atlas, { key: \"my_atlas\" });\n },\n});"
|
|
1290
1624
|
}
|
|
1291
1625
|
],
|
|
1292
1626
|
"resource.buffer": [
|
|
1293
1627
|
{
|
|
1294
1628
|
"sourceHash": "4353a4d474ea70b6",
|
|
1295
|
-
"ts": "// Set a unique buffer it to a sprite:\
|
|
1629
|
+
"ts": "// Set a unique buffer it to a sprite:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_buffer: resource.buffer(\"/cube.buffer\") },\n\n init(self) {\n go.set(\"#mesh\", \"vertices\", self.my_buffer);\n },\n});"
|
|
1296
1630
|
}
|
|
1297
1631
|
],
|
|
1298
1632
|
"resource.create_atlas": [
|
|
1299
1633
|
{
|
|
1300
1634
|
"sourceHash": "987cf3d09a4ce250",
|
|
1301
|
-
"ts": "// Create a backing texture and an atlas\nexport default defineScript({\n init() {\n // create an empty texture\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format
|
|
1635
|
+
"ts": "// Create a backing texture and an atlas\nexport default defineScript({\n init() {\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGBA;\n if (format === undefined) return;\n // create an empty texture\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format,\n };\n const my_texture_id = resource.create_texture(\"/my_texture.texturec\", tparams);\n\n // optionally use resource.set_texture to upload data to texture\n\n // create an atlas with one animation and one square geometry\n // note that the function doesn't support hashes for the texture,\n // you need to use a string for the texture path here aswell\n const aparams = {\n texture: \"/my_texture.texturec\",\n animations: [\n {\n id: \"my_animation\",\n width: 128,\n height: 128,\n frames: [1],\n },\n ],\n geometries: [\n {\n id: \"idle0\",\n width: 128,\n height: 128,\n pivot_x: 0.5,\n pivot_y: 0.5,\n vertices: [0, 0, 0, 128, 128, 128, 128, 0],\n uvs: [0, 0, 0, 128, 128, 128, 128, 0],\n indices: [0, 1, 2, 0, 2, 3],\n },\n ],\n } satisfies Parameters<typeof resource.create_atlas>[1];\n const my_atlas_id = resource.create_atlas(\"/my_atlas.texturesetc\", aparams);\n\n // assign the atlas to the 'sprite' component on the same go\n go.set(\"#sprite\", \"image\", my_atlas_id);\n },\n});"
|
|
1302
1636
|
}
|
|
1303
1637
|
],
|
|
1304
1638
|
"resource.create_buffer": [
|
|
1305
1639
|
{
|
|
1306
1640
|
"sourceHash": "a4804ebe744d930a",
|
|
1307
|
-
"ts": "// Create a buffer object and bind it to a buffer resource\nexport default defineScript({\n init() {\n const size = 1;\n const positions = [\n // triangle 1\n size, size, 0,\n -size, -size, 0,\n size, -size, 0,\n // triangle 2\n size, size, 0,\n -size, size, 0,\n -size, -size, 0,\n ];\n\n const buffer_handle = buffer.create(positions.length, [\n {\n name: hash(\"position\"),\n type: buffer.VALUE_TYPE_FLOAT32,\n count: 3,\n },\n ]);\n\n const stream = buffer.get_stream(buffer_handle, hash(\"position\"));\n\n // transfer vertex data to buffer\n
|
|
1641
|
+
"ts": "// Create a buffer object and bind it to a buffer resource\nexport default defineScript({\n init() {\n const size = 1;\n const positions = [\n // triangle 1\n size, size, 0,\n -size, -size, 0,\n size, -size, 0,\n // triangle 2\n size, size, 0,\n -size, size, 0,\n -size, -size, 0,\n ];\n\n const buffer_handle = buffer.create(positions.length, [\n {\n name: hash(\"position\"),\n type: buffer.VALUE_TYPE_FLOAT32,\n count: 3,\n },\n ]);\n\n const stream = buffer.get_stream(buffer_handle, hash(\"position\"));\n\n // transfer vertex data to buffer\n positions.forEach((value, k) => {\n stream[k] = value;\n });\n\n const my_buffer = resource.create_buffer(\"/my_buffer.bufferc\", { buffer: buffer_handle });\n go.set(\"/go#mesh\", \"vertices\", my_buffer);\n },\n});"
|
|
1308
1642
|
},
|
|
1309
1643
|
{
|
|
1310
1644
|
"sourceHash": "eef45bf7aae2047d",
|
|
@@ -1314,29 +1648,45 @@
|
|
|
1314
1648
|
"resource.create_sound_data": [
|
|
1315
1649
|
{
|
|
1316
1650
|
"sourceHash": "19e6f6ab7a317fa1",
|
|
1317
|
-
"ts": "export default defineScript({\n init() {\n // create a new sound resource, given the initial chunk of the file\n const relative_path = \"/a/unique/resource/name.oggc\";\n const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });\n go.set(\"#music\", \"sound\", hash); // override the previous sound resource\n sound.play(\"#music\"); // start the playing\n },\n});"
|
|
1651
|
+
"ts": "export default defineScript({\n init() {\n // create a new sound resource, given the initial chunk of the file\n const [data] = sys.load_resource(\"/sounds/music_header.oggc\");\n if (data === undefined) {\n return;\n }\n const filesize = 1048576;\n const relative_path = \"/a/unique/resource/name.oggc\";\n const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });\n go.set(\"#music\", \"sound\", hash); // override the previous sound resource\n sound.play(\"#music\"); // start the playing\n },\n});"
|
|
1318
1652
|
}
|
|
1319
1653
|
],
|
|
1320
1654
|
"resource.create_texture": [
|
|
1321
1655
|
{
|
|
1322
1656
|
"sourceHash": "717b1b10958e5fa2",
|
|
1323
|
-
"ts": "// How to create an 128x128 RGBA texture resource and assign it to a model\nexport default defineScript({\n init() {\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format
|
|
1657
|
+
"ts": "// How to create an 128x128 RGBA texture resource and assign it to a model\nexport default defineScript({\n init() {\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGBA;\n if (format === undefined) return;\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format,\n };\n const my_texture_id = resource.create_texture(\"/my_custom_texture.texturec\", tparams);\n go.set(\"#model\", \"texture0\", my_texture_id);\n },\n});"
|
|
1324
1658
|
},
|
|
1325
1659
|
{
|
|
1326
1660
|
"sourceHash": "71bd6ae180eb83d6",
|
|
1327
|
-
"ts": "// How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object\nexport default defineScript({\n init() {\n // Create a new buffer with 4 components and FLOAT32 type\n const tbuffer = buffer.create(128 * 128, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // Fill the buffer stream with some float values\n for (let y = 0; y < 128; y++) {\n for (let x = 0; x < 128; x++) {\n const index = y * 128 * 4 + x * 4;\n tstream[index + 0] = 999.0;\n tstream[index + 1] = -1.0;\n tstream[index + 2] = 0.5;\n tstream[index + 3] = 1.0;\n }\n }\n\n // Create a 2D Texture with a RGBA23F format\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format
|
|
1661
|
+
"ts": "// How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object\nexport default defineScript({\n init() {\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGBA32F;\n if (format === undefined) return;\n // Create a new buffer with 4 components and FLOAT32 type\n const tbuffer = buffer.create(128 * 128, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // Fill the buffer stream with some float values\n for (let y = 0; y < 128; y++) {\n for (let x = 0; x < 128; x++) {\n const index = y * 128 * 4 + x * 4;\n tstream[index + 0] = 999.0;\n tstream[index + 1] = -1.0;\n tstream[index + 2] = 0.5;\n tstream[index + 3] = 1.0;\n }\n }\n\n // Create a 2D Texture with a RGBA23F format\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format,\n };\n\n // Note that we pass the buffer as the last argument here!\n const my_texture_id = resource.create_texture(\"/my_custom_texture.texturec\", tparams, tbuffer);\n\n // assign the texture to a model\n go.set(\"#model\", \"texture0\", my_texture_id);\n },\n});"
|
|
1328
1662
|
},
|
|
1329
1663
|
{
|
|
1330
1664
|
"sourceHash": "be4f6e903c862a52",
|
|
1331
|
-
"ts": "// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type
|
|
1665
|
+
"ts": "// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n // the engine registers a texture type or format only when the driver supports it\n const type = graphics.TEXTURE_TYPE_IMAGE_3D;\n const format = graphics.TEXTURE_FORMAT_RGBA32F;\n if (type === undefined || format === undefined) return;\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type,\n width: 32,\n height: 32,\n depth: 32,\n format,\n flags: graphics.TEXTURE_USAGE_FLAG_STORAGE + graphics.TEXTURE_USAGE_FLAG_SAMPLE,\n });\n\n // pass the backing texture to the render script\n msg.post(\"@render:\", \"add_textures\", [t_volume]);\n },\n});"
|
|
1332
1666
|
},
|
|
1333
1667
|
{
|
|
1334
1668
|
"sourceHash": "b1535ccf9e09d259",
|
|
1335
|
-
"ts": "// How to create 512x512 texture array with 5 pages.\nconst new_tex = resource.create_texture(\"/runtime/example_array.texturec\", {\n
|
|
1669
|
+
"ts": "// How to create 512x512 texture array with 5 pages.\n// the engine registers a texture format only when the driver supports it\nconst format = graphics.TEXTURE_FORMAT_RGB;\nif (format !== undefined) {\n const new_tex = resource.create_texture(\"/runtime/example_array.texturec\", {\n type: graphics.TEXTURE_TYPE_2D_ARRAY,\n width: 512,\n height: 512,\n page_count: 5,\n format,\n });\n}"
|
|
1336
1670
|
},
|
|
1337
1671
|
{
|
|
1338
1672
|
"sourceHash": "54a85cf9f38f2521",
|
|
1339
|
-
"ts": "// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 32,\n height: 32,\n depth: 32,\n format:
|
|
1673
|
+
"ts": "// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 32,\n height: 32,\n depth: 32,\n format: graphics.TEXTURE_FORMAT_RGBA32F,\n flags: graphics.TEXTURE_USAGE_FLAG_STORAGE + graphics.TEXTURE_USAGE_FLAG_SAMPLE,\n });\n\n // pass the backing texture to the render script\n msg.post(\"@render:\", \"add_textures\", [t_volume]);\n },\n});"
|
|
1674
|
+
},
|
|
1675
|
+
{
|
|
1676
|
+
"sourceHash": "805bde1e64372a97",
|
|
1677
|
+
"ts": "if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {\n // it is safe to use this format\n}"
|
|
1678
|
+
},
|
|
1679
|
+
{
|
|
1680
|
+
"sourceHash": "51b59b3d6e594c38",
|
|
1681
|
+
"ts": "if (graphics.TEXTURE_TYPE_3D !== undefined) {\n // Device and graphics adapter support 3D textures\n}"
|
|
1682
|
+
},
|
|
1683
|
+
{
|
|
1684
|
+
"sourceHash": "99a0f19709b55611",
|
|
1685
|
+
"ts": "if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {\n // It is safe to use this format.\n}"
|
|
1686
|
+
},
|
|
1687
|
+
{
|
|
1688
|
+
"sourceHash": "a2e9eeb06d748575",
|
|
1689
|
+
"ts": "if (graphics.TEXTURE_TYPE_3D !== undefined) {\n // The device and graphics adapter support 3D textures.\n}"
|
|
1340
1690
|
}
|
|
1341
1691
|
],
|
|
1342
1692
|
"resource.create_texture_async": [
|
|
@@ -1346,23 +1696,44 @@
|
|
|
1346
1696
|
},
|
|
1347
1697
|
{
|
|
1348
1698
|
"sourceHash": "921632059c7abb58",
|
|
1349
|
-
"ts": "// Create a texture resource asyncronously without
|
|
1699
|
+
"ts": "// Create a texture resource asyncronously without handling its completion\nexport default defineScript({\n init() {\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGBA;\n if (format === undefined) return;\n // Create a texture resource async\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format,\n };\n\n // Create a new buffer with 4 components\n const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // Fill the buffer stream with some float values\n for (let y = 0; y < tparams.width; y++) {\n for (let x = 0; x < tparams.height; x++) {\n const index = y * 128 * 4 + x * 4;\n tstream[index + 0] = 255;\n tstream[index + 1] = 0;\n tstream[index + 2] = 255;\n tstream[index + 3] = 255;\n }\n }\n // create the texture\n // the binding requires a callback function, so pass one that does nothing\n const [tpath, request_id] = resource.create_texture_async(\"/my_texture.texturec\", tparams, tbuffer, () => {});\n // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture\n // that will be removed once the new texture has been updated\n go.set(\"#model\", \"texture0\", tpath);\n },\n});",
|
|
1700
|
+
"prose": "Create a texture resource asynchronously with a callback that does nothing"
|
|
1701
|
+
},
|
|
1702
|
+
{
|
|
1703
|
+
"sourceHash": "805bde1e64372a97",
|
|
1704
|
+
"ts": "if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {\n // it is safe to use this format\n}"
|
|
1705
|
+
},
|
|
1706
|
+
{
|
|
1707
|
+
"sourceHash": "51b59b3d6e594c38",
|
|
1708
|
+
"ts": "if (graphics.TEXTURE_TYPE_3D !== undefined) {\n // Device and graphics adapter support 3D textures\n}"
|
|
1709
|
+
},
|
|
1710
|
+
{
|
|
1711
|
+
"sourceHash": "99a0f19709b55611",
|
|
1712
|
+
"ts": "if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {\n // It is safe to use this format.\n}"
|
|
1713
|
+
},
|
|
1714
|
+
{
|
|
1715
|
+
"sourceHash": "a2e9eeb06d748575",
|
|
1716
|
+
"ts": "if (graphics.TEXTURE_TYPE_3D !== undefined) {\n // The device and graphics adapter support 3D textures.\n}"
|
|
1717
|
+
},
|
|
1718
|
+
{
|
|
1719
|
+
"sourceHash": "66e3c1c627270938",
|
|
1720
|
+
"ts": "// Create a texture resource asyncronously with a buffer and a callback\nfunction callback(self: unknown, request_id: number, result: resource.texture_creation_result) {\n // The resource has been updated with a new texture,\n // so we can update other systems with the new handle,\n // or update components to use the resource if we want\n const tinfo = resource.get_texture_info(result.path);\n msg.post(\"@render:\", \"set_backing_texture\", { handle: tinfo.handle });\n}\n\nexport default defineScript({\n init() {\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGBA;\n if (format === undefined) return;\n // Create a texture resource async\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format,\n };\n\n // Create a new buffer with 4 components\n const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // Fill the buffer stream with some float values\n for (let y = 0; y < tparams.width; y++) {\n for (let x = 0; x < tparams.height; x++) {\n const index = y * 128 * 4 + x * 4;\n tstream[index + 0] = 255;\n tstream[index + 1] = 0;\n tstream[index + 2] = 255;\n tstream[index + 3] = 255;\n }\n }\n // create the texture\n const [tpath, request_id] = resource.create_texture_async(\"/my_texture.texturec\", tparams, tbuffer, callback);\n // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture\n // that will be removed once the new texture has been updated\n go.set(\"#model\", \"texture0\", tpath);\n },\n});"
|
|
1350
1721
|
}
|
|
1351
1722
|
],
|
|
1352
1723
|
"resource.font": [
|
|
1353
1724
|
{
|
|
1354
1725
|
"sourceHash": "3e41babc3620a985",
|
|
1355
|
-
"ts": "// Load a font and set it to a label:\
|
|
1726
|
+
"ts": "// Load a font and set it to a label:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_font: resource.font(\"/font.font\") },\n\n init(self) {\n go.set(\"#label\", \"font\", self.my_font);\n },\n});"
|
|
1356
1727
|
},
|
|
1357
1728
|
{
|
|
1358
1729
|
"sourceHash": "8eb5018038b320d3",
|
|
1359
|
-
"ts": "// Load a font and set it to a gui:\
|
|
1730
|
+
"ts": "// Load a font and set it to a gui:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_font: resource.font(\"/font.font\") },\n\n init(self) {\n go.set(\"#gui\", \"fonts\", self.my_font, { key: \"my_font\" });\n },\n});"
|
|
1360
1731
|
}
|
|
1361
1732
|
],
|
|
1362
1733
|
"resource.get_buffer": [
|
|
1363
1734
|
{
|
|
1364
1735
|
"sourceHash": "ed7d361c7f5d2e35",
|
|
1365
|
-
"ts": "// How to get the data from a buffer\nexport default defineScript({\n init() {\n const res_path = go.get(\"#mesh\", \"vertices\");\n const buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n for (let i = 0; i < stream_positions.length; i++) {\n print(i, stream_positions[i]);\n }\n },\n});"
|
|
1736
|
+
"ts": "// How to get the data from a buffer\nexport default defineScript({\n init() {\n const res_path = go.get<mesh.properties>()(\"#mesh\", \"vertices\");\n const buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n for (let i = 0; i < stream_positions.length(); i++) {\n print(i, stream_positions[i]);\n }\n },\n});"
|
|
1366
1737
|
}
|
|
1367
1738
|
],
|
|
1368
1739
|
"resource.get_render_target_info": [
|
|
@@ -1378,13 +1749,13 @@
|
|
|
1378
1749
|
"resource.get_text_metrics": [
|
|
1379
1750
|
{
|
|
1380
1751
|
"sourceHash": "d63156dd59513358",
|
|
1381
|
-
"ts": "export default defineScript({\n init() {\n const font = go.get(\"#label\", \"font\");\n const metrics = resource.get_text_metrics(font, \"The quick brown fox\\n jumps over the lazy dog\");\n pprint(metrics);\n },\n});"
|
|
1752
|
+
"ts": "export default defineScript({\n init() {\n const font = go.get<label.properties>()(\"#label\", \"font\");\n const metrics = resource.get_text_metrics(font, \"The quick brown fox\\n jumps over the lazy dog\");\n pprint(metrics);\n },\n});"
|
|
1382
1753
|
}
|
|
1383
1754
|
],
|
|
1384
1755
|
"resource.get_texture_info": [
|
|
1385
1756
|
{
|
|
1386
1757
|
"sourceHash": "2d4a0b27a192425a",
|
|
1387
|
-
"ts": "// Create a new texture and get the metadata from it\nexport default defineScript({\n init() {\n // create an empty texture\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format
|
|
1758
|
+
"ts": "// Create a new texture and get the metadata from it\nexport default defineScript({\n init() {\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGBA;\n if (format === undefined) return;\n // create an empty texture\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format,\n };\n\n const my_texture_path = resource.create_texture(\"/my_texture.texturec\", tparams);\n const my_texture_info = resource.get_texture_info(my_texture_path);\n\n // my_texture_info now contains\n // {\n // handle = <the-numeric-handle>,\n // width = 128,\n // height = 128,\n // depth = 1\n // mipmaps = 1,\n // page_count = 1,\n // type = graphics.TEXTURE_TYPE_2D,\n // flags = graphics.TEXTURE_USAGE_FLAG_SAMPLE\n // }\n },\n});"
|
|
1388
1759
|
},
|
|
1389
1760
|
{
|
|
1390
1761
|
"sourceHash": "4fed93d6cd7f9380",
|
|
@@ -1393,84 +1764,108 @@
|
|
|
1393
1764
|
],
|
|
1394
1765
|
"resource.load": [
|
|
1395
1766
|
{
|
|
1396
|
-
"sourceHash": "
|
|
1397
|
-
"ts": "// read custom resource data into buffer\nconst buffer = resource.load(\"/resources/datafile\")
|
|
1767
|
+
"sourceHash": "dfc400954f81d242",
|
|
1768
|
+
"ts": "// read custom resource data into buffer\nconst buffer = resource.load(\"/resources/datafile\");"
|
|
1769
|
+
},
|
|
1770
|
+
{
|
|
1771
|
+
"sourceHash": "f02ab4b1fbd6e499",
|
|
1772
|
+
"ts": "// [project]\n// title = My project\n// version = 0.1\n// custom_resources = resources/,assets/level_data.json"
|
|
1398
1773
|
}
|
|
1399
1774
|
],
|
|
1400
1775
|
"resource.material": [
|
|
1401
1776
|
{
|
|
1402
1777
|
"sourceHash": "444ac3e37fe7401e",
|
|
1403
|
-
"ts": "// Load a material and set it to a sprite:\
|
|
1778
|
+
"ts": "// Load a material and set it to a sprite:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_material: resource.material(\"/material.material\") },\n\n init(self) {\n go.set(\"#sprite\", \"material\", self.my_material);\n },\n});"
|
|
1404
1779
|
},
|
|
1405
1780
|
{
|
|
1406
1781
|
"sourceHash": "7de09b2a13f4e657",
|
|
1407
|
-
"ts": "// Load a material resource and update a named material with the resource:\
|
|
1782
|
+
"ts": "// Load a material resource and update a named material with the resource:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_material: resource.material(\"/material.material\") },\n\n init(self) {\n go.set(\"#gui\", \"materials\", self.my_material, { key: \"my_material\" });\n },\n});"
|
|
1408
1783
|
}
|
|
1409
1784
|
],
|
|
1410
1785
|
"resource.render_target": [
|
|
1411
1786
|
{
|
|
1412
1787
|
"sourceHash": "87231742204d2351",
|
|
1413
|
-
"ts": "// Set a render target color attachment as a model texture:\
|
|
1788
|
+
"ts": "// Set a render target color attachment as a model texture:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_render_target: resource.render_target(\"/rt.render_target\") },\n\n init(self) {\n const rt_info = resource.get_render_target_info(self.my_render_target);\n go.set(\"#model\", \"texture0\", rt_info.attachments[0]!.texture!);\n },\n});"
|
|
1414
1789
|
}
|
|
1415
1790
|
],
|
|
1416
1791
|
"resource.set": [
|
|
1417
1792
|
{
|
|
1418
1793
|
"sourceHash": "fd3445f93ecdd85e",
|
|
1419
|
-
"ts": "// Assuming the folder \"/res\" is added to the project custom resources:\n// load a texture resource and set it on a sprite\nconst buffer = resource.load(\"/res/new.texturec\");\nresource.set(go.get(\"#sprite\", \"texture0\"), buffer);"
|
|
1794
|
+
"ts": "// Assuming the folder \"/res\" is added to the project custom resources:\n// load a texture resource and set it on a sprite\nconst buffer = resource.load(\"/res/new.texturec\");\nresource.set(go.get<sprite.properties>()(\"#sprite\", \"texture0\"), buffer);"
|
|
1420
1795
|
}
|
|
1421
1796
|
],
|
|
1422
1797
|
"resource.set_atlas": [
|
|
1423
1798
|
{
|
|
1424
1799
|
"sourceHash": "58ec7c40c31875a4",
|
|
1425
|
-
"ts": "// Add a new animation to an existing atlas\nexport default defineScript({\n init() {\n const data = resource.get_atlas(\"/main/my_atlas.a.texturesetc\");\n const my_animation = {\n id: \"my_new_animation\",\n width: 128,\n height: 128,\n frame_start: 1,\n frame_end: 6,\n playback: go.PLAYBACK_LOOP_PINGPONG,\n fps: 8,\n };\n data.animations.
|
|
1800
|
+
"ts": "// Add a new animation to an existing atlas\nexport default defineScript({\n init() {\n const data = resource.get_atlas(\"/main/my_atlas.a.texturesetc\");\n const my_animation = {\n id: \"my_new_animation\",\n width: 128,\n height: 128,\n frame_start: 1,\n frame_end: 6,\n playback: go.PLAYBACK_LOOP_PINGPONG,\n fps: 8,\n flip_vertical: false,\n flip_horizontal: false,\n };\n // set_atlas takes each animation's frames as a non-empty list\n const animations = data.animations.flatMap((animation) => {\n // an animation described by frame_start/frame_end passes through as-is\n if (!(\"frames\" in animation)) return [animation];\n const [first, ...rest] = (animation.frames as number[] | undefined) ?? [];\n return first === undefined ? [] : [{ ...animation, frames: [first, ...rest] as [number, ...number[]] }];\n });\n // set_atlas needs at least one animation and one geometry\n const [first_geometry, ...geometries] = data.geometries;\n if (first_geometry !== undefined) {\n resource.set_atlas(\"/main/my_atlas.a.texturesetc\", {\n ...data,\n animations: [my_animation, ...animations],\n geometries: [first_geometry, ...geometries],\n });\n }\n },\n});"
|
|
1426
1801
|
},
|
|
1427
1802
|
{
|
|
1428
1803
|
"sourceHash": "c672fd8c9d921f68",
|
|
1429
|
-
"ts": "// Sets atlas data for a 256x256 texture with a single animation being rendered as a quad\nexport default defineScript({\n init() {\n const params = {\n texture: \"/main/my_256x256_texture.texturec\",\n animations: [\n {\n id: \"my_animation\",\n width: 256,\n height: 256,\n frames: [1],\n },\n ],\n geometries: [\n {\n vertices: [0, 0, 0, 256, 256, 256, 256, 0],\n uvs: [0, 0, 0, 256, 256, 256, 256, 0],\n indices: [0, 1, 2, 0, 2, 3],\n },\n ],\n };\n resource.set_atlas(\"/main/test.a.texturesetc\", params);\n },\n});"
|
|
1804
|
+
"ts": "// Sets atlas data for a 256x256 texture with a single animation being rendered as a quad\nexport default defineScript({\n init() {\n const params = {\n texture: \"/main/my_256x256_texture.texturec\",\n animations: [\n {\n id: \"my_animation\",\n width: 256,\n height: 256,\n frames: [1],\n },\n ],\n geometries: [\n {\n vertices: [0, 0, 0, 256, 256, 256, 256, 0],\n uvs: [0, 0, 0, 256, 256, 256, 256, 0],\n indices: [0, 1, 2, 0, 2, 3],\n },\n ],\n } satisfies Parameters<typeof resource.set_atlas>[1];\n resource.set_atlas(\"/main/test.a.texturesetc\", params);\n },\n});"
|
|
1430
1805
|
}
|
|
1431
1806
|
],
|
|
1432
1807
|
"resource.set_buffer": [
|
|
1433
1808
|
{
|
|
1434
1809
|
"sourceHash": "a52fd8ac7453f601",
|
|
1435
|
-
"ts": "// How to set the data from a buffer\nfunction fill_stream(stream: { [index: number]: number }, verts: number[]) {\n verts.forEach((value, key) => {\n stream[key] = value;\n });\n}\n\nexport default defineScript({\n init() {\n const res_path = go.get(\"#mesh\", \"vertices\");\n\n const positions = [\n 1, -1, 0,\n 1, 1, 0,\n -1, -1, 0,\n ];\n\n const num_verts = positions.length / 3;\n\n // create a new buffer\n let buf = buffer.create(num_verts, [{ name: hash(\"position\"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);\n\n buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n fill_stream(stream_positions, positions);\n\n resource.set_buffer(res_path, buf);\n },\n});"
|
|
1810
|
+
"ts": "// How to set the data from a buffer\nfunction fill_stream(stream: { [index: number]: number }, verts: number[]) {\n verts.forEach((value, key) => {\n stream[key] = value;\n });\n}\n\nexport default defineScript({\n init() {\n const res_path = go.get<mesh.properties>()(\"#mesh\", \"vertices\");\n\n const positions = [\n 1, -1, 0,\n 1, 1, 0,\n -1, -1, 0,\n ];\n\n const num_verts = positions.length / 3;\n\n // create a new buffer\n let buf = buffer.create(num_verts, [{ name: hash(\"position\"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);\n\n buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n fill_stream(stream_positions, positions);\n\n resource.set_buffer(res_path, buf);\n },\n});"
|
|
1436
1811
|
}
|
|
1437
1812
|
],
|
|
1438
1813
|
"resource.set_texture": [
|
|
1439
1814
|
{
|
|
1440
1815
|
"sourceHash": "fe312c35ef2ab0f4",
|
|
1441
|
-
"ts": "// How to set all pixels of an atlas\nexport default defineScript({\n init(
|
|
1816
|
+
"ts": "// How to set all pixels of an atlas\nexport default defineScript({\n init() {\n const height = 128;\n const width = 128;\n const buf = buffer.create(width * height, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n const stream = buffer.get_stream(buf, hash(\"rgb\"));\n\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const index = y * width * 3 + x * 3;\n stream[index + 0] = 0xff;\n stream[index + 1] = 0x80;\n stream[index + 2] = 0x10;\n }\n }\n\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGB;\n if (format !== undefined) {\n const resource_path = go.get<model.properties>()(\"#model\", \"texture0\");\n const args = { width, height, type: graphics.TEXTURE_TYPE_2D, format, num_mip_maps: 1 };\n resource.set_texture(resource_path, args, buf);\n }\n return { buffer: buf, stream };\n },\n});"
|
|
1442
1817
|
},
|
|
1443
1818
|
{
|
|
1444
1819
|
"sourceHash": "b4098f0f37b9c1d0",
|
|
1445
|
-
"ts": "// How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.\nexport default defineScript({\n init(
|
|
1820
|
+
"ts": "// How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.\nexport default defineScript({\n init() {\n const x = 16;\n const y = 16;\n const height = 128 - x * 2;\n const width = 128 - y * 2;\n const buf = buffer.create(width * height, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n const stream = buffer.get_stream(buf, hash(\"rgb\"));\n\n for (let row = 0; row < height; row++) {\n for (let col = 0; col < width; col++) {\n const index = row * width * 3 + col * 3;\n stream[index + 0] = 0xff;\n stream[index + 1] = 0x80;\n stream[index + 2] = 0x10;\n }\n }\n\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGB;\n if (format !== undefined) {\n const resource_path = go.get<model.properties>()(\"#model\", \"texture0\");\n const args = { width, height, x, y, type: graphics.TEXTURE_TYPE_2D, format, num_mip_maps: 1 };\n resource.set_texture(resource_path, args, buf);\n }\n return { buffer: buf, stream };\n },\n});"
|
|
1446
1821
|
},
|
|
1447
1822
|
{
|
|
1448
1823
|
"sourceHash": "02d7f2ec29971bf1",
|
|
1449
|
-
"ts": "// Update a texture from a buffer resource\
|
|
1824
|
+
"ts": "// Update a texture from a buffer resource\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_buffer: resource.buffer(\"/my_default_buffer.buffer\") },\n\n init(self) {\n // the engine registers a texture format only when the driver supports it\n const format = graphics.TEXTURE_FORMAT_RGB;\n if (format === undefined) return;\n const resource_path = go.get<model.properties>()(\"#model\", \"texture0\");\n // the \"my_buffer\" resource is expected to hold 128 * 128 * 3 bytes!\n const args = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format,\n };\n // Note that the extra resource.get_buffer call is a requirement here\n // since the \"self.my_buffer\" is just pointing to a buffer resource path\n // and not an actual buffer object or buffer resource.\n resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer));\n },\n});"
|
|
1450
1825
|
},
|
|
1451
1826
|
{
|
|
1452
1827
|
"sourceHash": "15829bfe1b186bc3",
|
|
1453
|
-
"ts": "// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format:
|
|
1828
|
+
"ts": "// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format: graphics.TEXTURE_FORMAT_RGBA32F,\n };\n\n // This expects that the texture resource \"/my_3d_texture.texturec\" already exists\n // and is a 3D texture resource. To create a dynamic 3D texture resource\n // use the \"resource.create_texture\" function.\n resource.set_texture(\"/my_3d_texture.texturec\", t_args, tbuffer);\n },\n});"
|
|
1454
1829
|
},
|
|
1455
1830
|
{
|
|
1456
1831
|
"sourceHash": "f9b616092f8c1b6a",
|
|
1457
|
-
"ts": "// Update texture 2nd array page with loaded texture from png\nconst tex_path = \"/bundle_resources/page_02.png\";\nconst [data] = sys.load_resource(tex_path);\nif (data !== undefined) {\n const buf = image.load_buffer(data);\n if (buf !== undefined) {\n // new_tex is the resource handle of a texture created via resource.create_texture\n const new_tex = resource.create_texture(\"/my_array_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_2D_ARRAY,\n width: buf.width,\n height: buf.height,\n page_count: 2,\n format
|
|
1832
|
+
"ts": "// Update texture 2nd array page with loaded texture from png\nconst tex_path = \"/bundle_resources/page_02.png\";\nconst [data] = sys.load_resource(tex_path);\n// the engine registers a texture format only when the driver supports it\nconst format = graphics.TEXTURE_FORMAT_RGB;\nif (data !== undefined && format !== undefined) {\n const buf = image.load_buffer(data);\n if (buf !== undefined) {\n // new_tex is the resource handle of a texture created via resource.create_texture\n const new_tex = resource.create_texture(\"/my_array_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_2D_ARRAY,\n width: buf.width,\n height: buf.height,\n page_count: 2,\n format,\n });\n resource.set_texture(\n new_tex,\n {\n type: graphics.TEXTURE_TYPE_2D_ARRAY,\n width: buf.width,\n height: buf.height,\n page: 1,\n format,\n },\n buf.buffer,\n );\n go.set(\"#mesh\", \"texture0\", new_tex);\n }\n}"
|
|
1458
1833
|
},
|
|
1459
1834
|
{
|
|
1460
1835
|
"sourceHash": "34dce6f8362c0e92",
|
|
1461
|
-
"ts": "// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format:
|
|
1836
|
+
"ts": "// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format: graphics.TEXTURE_FORMAT_RGBA32F,\n };\n\n // This expects that the texture resource \"/my_3d_texture.texturec\" already exists\n // and is a 3D texture resource. To create a dynamic 3D texture resource\n // use the \"resource.create_texture\" function.\n resource.set_texture(\"/my_3d_texture.texturec\", t_args, tbuffer);\n },\n});"
|
|
1837
|
+
},
|
|
1838
|
+
{
|
|
1839
|
+
"sourceHash": "805bde1e64372a97",
|
|
1840
|
+
"ts": "if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {\n // it is safe to use this format\n}"
|
|
1841
|
+
},
|
|
1842
|
+
{
|
|
1843
|
+
"sourceHash": "51b59b3d6e594c38",
|
|
1844
|
+
"ts": "if (graphics.TEXTURE_TYPE_3D !== undefined) {\n // Device and graphics adapter support 3D textures\n}"
|
|
1845
|
+
},
|
|
1846
|
+
{
|
|
1847
|
+
"sourceHash": "99a0f19709b55611",
|
|
1848
|
+
"ts": "if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {\n // It is safe to use this format.\n}"
|
|
1849
|
+
},
|
|
1850
|
+
{
|
|
1851
|
+
"sourceHash": "a2e9eeb06d748575",
|
|
1852
|
+
"ts": "if (graphics.TEXTURE_TYPE_3D !== undefined) {\n // The device and graphics adapter support 3D textures.\n}"
|
|
1853
|
+
},
|
|
1854
|
+
{
|
|
1855
|
+
"sourceHash": "e051bd09ecb32c90",
|
|
1856
|
+
"ts": "// Update an existing 3D texture from a lua buffer\nexport default defineScript({\n init() {\n // the engine registers a texture type or format only when the driver supports it\n const type = graphics.TEXTURE_TYPE_IMAGE_3D;\n const format = graphics.TEXTURE_FORMAT_RGBA32F;\n if (type === undefined || format === undefined) return;\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 1; z <= 8; z++) {\n for (let y = 1; y <= 8; y++) {\n for (let x = 1; x <= 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type,\n width: 8,\n height: 8,\n depth: 8,\n format,\n };\n\n // This expects that the texture resource \"/my_3d_texture.texturec\" already exists\n // and is a 3D texture resource. To create a dynamic 3D texture resource\n // use the \"resource.create_texture\" function.\n resource.set_texture(\"/my_3d_texture.texturec\", t_args, tbuffer);\n },\n});"
|
|
1462
1857
|
}
|
|
1463
1858
|
],
|
|
1464
1859
|
"resource.texture": [
|
|
1465
1860
|
{
|
|
1466
1861
|
"sourceHash": "8cd63a7393c8a799",
|
|
1467
|
-
"ts": "// Load a texture and set it to a model:\
|
|
1862
|
+
"ts": "// Load a texture and set it to a model:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_texture: resource.texture(\"/texture.png\") },\n\n init(self) {\n go.set(\"#model\", \"texture0\", self.my_texture);\n },\n});"
|
|
1468
1863
|
}
|
|
1469
1864
|
],
|
|
1470
1865
|
"resource.tile_source": [
|
|
1471
1866
|
{
|
|
1472
1867
|
"sourceHash": "517b23c5ce0e56c6",
|
|
1473
|
-
"ts": "// Load tile source and set it to a tile map:\
|
|
1868
|
+
"ts": "// Load tile source and set it to a tile map:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_tile_source: resource.tile_source(\"/tilesource.tilesource\") },\n\n init(self) {\n go.set(\"#tilemap\", \"tile_source\", self.my_tile_source);\n },\n});"
|
|
1474
1869
|
}
|
|
1475
1870
|
],
|
|
1476
1871
|
"socket.gettime": [
|
|
@@ -1482,19 +1877,23 @@
|
|
|
1482
1877
|
"socket.newtry": [
|
|
1483
1878
|
{
|
|
1484
1879
|
"sourceHash": "38a669dbf612b327",
|
|
1485
|
-
"ts": "// Perform operations on an open socket c:\nconst [c] = socket.connect(\"localhost\", 80);\nif (c !== undefined) {\n // create a try function that closes 'c' on error\n const try_ = socket.newtry(() => c.close());\n // do everything reassured c will be closed\n
|
|
1880
|
+
"ts": "// Perform operations on an open socket c:\nconst [c] = socket.connect(\"localhost\", 80);\nif (c !== undefined) {\n // create a try function that closes 'c' on error\n const try_ = socket.newtry(() => c.close());\n // do everything reassured c will be closed\n const [sent, sendError, lastByte] = c.send(\"hello there?\\r\\n\");\n try_(sent, sendError, lastByte);\n const [line, receiveError, partial] = c.receive();\n const answer = try_(line, receiveError, partial);\n // ...\n const [byeSent, byeError, byeLastByte] = c.send(\"good bye\\r\\n\");\n try_(byeSent, byeError, byeLastByte);\n c.close();\n}"
|
|
1486
1881
|
}
|
|
1487
1882
|
],
|
|
1488
1883
|
"socket.protect": [
|
|
1489
1884
|
{
|
|
1490
1885
|
"sourceHash": "478d4974b491bda9",
|
|
1491
|
-
"ts": "const dostuff = socket.protect(() => {\n let try_ = socket.newtry();\n const
|
|
1886
|
+
"ts": "const dostuff = socket.protect(() => {\n let try_ = socket.newtry();\n const [conn, connectError] = socket.connect(\"myserver.com\", 80);\n const c = try_(conn, connectError);\n try_ = socket.newtry(() => c.close());\n const [sent, sendError, lastByte] = c.send(\"hello?\\r\\n\");\n try_(sent, sendError, lastByte);\n const [line, receiveError, partial] = c.receive();\n const answer = try_(line, receiveError, partial);\n c.close();\n});\n\nconst [n, error] = dostuff();"
|
|
1492
1887
|
}
|
|
1493
1888
|
],
|
|
1494
1889
|
"socket.skip": [
|
|
1495
1890
|
{
|
|
1496
|
-
"sourceHash": "
|
|
1497
|
-
"ts": "const line = \"250 OK\";\n
|
|
1891
|
+
"sourceHash": "4a23a75fe4aaaca9",
|
|
1892
|
+
"ts": "const line = \"250 OK\";\n// get the status code and separator from SMTP server reply\nconst [dummy1, dummy2, code, sep] = string.find(line, \"^(%d%d%d)(.?)\");"
|
|
1893
|
+
},
|
|
1894
|
+
{
|
|
1895
|
+
"sourceHash": "76686918042071bd",
|
|
1896
|
+
"ts": "const line = \"250 OK\";\n// get the status code and separator from SMTP server reply\nconst [code, sep] = socket.skip(2, string.find(line, \"^(%d%d%d)(.?)\"));"
|
|
1498
1897
|
}
|
|
1499
1898
|
],
|
|
1500
1899
|
"sound.get_group_gain": [
|
|
@@ -1547,8 +1946,12 @@
|
|
|
1547
1946
|
],
|
|
1548
1947
|
"sound.play": [
|
|
1549
1948
|
{
|
|
1550
|
-
"sourceHash": "
|
|
1551
|
-
"ts": "
|
|
1949
|
+
"sourceHash": "657f9fcfa39cf3af",
|
|
1950
|
+
"ts": "sound.play(\"#sound\", { delay: 1, gain: 0.9, pan: -1.0 });"
|
|
1951
|
+
},
|
|
1952
|
+
{
|
|
1953
|
+
"sourceHash": "181c1feca6bf14c8",
|
|
1954
|
+
"ts": "function sound_done(self: unknown, message_id: unknown, message: unknown, sender: unknown) {\n // play 'boom' sound fx when the countdown has completed\n const { play_id } = message as { play_id: number };\n if (message_id === hash(\"sound_done\") && play_id === (self as { countdown_id: number }).countdown_id) {\n sound.play(\"#boom\", undefined, sound_done);\n }\n}\n\nexport default defineScript({\n init() {\n return { countdown_id: sound.play(\"#countdown\", undefined, sound_done) };\n },\n});"
|
|
1552
1955
|
}
|
|
1553
1956
|
],
|
|
1554
1957
|
"sound.set_gain": [
|
|
@@ -1577,8 +1980,12 @@
|
|
|
1577
1980
|
],
|
|
1578
1981
|
"sprite.play_flipbook": [
|
|
1579
1982
|
{
|
|
1580
|
-
"sourceHash": "
|
|
1581
|
-
"ts": "
|
|
1983
|
+
"sourceHash": "69a3c26fd553ffa4",
|
|
1984
|
+
"ts": "const url = msg.url(\"#sprite\");\n\nfunction anim_done(self: unknown, message_id: Hash, message: { id: Hash }) {\n if (message_id === hash(\"animation_done\") && message.id === hash(\"jump\")) {\n // jump animation done, chain with \"run\"\n sprite.play_flipbook(url, \"run\");\n }\n}"
|
|
1985
|
+
},
|
|
1986
|
+
{
|
|
1987
|
+
"sourceHash": "286542aa4db17a87",
|
|
1988
|
+
"ts": "export default defineScript({\n init() {\n const url = msg.url(\"#sprite\");\n sprite.play_flipbook(url, \"jump\", (self, message_id, message) => {\n if (message_id === hash(\"animation_done\") && message.id === hash(\"jump\")) {\n // jump animation done, chain with \"run\"\n sprite.play_flipbook(url, \"run\");\n }\n });\n },\n});"
|
|
1582
1989
|
}
|
|
1583
1990
|
],
|
|
1584
1991
|
"sprite.reset_constant": [
|
|
@@ -1590,13 +1997,13 @@
|
|
|
1590
1997
|
"sprite.set_hflip": [
|
|
1591
1998
|
{
|
|
1592
1999
|
"sourceHash": "2d067cdccd1fb269",
|
|
1593
|
-
"ts": "// How to flip a sprite so it faces the horizontal movement (it is assumed that\n// the sprite component has id \"sprite\" and the original animation faces right):\nexport default defineScript({\n update(self, dt) {\n // calculate self.velocity somehow\n sprite.set_hflip(\"#sprite\", self.velocity.x < 0);\n },\n});"
|
|
2000
|
+
"ts": "// How to flip a sprite so it faces the horizontal movement (it is assumed that\n// the sprite component has id \"sprite\" and the original animation faces right):\nexport default defineScript({\n init() {\n return { velocity: vmath.vector3() };\n },\n\n update(self, dt) {\n // calculate self.velocity somehow\n sprite.set_hflip(\"#sprite\", self.velocity.x < 0);\n },\n});"
|
|
1594
2001
|
}
|
|
1595
2002
|
],
|
|
1596
2003
|
"sprite.set_vflip": [
|
|
1597
2004
|
{
|
|
1598
2005
|
"sourceHash": "89dcc94c14d785e2",
|
|
1599
|
-
"ts": "// How to flip a sprite in a game which negates gravity as a game mechanic (it is\n// assumed that the sprite component has id \"sprite\" and the original animation\n// is up-right):\nexport default defineScript({\n update(self, dt) {\n // calculate self.up_side_down somehow, then:\n sprite.set_vflip(\"#sprite\", self.up_side_down);\n },\n});"
|
|
2006
|
+
"ts": "// How to flip a sprite in a game which negates gravity as a game mechanic (it is\n// assumed that the sprite component has id \"sprite\" and the original animation\n// is up-right):\nexport default defineScript({\n init() {\n return { up_side_down: false };\n },\n\n update(self, dt) {\n // calculate self.up_side_down somehow, then:\n sprite.set_vflip(\"#sprite\", self.up_side_down);\n },\n});"
|
|
1600
2007
|
}
|
|
1601
2008
|
],
|
|
1602
2009
|
"sys.deserialize": [
|
|
@@ -1608,7 +2015,7 @@
|
|
|
1608
2015
|
"sys.exists": [
|
|
1609
2016
|
{
|
|
1610
2017
|
"sourceHash": "7e98945102ff1ab7",
|
|
1611
|
-
"ts": "// Load data but return nil if path didn't exist\
|
|
2018
|
+
"ts": "// Load data but return nil if path didn't exist\nfunction load_data(path: string) {\n if (!sys.exists(path)) {\n return undefined;\n }\n return sys.load(path); // returns {} if it failed\n}"
|
|
1612
2019
|
}
|
|
1613
2020
|
],
|
|
1614
2021
|
"sys.exit": [
|
|
@@ -1619,8 +2026,12 @@
|
|
|
1619
2026
|
],
|
|
1620
2027
|
"sys.get_application_info": [
|
|
1621
2028
|
{
|
|
1622
|
-
"sourceHash": "
|
|
1623
|
-
"ts": "
|
|
2029
|
+
"sourceHash": "326e42d5ff9baf96",
|
|
2030
|
+
"ts": "const sysinfo = sys.get_sys_info();\nlet twitter: { installed?: boolean } = {};\n\nif (sysinfo.system_name === \"Android\") {\n twitter = sys.get_application_info(\"com.twitter.android\");\n} else if (sysinfo.system_name === \"iPhone OS\") {\n twitter = sys.get_application_info(\"twitter:\");\n}\n\nif (twitter.installed) {\n // twitter is installed!\n}"
|
|
2031
|
+
},
|
|
2032
|
+
{
|
|
2033
|
+
"sourceHash": "1dd1eced66cc1e10",
|
|
2034
|
+
"ts": "// ...\n// <key>LSApplicationQueriesSchemes</key>\n// <array>\n// <string>twitter</string>\n// </array>\n// ..."
|
|
1624
2035
|
}
|
|
1625
2036
|
],
|
|
1626
2037
|
"sys.get_application_path": [
|
|
@@ -1637,8 +2048,12 @@
|
|
|
1637
2048
|
],
|
|
1638
2049
|
"sys.get_config_int": [
|
|
1639
2050
|
{
|
|
1640
|
-
"sourceHash": "
|
|
1641
|
-
"ts": "
|
|
2051
|
+
"sourceHash": "cadf71c740165693",
|
|
2052
|
+
"ts": "const speed = sys.get_config_int(\"my_game.speed\", 20); // with default value"
|
|
2053
|
+
},
|
|
2054
|
+
{
|
|
2055
|
+
"sourceHash": "9365fae7e38c060c",
|
|
2056
|
+
"ts": "const testmode = sys.get_config_int(\"my_game.testmode\"); // without default value\nif (testmode !== undefined) {\n // do stuff\n}"
|
|
1642
2057
|
}
|
|
1643
2058
|
],
|
|
1644
2059
|
"sys.get_config_number": [
|
|
@@ -1649,8 +2064,20 @@
|
|
|
1649
2064
|
],
|
|
1650
2065
|
"sys.get_config_string": [
|
|
1651
2066
|
{
|
|
1652
|
-
"sourceHash": "
|
|
1653
|
-
"ts": "
|
|
2067
|
+
"sourceHash": "0bf7e3158e38a94a",
|
|
2068
|
+
"ts": "const text = sys.get_config_string(\"my_game.text\", \"default text\");"
|
|
2069
|
+
},
|
|
2070
|
+
{
|
|
2071
|
+
"sourceHash": "a4703f05ae2e55b8",
|
|
2072
|
+
"ts": "// $ dmengine --config=bootstrap.main_collection=/mytest.collectionc --config=mygame.testmode=1"
|
|
2073
|
+
},
|
|
2074
|
+
{
|
|
2075
|
+
"sourceHash": "4bf891e310fb931a",
|
|
2076
|
+
"ts": "const testmode = sys.get_config_int(\"mygame.testmode\");"
|
|
2077
|
+
},
|
|
2078
|
+
{
|
|
2079
|
+
"sourceHash": "c1b9b57492dd68a7",
|
|
2080
|
+
"ts": "const text = sys.get_config_string(\"my_game.text\", \"default text\");"
|
|
1654
2081
|
}
|
|
1655
2082
|
],
|
|
1656
2083
|
"sys.get_connectivity": [
|
|
@@ -1667,8 +2094,12 @@
|
|
|
1667
2094
|
],
|
|
1668
2095
|
"sys.get_host_path": [
|
|
1669
2096
|
{
|
|
1670
|
-
"sourceHash": "
|
|
1671
|
-
"ts": "
|
|
2097
|
+
"sourceHash": "cea90df8f93a0217",
|
|
2098
|
+
"ts": "const mytable = { score: 100, level: 3 };\nconst host_path = sys.get_host_path(\"logs/test.txt\");\nsys.save(host_path, mytable);"
|
|
2099
|
+
},
|
|
2100
|
+
{
|
|
2101
|
+
"sourceHash": "8b9a6ad30303b25e",
|
|
2102
|
+
"ts": "const host_path = sys.get_host_path(\"logs/test.txt\");\nconst table = sys.load(host_path);"
|
|
1672
2103
|
}
|
|
1673
2104
|
],
|
|
1674
2105
|
"sys.get_ifaddrs": [
|
|
@@ -1697,14 +2128,30 @@
|
|
|
1697
2128
|
],
|
|
1698
2129
|
"sys.load_buffer": [
|
|
1699
2130
|
{
|
|
1700
|
-
"sourceHash": "
|
|
1701
|
-
"ts": "
|
|
2131
|
+
"sourceHash": "485ff25191819692",
|
|
2132
|
+
"ts": "const my_buffer = sys.load_buffer(\"/assets/my_level_data.bin\");\nconst data_str = buffer.get_bytes(my_buffer, \"data\");\nconst has_my_header = data_str.slice(0, 6) === \"D3F0LD\";"
|
|
2133
|
+
},
|
|
2134
|
+
{
|
|
2135
|
+
"sourceHash": "ff532f8e663a09ba",
|
|
2136
|
+
"ts": "const asset_1 = sys.load_buffer(\"folder_next_to_binary/my_level_asset.txt\");\nconst asset_2 = sys.load_buffer(\"/my/absolute/path\");"
|
|
1702
2137
|
}
|
|
1703
2138
|
],
|
|
1704
2139
|
"sys.load_buffer_async": [
|
|
1705
2140
|
{
|
|
1706
|
-
"sourceHash": "
|
|
1707
|
-
"ts": "
|
|
2141
|
+
"sourceHash": "91d84e7dc569ae20",
|
|
2142
|
+
"ts": "function my_callback(self: unknown, request_id: unknown, result: unknown) {\n const { status, buf } = result as { status: number; buf: Opaque<\"buffer\"> };\n if (status === sys.REQUEST_STATUS_FINISHED) {\n resource.set_texture(\"/my_texture\", { type: graphics.TEXTURE_TYPE_2D, width: 128, height: 128, format: graphics.TEXTURE_FORMAT_RGBA }, buf);\n }\n}\n\nconst my_request = sys.load_buffer_async(\"/assets/my_level_data.bin\", my_callback);"
|
|
2143
|
+
},
|
|
2144
|
+
{
|
|
2145
|
+
"sourceHash": "5545b8901e6ec4c5",
|
|
2146
|
+
"ts": "function my_callback(self: unknown, request_id: unknown, result: unknown) {\n const { first_asset, second_asset } = self as { first_asset: Hash; second_asset: Hash };\n if ((result as { status: number }).status !== sys.REQUEST_STATUS_FINISHED) {\n // uh oh! File could not be found, do something graceful\n } else if (request_id === first_asset) {\n // result.buffer contains data from my_level_asset.bin\n } else if (request_id === second_asset) {\n // result.buffer contains data from 'my_level.bin'\n }\n}\n\nexport default defineScript({\n init() {\n const first_path = \"folder_next_to_binary/my_level_asset.bin\";\n const second_path = \"/some_absolute_path/my_level.bin\";\n return {\n first_asset: hash(first_path),\n second_asset: hash(second_path),\n first_request: sys.load_buffer_async(first_path, my_callback),\n second_request: sys.load_buffer_async(second_path, my_callback),\n };\n },\n});"
|
|
2147
|
+
},
|
|
2148
|
+
{
|
|
2149
|
+
"sourceHash": "7f66d3285b20ff78",
|
|
2150
|
+
"ts": "// Load binary data from a custom project resource and update a texture resource:\nfunction my_callback(self: unknown, request_id: number, result: sys.load_buffer_result) {\n const format = graphics.TEXTURE_FORMAT_RGBA;\n if (result.status === sys.REQUEST_STATUS_FINISHED && result.buffer !== undefined && format !== undefined) {\n resource.set_texture(\"/my_texture\", { type: graphics.TEXTURE_TYPE_2D, width: 128, height: 128, format }, result.buffer);\n }\n}\n\nconst my_request = sys.load_buffer_async(\"/assets/my_level_data.bin\", my_callback);"
|
|
2151
|
+
},
|
|
2152
|
+
{
|
|
2153
|
+
"sourceHash": "9be4f92f718990af",
|
|
2154
|
+
"ts": "// Load binary data from non-custom resource files on disk:\nfunction my_callback(self: unknown, request_id: number, result: sys.load_buffer_result) {\n const { first_request, second_request } = self as { first_request: number; second_request: number };\n if (result.status !== sys.REQUEST_STATUS_FINISHED) {\n // uh oh! File could not be found, do something graceful\n } else if (request_id === first_request) {\n // result.buffer contains data from my_level_asset.bin\n } else if (request_id === second_request) {\n // result.buffer contains data from 'my_level.bin'\n }\n}\n\nexport default defineScript({\n init() {\n return {\n first_request: sys.load_buffer_async(\"folder_next_to_binary/my_level_asset.bin\", my_callback),\n second_request: sys.load_buffer_async(\"/some_absolute_path/my_level.bin\", my_callback),\n };\n },\n});"
|
|
1708
2155
|
}
|
|
1709
2156
|
],
|
|
1710
2157
|
"sys.load_resource": [
|
|
@@ -1745,8 +2192,12 @@
|
|
|
1745
2192
|
],
|
|
1746
2193
|
"sys.set_engine_throttle": [
|
|
1747
2194
|
{
|
|
1748
|
-
"sourceHash": "
|
|
1749
|
-
"ts": "
|
|
2195
|
+
"sourceHash": "3e3d6cc6b4f7ebb6",
|
|
2196
|
+
"ts": "sys.set_engine_throttle(false);"
|
|
2197
|
+
},
|
|
2198
|
+
{
|
|
2199
|
+
"sourceHash": "8bf9b8da4d26c449",
|
|
2200
|
+
"ts": "sys.set_engine_throttle(true, 1.5);"
|
|
1750
2201
|
}
|
|
1751
2202
|
],
|
|
1752
2203
|
"sys.set_error_handler": [
|
|
@@ -1755,10 +2206,10 @@
|
|
|
1755
2206
|
"ts": "// Install error handler that just prints the errors\nfunction my_error_handler(source: unknown, message: unknown, traceback: unknown) {\n print(source); //> lua\n print(message); //> main/my.script:10: attempt to perform arithmetic on a string value\n print(traceback); //> stack traceback:\n //> main/test.script:10: in function 'boom'\n //> main/test.script:15: in function <main/my.script:13>\n}\n\nfunction boom() {\n return 10 + \"string\";\n}\n\nexport default defineScript({\n init() {\n sys.set_error_handler(my_error_handler);\n boom();\n },\n});"
|
|
1756
2207
|
}
|
|
1757
2208
|
],
|
|
1758
|
-
"sys.
|
|
2209
|
+
"sys.set_render_enabled": [
|
|
1759
2210
|
{
|
|
1760
2211
|
"sourceHash": "aa4a8e62d5eddb0b",
|
|
1761
|
-
"ts": "// Disable rendering\nsys.
|
|
2212
|
+
"ts": "// Disable rendering\nsys.set_render_enabled(false);"
|
|
1762
2213
|
}
|
|
1763
2214
|
],
|
|
1764
2215
|
"sys.set_update_frequency": [
|
|
@@ -1771,6 +2222,10 @@
|
|
|
1771
2222
|
{
|
|
1772
2223
|
"sourceHash": "95117be25e11bf9f",
|
|
1773
2224
|
"ts": "// Setting the swap intervall to swap every v-blank\nsys.set_vsync_swap_interval(1);"
|
|
2225
|
+
},
|
|
2226
|
+
{
|
|
2227
|
+
"sourceHash": "3b6e97f1ef4ca783",
|
|
2228
|
+
"ts": "// Setting the swap interval to swap every v-blank\nsys.set_vsync_swap_interval(1);"
|
|
1774
2229
|
}
|
|
1775
2230
|
],
|
|
1776
2231
|
"tilemap.get_bounds": [
|
|
@@ -1819,12 +2274,20 @@
|
|
|
1819
2274
|
{
|
|
1820
2275
|
"sourceHash": "00f46bbbb35028b3",
|
|
1821
2276
|
"ts": "function cancel_ticking(self: { handle: number }) {\n self.handle = timer.delay(1, true, () => print(\"print every second\"));\n // ...\n const result = timer.cancel(self.handle);\n if (!result) {\n print(\"the timer is already cancelled\");\n }\n}"
|
|
2277
|
+
},
|
|
2278
|
+
{
|
|
2279
|
+
"sourceHash": "ad9e37f1a30347b3",
|
|
2280
|
+
"ts": "function cancel_ticking(self: { handle: number }) {\n self.handle = timer.delay(1, true, () => print(\"print every second\"));\n // ...\n const cancelled = timer.cancel(self.handle);\n if (!cancelled) {\n print(\"the timer is already cancelled\");\n }\n}"
|
|
1822
2281
|
}
|
|
1823
2282
|
],
|
|
1824
2283
|
"timer.delay": [
|
|
1825
2284
|
{
|
|
1826
|
-
"sourceHash": "
|
|
1827
|
-
"ts": "
|
|
2285
|
+
"sourceHash": "afdbd5fc199b8290",
|
|
2286
|
+
"ts": "timer.delay(1, false, () => print(\"print in one second\"));"
|
|
2287
|
+
},
|
|
2288
|
+
{
|
|
2289
|
+
"sourceHash": "777732bd4b7c14a2",
|
|
2290
|
+
"ts": "function call_every_second(self: unknown, handle: unknown, time_elapsed: unknown) {\n const state = self as { counter: number };\n state.counter = state.counter + 1;\n print(\"Call #\", state.counter);\n if (state.counter === 10) {\n timer.cancel(handle as number); // cancel timer after 10 calls\n }\n}\n\nfunction start_counting(self: { counter: number }) {\n self.counter = 0;\n timer.delay(1, true, call_every_second);\n}"
|
|
1828
2291
|
}
|
|
1829
2292
|
],
|
|
1830
2293
|
"timer.get_info": [
|
|
@@ -1837,6 +2300,10 @@
|
|
|
1837
2300
|
{
|
|
1838
2301
|
"sourceHash": "3d4814c0a3380acf",
|
|
1839
2302
|
"ts": "function trigger_ticking(self: { handle: number }) {\n self.handle = timer.delay(1, true, () => print(\"print every second or manually by timer.trigger\"));\n // ...\n const result = timer.trigger(self.handle);\n if (!result) {\n print(\"the timer is already cancelled or complete\");\n }\n}"
|
|
2303
|
+
},
|
|
2304
|
+
{
|
|
2305
|
+
"sourceHash": "96cf34367a47da0b",
|
|
2306
|
+
"ts": "function trigger_ticking(self: { handle: number }) {\n self.handle = timer.delay(1, true, () => print(\"print every second or manually by timer.trigger\"));\n // ...\n const triggered = timer.trigger(self.handle);\n if (!triggered) {\n print(\"the timer is already cancelled or complete\");\n }\n}"
|
|
1840
2307
|
}
|
|
1841
2308
|
],
|
|
1842
2309
|
"update": [
|
|
@@ -1846,7 +2313,7 @@
|
|
|
1846
2313
|
},
|
|
1847
2314
|
{
|
|
1848
2315
|
"sourceHash": "f4f87939dbdd5fc3",
|
|
1849
|
-
"ts": "// This example demonstrates how to update a text node that displays game score\n// in a counting fashion. It is assumed that the gui component receives messages\n// from the game when a new score is to be shown.\nexport default defineGuiScript({\n init(
|
|
2316
|
+
"ts": "// This example demonstrates how to update a text node that displays game score\n// in a counting fashion. It is assumed that the gui component receives messages\n// from the game when a new score is to be shown.\nexport default defineGuiScript({\n init() {\n return {\n // fetch the score text node for later use (assumes it is called \"score\")\n score_node: gui.get_node(\"score\"),\n // keep track of the current score counted up so far\n current_score: 0,\n // keep track of the target score we should count up to\n target_score: 0,\n // how fast we will update the score, in score/second\n score_update_speed: 1,\n };\n },\n\n update(self, dt) {\n // check if target score is more than current score\n if (self.current_score < self.target_score) {\n // increment current score according to the speed\n self.current_score = self.current_score + dt * self.score_update_speed;\n // check if we went past the target score, clamp current score in that case\n if (self.current_score > self.target_score) {\n self.current_score = self.target_score;\n }\n // update the score text node\n gui.set_text(self.score_node, \"\" + math.floor(self.current_score));\n }\n },\n\n on_message(self, message_id, message) {\n // check the message\n if (message_id === hash(\"set_score\") && typeof message.score === \"number\") {\n self.target_score = message.score;\n }\n },\n});"
|
|
1850
2317
|
}
|
|
1851
2318
|
],
|
|
1852
2319
|
"vmath.clamp": [
|
|
@@ -1904,11 +2371,11 @@
|
|
|
1904
2371
|
},
|
|
1905
2372
|
{
|
|
1906
2373
|
"sourceHash": "7cf8c0c1679ab05b",
|
|
1907
|
-
"ts": "export default defineScript({\n init(
|
|
2374
|
+
"ts": "export default defineScript({\n init() {\n return { t: 0 };\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startrot = vmath.quat_rotation_z(0);\n const endrot = vmath.quat_rotation_z(3.141592653);\n const rot = vmath.lerp(self.t, startrot, endrot);\n go.set_rotation(rot, \"go\");\n }\n },\n});"
|
|
1908
2375
|
},
|
|
1909
2376
|
{
|
|
1910
2377
|
"sourceHash": "0f4fdfe7a9a39df7",
|
|
1911
|
-
"ts": "export default defineScript({\n init(
|
|
2378
|
+
"ts": "export default defineScript({\n init() {\n return { t: 0 };\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startx = 0;\n const endx = 600;\n const x = vmath.lerp(self.t, startx, endx);\n go.set_position(vmath.vector3(x, 100, 0), \"go\");\n }\n },\n});"
|
|
1912
2379
|
}
|
|
1913
2380
|
],
|
|
1914
2381
|
"vmath.matrix4": [
|
|
@@ -2094,7 +2561,7 @@
|
|
|
2094
2561
|
},
|
|
2095
2562
|
{
|
|
2096
2563
|
"sourceHash": "858acbd524dfe896",
|
|
2097
|
-
"ts": "export default defineScript({\n init(
|
|
2564
|
+
"ts": "export default defineScript({\n init() {\n return { t: 0 };\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startrot = vmath.quat_rotation_z(0);\n const endrot = vmath.quat_rotation_z(3.141592653);\n const rot = vmath.slerp(self.t, startrot, endrot);\n go.set_rotation(rot, \"go\");\n }\n },\n});"
|
|
2098
2565
|
}
|
|
2099
2566
|
],
|
|
2100
2567
|
"vmath.vector": [
|
|
@@ -2143,6 +2610,10 @@
|
|
|
2143
2610
|
{
|
|
2144
2611
|
"sourceHash": "5075cb14faa9510b",
|
|
2145
2612
|
"ts": "function window_callback(self: unknown, event: unknown, data: Record<string | number, unknown>) {\n if (event === window.WINDOW_EVENT_FOCUS_LOST) {\n print(\"window.WINDOW_EVENT_FOCUS_LOST\");\n } else if (event === window.WINDOW_EVENT_FOCUS_GAINED) {\n print(\"window.WINDOW_EVENT_FOCUS_GAINED\");\n } else if (event === window.WINDOW_EVENT_ICONFIED) {\n print(\"window.WINDOW_EVENT_ICONFIED\");\n } else if (event === window.WINDOW_EVENT_DEICONIFIED) {\n print(\"window.WINDOW_EVENT_DEICONIFIED\");\n } else if (event === window.WINDOW_EVENT_RESIZED) {\n print(\"Window resized: \", data.width, data.height);\n }\n}\n\nexport default defineScript({\n init() {\n window.set_listener(window_callback);\n },\n});"
|
|
2613
|
+
},
|
|
2614
|
+
{
|
|
2615
|
+
"sourceHash": "c4168599cd777bb9",
|
|
2616
|
+
"ts": "function window_callback(self: unknown, event: unknown, data: Record<string | number, unknown>) {\n if (event === window.WINDOW_EVENT_FOCUS_LOST) {\n print(\"window.WINDOW_EVENT_FOCUS_LOST\");\n } else if (event === window.WINDOW_EVENT_FOCUS_GAINED) {\n print(\"window.WINDOW_EVENT_FOCUS_GAINED\");\n } else if (event === window.WINDOW_EVENT_ICONIFIED) {\n print(\"window.WINDOW_EVENT_ICONIFIED\");\n } else if (event === window.WINDOW_EVENT_DEICONIFIED) {\n print(\"window.WINDOW_EVENT_DEICONIFIED\");\n } else if (event === window.WINDOW_EVENT_RESIZED) {\n print(\"Window resized: \", data.width, data.height);\n }\n}\n\nexport default defineScript({\n init() {\n window.set_listener(window_callback);\n },\n});"
|
|
2146
2617
|
}
|
|
2147
2618
|
],
|
|
2148
2619
|
"zlib.deflate": [
|