cluaupp 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +10 -5
- package/api/CHANGELOG.md +3 -0
- package/api/chat.js +74 -0
- package/api/fixtures/roblox/README.md +6 -0
- package/api/fixtures/roblox/aux/sample.d.luau +6 -0
- package/api/fixtures/roblox/mini/Mini-API-Dump.json +72 -0
- package/api/generated/bench-latest.json +39 -0
- package/api/generated/capability-profile.json +76 -0
- package/api/generated/lsp-index.json +1 -0
- package/api/generated/luau/classes.d.luau +11221 -0
- package/api/generated/luau/datatypes.d.luau +327 -0
- package/api/generated/luau/enums.d.luau +4918 -0
- package/api/generated/luau/globals.d.luau +12 -0
- package/api/manifests/roblox-target.manifest.json +22 -0
- package/api/normalized/roblox-target.profile.json +237461 -0
- package/api/overrides/classes.json +8 -0
- package/api/overrides/compatibility.json +9 -0
- package/api/overrides/datatypes.json +1579 -0
- package/api/overrides/enums.json +8 -0
- package/api/overrides/globals.json +8 -0
- package/api/overrides/type-mappings.json +9 -0
- package/api/roblox-api.lock.json +9 -0
- package/data/Mini-API-Dump.json +1 -0
- package/editors/vscode/README.md +12 -10
- package/editors/vscode/extension.js +82 -0
- package/editors/vscode/icons/axiom.svg +4 -0
- package/editors/vscode/icons/bloom.svg +5 -0
- package/editors/vscode/icons/helm.svg +4 -0
- package/editors/vscode/icons/hive.svg +5 -0
- package/editors/vscode/icons/mint.svg +4 -0
- package/editors/vscode/icons/shift.svg +6 -0
- package/editors/vscode/language-configuration-schema.json +24 -0
- package/editors/vscode/package.json +172 -12
- package/editors/vscode/snippets/axiom.json +12 -0
- package/editors/vscode/snippets/bloom.json +12 -0
- package/editors/vscode/snippets/helm.json +12 -0
- package/editors/vscode/snippets/hive.json +12 -0
- package/editors/vscode/snippets/mint.json +12 -0
- package/editors/vscode/snippets/shift.json +17 -0
- package/editors/vscode/syntaxes/axiom.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/bloom.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/helm.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/hive.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/mint.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/schema.tmLanguage.json +89 -0
- package/editors/vscode/syntaxes/shift.tmLanguage.json +5 -0
- package/examples/game/.cluaupp/compile-cache/ReplicatedStorage__Shared__Constants__Datas__TemplateData.clh.json +1 -0
- package/examples/game/.cluaupp/compile-cache/ServerScriptService__Boot__DataBoot.server.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/ServerScriptService__Configuration__ServerConfig.clp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/ServerScriptService__Handlers__Guard.server.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/ServerScriptService__Handlers__PlayerHandler.server.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/StarterPlayer__StarterCharacterScripts__Character__CharacterReady.client.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/StarterPlayer__StarterPlayerScripts__Controllers__DataController.client.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/index.json +12 -0
- package/examples/game/.cluaupp/datamodel-profile.json +94 -0
- package/examples/game/.vscode/settings.json +12 -1
- package/examples/game/include/clpp/datatypes.clh +337 -373
- package/examples/game/include/clpp/generated/datamodel.clh +25 -0
- package/examples/game/include/clpp/generated/enums.clh +1 -1
- package/examples/game/include/clpp/generated/instances.clh +41135 -41064
- package/examples/game/include/clpp/libs/axiom.clh +1 -1
- package/examples/game/include/clpp/libs/math.clh +14 -0
- package/examples/game/include/clpp/libs/spring.clh +17 -0
- package/examples/game/include/clpp/libs/ward.clh +1 -0
- package/examples/game/include/clpp/roblox.clh +3 -4
- package/examples/game/libs/ArrayIndexer/init.luau +209 -0
- package/examples/game/libs/Axiom/init.luau +608 -0
- package/examples/game/libs/Bloom/init.luau +433 -0
- package/examples/game/libs/Coil/init.luau +215 -0
- package/examples/game/libs/Crest/init.luau +426 -0
- package/examples/game/libs/Echo/init.luau +417 -0
- package/examples/game/libs/Ember/init.luau +365 -0
- package/examples/game/libs/Flare/init.luau +717 -0
- package/examples/game/libs/Gleam/init.luau +729 -0
- package/examples/game/libs/Guide/init.luau +215 -0
- package/examples/game/libs/Helm/init.luau +377 -0
- package/examples/game/libs/Hive/init.luau +241 -0
- package/examples/game/libs/Keep/Client.luau +114 -0
- package/examples/game/libs/Keep/Data.luau +883 -0
- package/examples/game/libs/Keep/Engine.luau +211 -0
- package/examples/game/libs/Keep/Enum.luau +6 -0
- package/examples/game/libs/Keep/Enums.luau +10 -0
- package/examples/game/libs/Keep/Path.luau +236 -0
- package/examples/game/libs/Keep/Replicator.luau +298 -0
- package/examples/game/libs/Keep/Server.luau +251 -0
- package/examples/game/libs/Keep/Store.luau +652 -0
- package/examples/game/libs/Keep/Trade.luau +455 -0
- package/examples/game/libs/Keep/init.luau +205 -0
- package/examples/game/libs/Lens/init.luau +609 -0
- package/examples/game/libs/Mint/init.luau +279 -0
- package/examples/game/libs/Net/init.luau +156 -0
- package/examples/game/libs/Net/src/codec.luau +224 -0
- package/examples/game/libs/Occlude/init.luau +117 -0
- package/examples/game/libs/Pin/init.luau +309 -0
- package/examples/game/libs/Promise/LICENSE +21 -0
- package/examples/game/libs/Promise/_impl/LICENSE +21 -0
- package/examples/game/libs/Promise/_impl/init.lua +1991 -0
- package/examples/game/libs/Promise/init.lua +1990 -0
- package/examples/game/libs/Promise/init.luau +13 -0
- package/examples/game/libs/Promise/types.luau +46 -0
- package/examples/game/libs/Roster/init.luau +686 -0
- package/examples/game/libs/SOURCES.md +31 -0
- package/examples/game/libs/Shift/init.luau +238 -0
- package/examples/game/libs/Spark/init.luau +487 -0
- package/examples/game/libs/Stage/init.luau +178 -0
- package/examples/game/libs/Sweep/init.luau +259 -0
- package/examples/game/libs/Trace/init.luau +213 -0
- package/examples/game/libs/Ward/init.luau +211 -0
- package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau +29 -0
- package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau.map.json +13 -0
- package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau +83 -0
- package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau +18 -0
- package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau +14 -0
- package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau +15 -0
- package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau +50 -0
- package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau.map.json +13 -0
- package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau +12 -0
- package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau.map.json +13 -0
- package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau +16 -0
- package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau.map.json +13 -0
- package/examples/game/src/ReplicatedStorage/Shared/Net/Net.clh +26 -0
- package/examples/game/src/ServerScriptService/Boot/DataBoot.server.clpp +1 -1
- package/examples/game/src/ServerScriptService/Handlers/PlayerHandler.server.clpp +1 -1
- package/examples/game/stylua.toml +9 -0
- package/generated/api/build-profile.js +115 -0
- package/generated/api/cache.js +44 -0
- package/generated/api/coverage.js +32 -0
- package/generated/api/diff.js +125 -0
- package/generated/api/generators/clpp-headers.js +353 -0
- package/generated/api/generators/docs-reference.js +7 -0
- package/generated/api/generators/lsp-index.js +81 -0
- package/generated/api/generators/luau-defs.js +94 -0
- package/generated/api/ide.js +76 -0
- package/generated/api/identifier.js +47 -0
- package/generated/api/index.js +324 -0
- package/generated/api/loader.js +57 -0
- package/generated/api/merge.js +88 -0
- package/generated/api/model.js +5 -0
- package/generated/api/normalize.js +231 -0
- package/generated/api/overrides-validate.js +58 -0
- package/generated/api/perf.js +12 -0
- package/generated/api/registry.js +136 -0
- package/generated/api/release.js +44 -0
- package/generated/api/resolver.js +250 -0
- package/generated/api/sources/aux-types-diff.js +75 -0
- package/generated/api/sources/client-tracker.js +11 -0
- package/generated/api/sources/creator-docs.js +42 -0
- package/generated/api/sources/luau-types.js +34 -0
- package/generated/api/sources/mini-dump.js +17 -0
- package/generated/api/sources/studio-api.js +8 -0
- package/generated/api/sources/studio-apiv2.js +11 -0
- package/generated/api/sources/studio-full-api.js +8 -0
- package/generated/api/studio-smoke.js +80 -0
- package/generated/api/type-parse.js +49 -0
- package/generated/api/understander.js +51 -0
- package/generated/api/validate.js +135 -0
- package/generated/api-cli.js +421 -0
- package/generated/cli.js +16 -5
- package/generated/clpp/contract.js +3 -3
- package/generated/clpp/format-luau.js +236 -0
- package/generated/clpp/index.js +13 -1
- package/generated/clpp/modules.js +227 -0
- package/generated/clpp/postprocess.js +86 -5
- package/generated/clpp/rewrite-janitor.js +145 -0
- package/generated/clpp/runner.js +14 -2
- package/generated/compile.js +82 -0
- package/generated/flare/parse.js +12 -1
- package/generated/intellisense.js +57 -1
- package/generated/native/index.js +217 -16
- package/generated/target/authority-check.js +136 -0
- package/generated/target/authority-graph.js +74 -0
- package/generated/target/build-cache.js +112 -0
- package/generated/target/capabilities.js +89 -0
- package/generated/target/capability-profile.js +30 -0
- package/generated/target/component-contracts.js +60 -0
- package/generated/target/context-check.js +160 -0
- package/generated/target/datamodel-check.js +170 -0
- package/generated/target/datamodel-generate.js +74 -0
- package/generated/target/datamodel.js +233 -0
- package/generated/target/diagnostics.js +63 -0
- package/generated/target/doctor.js +152 -0
- package/generated/target/flare-version.js +58 -0
- package/generated/target/get-service.js +69 -0
- package/generated/target/lifetime-check.js +47 -0
- package/generated/target/luau-stamp.js +39 -0
- package/generated/target/optimizer-advise.js +88 -0
- package/generated/target/optimizer-apply.js +44 -0
- package/generated/target/optimizer-soa.js +254 -0
- package/generated/target/parallel-check.js +136 -0
- package/generated/target/pgo.js +148 -0
- package/generated/target/project-docs.js +69 -0
- package/generated/target/project-graph.js +71 -0
- package/generated/target/roblox.js +63 -0
- package/generated/target/security-check.js +41 -0
- package/generated/target/source-map.js +25 -0
- package/generated/target/studio-bridge.js +112 -0
- package/generated/utils/project.js +178 -8
- package/generated/utils/rojo-mapper.js +11 -3
- package/include/clpp/datatypes.clh +337 -373
- package/include/clpp/generated/enums.clh +1 -1
- package/include/clpp/generated/instances.clh +41135 -41064
- package/include/clpp/libs/axiom.clh +1 -1
- package/include/clpp/libs/hive.clh +1 -0
- package/include/clpp/libs/keep.clh +2 -0
- package/include/clpp/libs/math.clh +14 -0
- package/include/clpp/libs/spring.clh +17 -0
- package/include/clpp/libs/ward.clh +1 -0
- package/include/clpp/roblox.clh +3 -4
- package/package.json +10 -3
- package/plugins/CluauppNav/Plugin.luau +207 -0
- package/plugins/CluauppNav/ProfileLogger.luau +27 -0
- package/plugins/CluauppNav/README.md +24 -0
- package/runtime/Axiom/init.luau +10 -7
- package/runtime/Coil/init.luau +8 -2
- package/runtime/Crest/init.luau +1 -0
- package/runtime/Flare/init.luau +2 -1
- package/runtime/Gleam/init.luau +15 -4
- package/runtime/Hive/init.luau +36 -14
- package/runtime/Pin/init.luau +5 -2
- package/runtime/Roster/init.luau +2 -0
- package/runtime/Spark/init.luau +3 -0
- package/runtime/Sweep/init.luau +2 -0
- package/runtime/Trace/init.luau +3 -0
- package/runtime/Ward/init.luau +38 -5
- package/scripts/postinstall-editor.js +17 -0
- package/skills/README.md +13 -0
- package/skills/clpp-hive-flare/SKILL.md +79 -0
- package/skills/clpp-language/SKILL.md +123 -0
- package/skills/clpp-language/compiler.md +89 -0
- package/skills/clpp-style/SKILL.md +95 -0
- package/src/api/build-profile.ts +138 -0
- package/src/api/cache.ts +45 -0
- package/src/api/coverage.ts +46 -0
- package/src/api/diff.ts +143 -0
- package/src/api/generators/clpp-headers.ts +377 -0
- package/src/api/generators/docs-reference.ts +11 -0
- package/src/api/generators/lsp-index.ts +106 -0
- package/src/api/generators/luau-defs.ts +98 -0
- package/src/api/ide.ts +87 -0
- package/src/api/identifier.ts +47 -0
- package/src/api/index.ts +269 -0
- package/src/api/loader.ts +60 -0
- package/src/api/merge.ts +126 -0
- package/src/api/model.ts +283 -0
- package/src/api/normalize.ts +257 -0
- package/src/api/overrides-validate.ts +58 -0
- package/src/api/perf.ts +15 -0
- package/src/api/registry.ts +162 -0
- package/src/api/release.ts +47 -0
- package/src/api/resolver.ts +255 -0
- package/src/api/sources/aux-types-diff.ts +81 -0
- package/src/api/sources/client-tracker.ts +10 -0
- package/src/api/sources/creator-docs.ts +37 -0
- package/src/api/sources/luau-types.ts +30 -0
- package/src/api/sources/mini-dump.ts +50 -0
- package/src/api/sources/studio-api.ts +7 -0
- package/src/api/sources/studio-apiv2.ts +10 -0
- package/src/api/sources/studio-full-api.ts +7 -0
- package/src/api/studio-smoke.ts +82 -0
- package/src/api/type-parse.ts +48 -0
- package/src/api/understander.ts +72 -0
- package/src/api/validate.ts +160 -0
- package/src/api-cli.ts +493 -0
- package/src/api.generated.js +37 -22
- package/src/cli.ts +21 -6
- package/src/clpp/contract.ts +34 -3
- package/src/clpp/format-luau.ts +262 -0
- package/src/clpp/index.ts +13 -2
- package/src/clpp/modules.ts +252 -0
- package/src/clpp/postprocess.ts +100 -5
- package/src/clpp/rewrite-janitor.ts +156 -0
- package/src/clpp/runner.ts +14 -2
- package/src/compile.ts +87 -0
- package/src/flare/parse.ts +14 -1
- package/src/flare/types.ts +2 -0
- package/src/intellisense.ts +58 -1
- package/src/native/index.ts +225 -16
- package/src/target/authority-check.ts +162 -0
- package/src/target/authority-graph.ts +80 -0
- package/src/target/build-cache.ts +129 -0
- package/src/target/capabilities.ts +115 -0
- package/src/target/capability-profile.ts +25 -0
- package/src/target/component-contracts.ts +64 -0
- package/src/target/context-check.ts +177 -0
- package/src/target/datamodel-check.ts +188 -0
- package/src/target/datamodel-generate.ts +78 -0
- package/src/target/datamodel.ts +261 -0
- package/src/target/diagnostics.ts +67 -0
- package/src/target/doctor.ts +171 -0
- package/src/target/flare-version.ts +61 -0
- package/src/target/get-service.ts +85 -0
- package/src/target/lifetime-check.ts +45 -0
- package/src/target/luau-stamp.ts +33 -0
- package/src/target/optimizer-advise.ts +93 -0
- package/src/target/optimizer-apply.ts +63 -0
- package/src/target/optimizer-soa.ts +270 -0
- package/src/target/parallel-check.ts +135 -0
- package/src/target/pgo.ts +157 -0
- package/src/target/project-docs.ts +68 -0
- package/src/target/project-graph.ts +75 -0
- package/src/target/roblox.ts +78 -0
- package/src/target/security-check.ts +40 -0
- package/src/target/source-map.ts +36 -0
- package/src/target/studio-bridge.ts +140 -0
- package/src/types.ts +14 -0
- package/src/utils/project.ts +183 -9
- package/src/utils/rojo-mapper.ts +12 -3
- package/stylua.toml +9 -0
- package/templates/game/.vscode/settings.json +7 -1
- package/templates/game/include/clpp/datatypes.clh +337 -373
- package/templates/game/include/clpp/generated/enums.clh +1 -1
- package/templates/game/include/clpp/generated/instances.clh +41135 -41064
- package/templates/game/include/clpp/libs/axiom.clh +1 -1
- package/templates/game/include/clpp/libs/ward.clh +1 -0
- package/templates/game/include/clpp/roblox.clh +3 -4
- package/templates/game/src/ServerScriptService/Boot/DataBoot.server.clpp +1 -1
- package/templates/game/src/ServerScriptService/Handlers/PlayerHandler.server.clpp +1 -1
- package/templates/game/stylua.toml +9 -0
|
@@ -0,0 +1,729 @@
|
|
|
1
|
+
--!native
|
|
2
|
+
--!optimize 2
|
|
3
|
+
--!strict
|
|
4
|
+
-- Gleam — Cluaupp declarative UI (Vide-style sources + create). Scope = Sweep.
|
|
5
|
+
|
|
6
|
+
local RunService = game:GetService("RunService")
|
|
7
|
+
|
|
8
|
+
local Sweep = require(script.Parent.Sweep)
|
|
9
|
+
local Coil = require(script.Parent.Coil)
|
|
10
|
+
|
|
11
|
+
local Gleam = {}
|
|
12
|
+
Gleam.__index = Gleam
|
|
13
|
+
|
|
14
|
+
type Scope = {
|
|
15
|
+
Sweep: any,
|
|
16
|
+
Deps: { [any]: boolean },
|
|
17
|
+
Alive: boolean,
|
|
18
|
+
Tracking: boolean,
|
|
19
|
+
Fn: () -> (),
|
|
20
|
+
Running: boolean,
|
|
21
|
+
Dirty: boolean,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Source<T> = {
|
|
25
|
+
Get: (self: Source<T>) -> T,
|
|
26
|
+
Set: (self: Source<T>, value: T) -> (),
|
|
27
|
+
Listen: (self: Source<T>, fn: () -> ()) -> () -> (),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type Action = {
|
|
31
|
+
_gleamAction: boolean,
|
|
32
|
+
Run: (instance: Instance) -> (),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
local stack: { Scope } = {}
|
|
36
|
+
local untrackDepth = 0
|
|
37
|
+
local batchDepth = 0
|
|
38
|
+
local flushing = false
|
|
39
|
+
local pending: { [Scope]: boolean } = {}
|
|
40
|
+
|
|
41
|
+
local SETTLE = 0.0005
|
|
42
|
+
|
|
43
|
+
local ACTION_FLAG = "_gleamAction"
|
|
44
|
+
-- cluaupp: weak-table Sweep (Instance cannot take _gleamSweep)
|
|
45
|
+
local sweeps: { [Instance]: any } = setmetatable({}, { __mode = "k" }) :: any
|
|
46
|
+
|
|
47
|
+
local function getSweep(instance: Instance): any?
|
|
48
|
+
return sweeps[instance]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
local function setSweep(instance: Instance, sweep: any)
|
|
52
|
+
sweeps[instance] = sweep
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
local function peek(): Scope?
|
|
56
|
+
return stack[#stack]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
local function push(scope: Scope)
|
|
60
|
+
table.insert(stack, scope)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
local function pop()
|
|
64
|
+
table.remove(stack)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
local function isSource(value: any): boolean
|
|
68
|
+
return typeof(value) == "table" and typeof(value.Get) == "function" and typeof(value.Set) == "function"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
local function isAction(value: any): boolean
|
|
72
|
+
return typeof(value) == "table" and value[ACTION_FLAG] == true and typeof(value.Run) == "function"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
local function detach(scope: Scope)
|
|
76
|
+
for src in scope.Deps do
|
|
77
|
+
local effects = src._effects
|
|
78
|
+
if effects then
|
|
79
|
+
effects[scope] = nil
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
table.clear(scope.Deps)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
local function teardown(scope: Scope)
|
|
86
|
+
if not scope.Alive then
|
|
87
|
+
return
|
|
88
|
+
end
|
|
89
|
+
scope.Alive = false
|
|
90
|
+
pending[scope] = nil
|
|
91
|
+
detach(scope)
|
|
92
|
+
scope.Sweep:Destroy()
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
local runScope: (scope: Scope) -> ()
|
|
96
|
+
|
|
97
|
+
local function flush()
|
|
98
|
+
if flushing or batchDepth > 0 then
|
|
99
|
+
return
|
|
100
|
+
end
|
|
101
|
+
flushing = true
|
|
102
|
+
local n = 0
|
|
103
|
+
local err: any = nil
|
|
104
|
+
while true do
|
|
105
|
+
local scope = next(pending)
|
|
106
|
+
if not scope then
|
|
107
|
+
break
|
|
108
|
+
end
|
|
109
|
+
pending[scope] = nil
|
|
110
|
+
n += 1
|
|
111
|
+
if n > 1000 then
|
|
112
|
+
err = "Gleam effect loop"
|
|
113
|
+
break
|
|
114
|
+
end
|
|
115
|
+
local ok, runErr = pcall(runScope, scope)
|
|
116
|
+
if not ok then
|
|
117
|
+
err = runErr
|
|
118
|
+
break
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
flushing = false
|
|
122
|
+
if err ~= nil then
|
|
123
|
+
error(err)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
local function schedule(scope: Scope)
|
|
128
|
+
if not scope.Alive then
|
|
129
|
+
return
|
|
130
|
+
end
|
|
131
|
+
if scope.Running then
|
|
132
|
+
scope.Dirty = true
|
|
133
|
+
return
|
|
134
|
+
end
|
|
135
|
+
pending[scope] = true
|
|
136
|
+
flush()
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
runScope = function(scope: Scope)
|
|
140
|
+
if not scope.Alive then
|
|
141
|
+
return
|
|
142
|
+
end
|
|
143
|
+
if scope.Running then
|
|
144
|
+
scope.Dirty = true
|
|
145
|
+
return
|
|
146
|
+
end
|
|
147
|
+
scope.Running = true
|
|
148
|
+
repeat
|
|
149
|
+
scope.Dirty = false
|
|
150
|
+
detach(scope)
|
|
151
|
+
scope.Sweep:Cleanup()
|
|
152
|
+
push(scope)
|
|
153
|
+
local ok, err = pcall(scope.Fn)
|
|
154
|
+
pop()
|
|
155
|
+
if not ok then
|
|
156
|
+
scope.Running = false
|
|
157
|
+
error(err)
|
|
158
|
+
end
|
|
159
|
+
until not scope.Dirty or not scope.Alive
|
|
160
|
+
scope.Running = false
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
local function subscribe(src: any, scope: Scope)
|
|
164
|
+
if scope.Deps[src] then
|
|
165
|
+
return
|
|
166
|
+
end
|
|
167
|
+
scope.Deps[src] = true
|
|
168
|
+
src._effects[scope] = true
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
function Gleam.Source<T>(initial: T): Source<T>
|
|
172
|
+
local src = {
|
|
173
|
+
_value = initial,
|
|
174
|
+
_effects = {} :: { [Scope]: boolean },
|
|
175
|
+
_listens = {} :: { () -> () },
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function src:Get(): T
|
|
179
|
+
local scope = peek()
|
|
180
|
+
if scope and scope.Tracking and untrackDepth == 0 then
|
|
181
|
+
subscribe(src, scope)
|
|
182
|
+
end
|
|
183
|
+
return src._value
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
function src:Set(nextValue: T)
|
|
187
|
+
if src._value == nextValue then
|
|
188
|
+
return
|
|
189
|
+
end
|
|
190
|
+
src._value = nextValue
|
|
191
|
+
batchDepth += 1
|
|
192
|
+
local ok, err = pcall(function()
|
|
193
|
+
for scope in src._effects do
|
|
194
|
+
schedule(scope)
|
|
195
|
+
end
|
|
196
|
+
local listens = table.clone(src._listens)
|
|
197
|
+
for _, fn in listens do
|
|
198
|
+
fn()
|
|
199
|
+
end
|
|
200
|
+
end)
|
|
201
|
+
batchDepth -= 1
|
|
202
|
+
if not ok then
|
|
203
|
+
flush()
|
|
204
|
+
error(err)
|
|
205
|
+
end
|
|
206
|
+
flush()
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
function src:Listen(fn: () -> ()): () -> ()
|
|
210
|
+
table.insert(src._listens, fn)
|
|
211
|
+
return function()
|
|
212
|
+
local index = table.find(src._listens, fn)
|
|
213
|
+
if index then
|
|
214
|
+
table.remove(src._listens, index)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
return src :: any
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
function Gleam.Effect(fn: () -> ())
|
|
223
|
+
local parent = peek()
|
|
224
|
+
local sweep = Sweep.new()
|
|
225
|
+
local scope: Scope = {
|
|
226
|
+
Sweep = sweep,
|
|
227
|
+
Deps = {},
|
|
228
|
+
Alive = true,
|
|
229
|
+
Tracking = true,
|
|
230
|
+
Fn = fn,
|
|
231
|
+
Running = false,
|
|
232
|
+
Dirty = false,
|
|
233
|
+
}
|
|
234
|
+
if parent then
|
|
235
|
+
parent.Sweep:Add(function()
|
|
236
|
+
teardown(scope)
|
|
237
|
+
end, true)
|
|
238
|
+
end
|
|
239
|
+
runScope(scope)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
function Gleam.Derive<T>(compute: () -> T): Source<T>
|
|
243
|
+
local derived = Gleam.Source((nil :: any) :: T)
|
|
244
|
+
Gleam.Effect(function()
|
|
245
|
+
derived:Set(compute())
|
|
246
|
+
end)
|
|
247
|
+
return derived
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
function Gleam.Untrack<T>(fn: () -> T): T
|
|
251
|
+
untrackDepth += 1
|
|
252
|
+
local ok, result = pcall(fn)
|
|
253
|
+
untrackDepth -= 1
|
|
254
|
+
if not ok then
|
|
255
|
+
error(result)
|
|
256
|
+
end
|
|
257
|
+
return result
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
function Gleam.Batch(fn: () -> ())
|
|
261
|
+
batchDepth += 1
|
|
262
|
+
local ok, err = pcall(fn)
|
|
263
|
+
batchDepth -= 1
|
|
264
|
+
if not ok then
|
|
265
|
+
flush()
|
|
266
|
+
error(err)
|
|
267
|
+
end
|
|
268
|
+
flush()
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
function Gleam.Cleanup(fn: () -> ())
|
|
272
|
+
local scope = peek()
|
|
273
|
+
if scope then
|
|
274
|
+
scope.Sweep:Add(fn, true)
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
local function destroyNode(node: any)
|
|
279
|
+
if node == nil then
|
|
280
|
+
return
|
|
281
|
+
end
|
|
282
|
+
if typeof(node) == "Instance" then
|
|
283
|
+
local sweep = getSweep(node)
|
|
284
|
+
if sweep then
|
|
285
|
+
sweeps[node] = nil
|
|
286
|
+
sweep:Destroy()
|
|
287
|
+
else
|
|
288
|
+
node:Destroy()
|
|
289
|
+
end
|
|
290
|
+
return
|
|
291
|
+
end
|
|
292
|
+
if typeof(node) == "table" then
|
|
293
|
+
if isSource(node) then
|
|
294
|
+
destroyNode(node:Get())
|
|
295
|
+
return
|
|
296
|
+
end
|
|
297
|
+
for _, child in node do
|
|
298
|
+
destroyNode(child)
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
local function bindProperty(instance: Instance, key: any, value: any)
|
|
304
|
+
if isSource(value) then
|
|
305
|
+
Gleam.Effect(function()
|
|
306
|
+
(instance :: any)[key] = value:Get()
|
|
307
|
+
end)
|
|
308
|
+
return
|
|
309
|
+
end
|
|
310
|
+
if typeof(value) == "function" then
|
|
311
|
+
local ok, signal = pcall(function()
|
|
312
|
+
return (instance :: any)[key]
|
|
313
|
+
end)
|
|
314
|
+
if ok and typeof(signal) == "RBXScriptSignal" then
|
|
315
|
+
local scope = peek()
|
|
316
|
+
if scope then
|
|
317
|
+
scope.Sweep:Add(signal:Connect(value))
|
|
318
|
+
else
|
|
319
|
+
signal:Connect(value)
|
|
320
|
+
end
|
|
321
|
+
return
|
|
322
|
+
end
|
|
323
|
+
Gleam.Effect(function()
|
|
324
|
+
(instance :: any)[key] = value()
|
|
325
|
+
end)
|
|
326
|
+
return
|
|
327
|
+
end
|
|
328
|
+
(instance :: any)[key] = value
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
local function unparentNode(node: any, parent: Instance)
|
|
332
|
+
if typeof(node) == "Instance" then
|
|
333
|
+
if node.Parent == parent then
|
|
334
|
+
node.Parent = nil
|
|
335
|
+
end
|
|
336
|
+
return
|
|
337
|
+
end
|
|
338
|
+
if typeof(node) == "table" and not isSource(node) and not isAction(node) then
|
|
339
|
+
for _, item in node do
|
|
340
|
+
unparentNode(item, parent)
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
local adopt: (parent: Instance, child: any) -> ()
|
|
346
|
+
|
|
347
|
+
adopt = function(parent: Instance, child: any)
|
|
348
|
+
if child == nil then
|
|
349
|
+
return
|
|
350
|
+
end
|
|
351
|
+
if isAction(child) then
|
|
352
|
+
(child :: Action).Run(parent)
|
|
353
|
+
return
|
|
354
|
+
end
|
|
355
|
+
if isSource(child) then
|
|
356
|
+
Gleam.Effect(function()
|
|
357
|
+
local current = child:Get()
|
|
358
|
+
Gleam.Cleanup(function()
|
|
359
|
+
unparentNode(current, parent)
|
|
360
|
+
end)
|
|
361
|
+
adopt(parent, current)
|
|
362
|
+
end)
|
|
363
|
+
return
|
|
364
|
+
end
|
|
365
|
+
if typeof(child) == "function" then
|
|
366
|
+
Gleam.Effect(function()
|
|
367
|
+
local current = child()
|
|
368
|
+
Gleam.Cleanup(function()
|
|
369
|
+
unparentNode(current, parent)
|
|
370
|
+
end)
|
|
371
|
+
adopt(parent, current)
|
|
372
|
+
end)
|
|
373
|
+
return
|
|
374
|
+
end
|
|
375
|
+
if typeof(child) == "Instance" then
|
|
376
|
+
child.Parent = parent
|
|
377
|
+
return
|
|
378
|
+
end
|
|
379
|
+
if typeof(child) == "table" then
|
|
380
|
+
for _, item in child do
|
|
381
|
+
adopt(parent, item)
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
local function applyProps(instance: Instance, props: { [any]: any })
|
|
387
|
+
local parentValue: any = nil
|
|
388
|
+
local actions: { Action } = {}
|
|
389
|
+
local children: { any } = {}
|
|
390
|
+
|
|
391
|
+
for key, value in props do
|
|
392
|
+
if isAction(value) then
|
|
393
|
+
table.insert(actions, value)
|
|
394
|
+
elseif key == "Parent" then
|
|
395
|
+
parentValue = value
|
|
396
|
+
elseif key == "Children" or typeof(key) == "number" then
|
|
397
|
+
table.insert(children, value)
|
|
398
|
+
else
|
|
399
|
+
bindProperty(instance, key, value)
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
for _, child in children do
|
|
404
|
+
adopt(instance, child)
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
for _, action in actions do
|
|
408
|
+
action.Run(instance)
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
if parentValue ~= nil then
|
|
412
|
+
bindProperty(instance, "Parent", parentValue)
|
|
413
|
+
end
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
local function pushSweepScope(sweep: any): Scope
|
|
417
|
+
local scope: Scope = {
|
|
418
|
+
Sweep = sweep,
|
|
419
|
+
Deps = {},
|
|
420
|
+
Alive = true,
|
|
421
|
+
Tracking = false,
|
|
422
|
+
Fn = function() end,
|
|
423
|
+
Running = false,
|
|
424
|
+
Dirty = false,
|
|
425
|
+
}
|
|
426
|
+
push(scope)
|
|
427
|
+
return scope
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
function Gleam.Create(className: string, props: { [any]: any }?): Instance
|
|
431
|
+
local instance = Instance.new(className)
|
|
432
|
+
local sweep = Sweep.new()
|
|
433
|
+
sweep:Add(instance, "Destroy")
|
|
434
|
+
sweep:LinkToInstance(instance)
|
|
435
|
+
setSweep(instance, sweep)
|
|
436
|
+
|
|
437
|
+
local parent = peek()
|
|
438
|
+
pushSweepScope(sweep)
|
|
439
|
+
if props then
|
|
440
|
+
applyProps(instance, props)
|
|
441
|
+
end
|
|
442
|
+
pop()
|
|
443
|
+
|
|
444
|
+
if parent then
|
|
445
|
+
parent.Sweep:Add(function()
|
|
446
|
+
sweep:Destroy()
|
|
447
|
+
end, true)
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
return instance
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
function Gleam.TextButton(props: { [any]: any }?): TextButton
|
|
454
|
+
return Gleam.Create("TextButton", props) :: TextButton
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
function Gleam.TextLabel(props: { [any]: any }?): TextLabel
|
|
458
|
+
return Gleam.Create("TextLabel", props) :: TextLabel
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
function Gleam.Frame(props: { [any]: any }?): Frame
|
|
462
|
+
return Gleam.Create("Frame", props) :: Frame
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
function Gleam.ScreenGui(props: { [any]: any }?): ScreenGui
|
|
466
|
+
return Gleam.Create("ScreenGui", props) :: ScreenGui
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
function Gleam.ImageLabel(props: { [any]: any }?): ImageLabel
|
|
470
|
+
return Gleam.Create("ImageLabel", props) :: ImageLabel
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
function Gleam.ScrollingFrame(props: { [any]: any }?): ScrollingFrame
|
|
474
|
+
return Gleam.Create("ScrollingFrame", props) :: ScrollingFrame
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
function Gleam.List(...: Instance): { Instance }
|
|
478
|
+
return { ... }
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
function Gleam.Mount(instance: Instance, parent: Instance): () -> ()
|
|
482
|
+
instance.Parent = parent
|
|
483
|
+
local function unmount()
|
|
484
|
+
destroyNode(instance)
|
|
485
|
+
end
|
|
486
|
+
local scope = peek()
|
|
487
|
+
if scope then
|
|
488
|
+
scope.Sweep:Add(unmount, true)
|
|
489
|
+
end
|
|
490
|
+
return unmount
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
function Gleam.Root(fn: () -> ()): () -> ()
|
|
494
|
+
local sweep = Sweep.new()
|
|
495
|
+
local scope: Scope = {
|
|
496
|
+
Sweep = sweep,
|
|
497
|
+
Deps = {},
|
|
498
|
+
Alive = true,
|
|
499
|
+
Tracking = false,
|
|
500
|
+
Fn = fn,
|
|
501
|
+
Running = false,
|
|
502
|
+
Dirty = false,
|
|
503
|
+
}
|
|
504
|
+
push(scope)
|
|
505
|
+
local ok, err = pcall(fn)
|
|
506
|
+
pop()
|
|
507
|
+
if not ok then
|
|
508
|
+
teardown(scope)
|
|
509
|
+
error(err)
|
|
510
|
+
end
|
|
511
|
+
return function()
|
|
512
|
+
teardown(scope)
|
|
513
|
+
end
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
function Gleam.Show<T>(source: Source<T>, render: (value: T) -> Instance?): Source<Instance?>
|
|
517
|
+
local holder = Gleam.Source(nil :: Instance?)
|
|
518
|
+
Gleam.Effect(function()
|
|
519
|
+
local produced: Instance? = render(source:Get())
|
|
520
|
+
Gleam.Cleanup(function()
|
|
521
|
+
destroyNode(produced)
|
|
522
|
+
end)
|
|
523
|
+
holder:Set(produced)
|
|
524
|
+
end)
|
|
525
|
+
return holder
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
function Gleam.Switch<T>(source: Source<T>, map: { [any]: () -> Instance }): Source<Instance?>
|
|
529
|
+
return Gleam.Show(source, function(value)
|
|
530
|
+
local render = map[value]
|
|
531
|
+
if render then
|
|
532
|
+
return render()
|
|
533
|
+
end
|
|
534
|
+
return nil
|
|
535
|
+
end)
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
function Gleam.Indexes<T>(source: Source<{ T }>, render: (item: Source<T>, index: number) -> Instance): Source<{ Instance }>
|
|
539
|
+
local holder = Gleam.Source({} :: { Instance })
|
|
540
|
+
Gleam.Effect(function()
|
|
541
|
+
local items = source:Get()
|
|
542
|
+
local result: { Instance } = {}
|
|
543
|
+
if typeof(items) == "table" then
|
|
544
|
+
for index, value in items do
|
|
545
|
+
local item = Gleam.Source(value)
|
|
546
|
+
result[index] = render(item, index)
|
|
547
|
+
end
|
|
548
|
+
end
|
|
549
|
+
Gleam.Cleanup(function()
|
|
550
|
+
destroyNode(result)
|
|
551
|
+
end)
|
|
552
|
+
holder:Set(result)
|
|
553
|
+
end)
|
|
554
|
+
return holder
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
function Gleam.Values<T>(source: Source<{ T }>, render: (item: Source<T>, value: T) -> Instance): Source<{ Instance }>
|
|
558
|
+
local holder = Gleam.Source({} :: { Instance })
|
|
559
|
+
Gleam.Effect(function()
|
|
560
|
+
local items = source:Get()
|
|
561
|
+
local result: { Instance } = {}
|
|
562
|
+
if typeof(items) == "table" then
|
|
563
|
+
for index, value in items do
|
|
564
|
+
local item = Gleam.Source(value)
|
|
565
|
+
result[index] = render(item, value)
|
|
566
|
+
end
|
|
567
|
+
end
|
|
568
|
+
Gleam.Cleanup(function()
|
|
569
|
+
destroyNode(result)
|
|
570
|
+
end)
|
|
571
|
+
holder:Set(result)
|
|
572
|
+
end)
|
|
573
|
+
return holder
|
|
574
|
+
end
|
|
575
|
+
|
|
576
|
+
local function coilSettled(spring: any): boolean
|
|
577
|
+
return math.abs(spring.Position - spring.Goal) <= SETTLE and math.abs(spring.Velocity) <= SETTLE
|
|
578
|
+
end
|
|
579
|
+
|
|
580
|
+
local function makeCoils(value: any, damping: number, speed: number): ({ any }?, (coils: { any }) -> any, (goal: any, coils: { any }) -> ())
|
|
581
|
+
local kind = typeof(value)
|
|
582
|
+
if kind == "number" then
|
|
583
|
+
return { Coil.new(damping, speed, value) }, function(coils)
|
|
584
|
+
return coils[1]:Get()
|
|
585
|
+
end, function(goal, coils)
|
|
586
|
+
coils[1]:Set(goal)
|
|
587
|
+
end
|
|
588
|
+
end
|
|
589
|
+
if kind == "Vector2" then
|
|
590
|
+
return {
|
|
591
|
+
Coil.new(damping, speed, value.X),
|
|
592
|
+
Coil.new(damping, speed, value.Y),
|
|
593
|
+
}, function(coils)
|
|
594
|
+
return Vector2.new(coils[1]:Get(), coils[2]:Get())
|
|
595
|
+
end, function(goal, coils)
|
|
596
|
+
coils[1]:Set(goal.X)
|
|
597
|
+
coils[2]:Set(goal.Y)
|
|
598
|
+
end
|
|
599
|
+
end
|
|
600
|
+
if kind == "Vector3" then
|
|
601
|
+
return {
|
|
602
|
+
Coil.new(damping, speed, value.X),
|
|
603
|
+
Coil.new(damping, speed, value.Y),
|
|
604
|
+
Coil.new(damping, speed, value.Z),
|
|
605
|
+
}, function(coils)
|
|
606
|
+
return Vector3.new(coils[1]:Get(), coils[2]:Get(), coils[3]:Get())
|
|
607
|
+
end, function(goal, coils)
|
|
608
|
+
coils[1]:Set(goal.X)
|
|
609
|
+
coils[2]:Set(goal.Y)
|
|
610
|
+
coils[3]:Set(goal.Z)
|
|
611
|
+
end
|
|
612
|
+
end
|
|
613
|
+
if kind == "UDim2" then
|
|
614
|
+
return {
|
|
615
|
+
Coil.new(damping, speed, value.X.Scale),
|
|
616
|
+
Coil.new(damping, speed, value.X.Offset),
|
|
617
|
+
Coil.new(damping, speed, value.Y.Scale),
|
|
618
|
+
Coil.new(damping, speed, value.Y.Offset),
|
|
619
|
+
}, function(coils)
|
|
620
|
+
return UDim2.new(coils[1]:Get(), coils[2]:Get(), coils[3]:Get(), coils[4]:Get())
|
|
621
|
+
end, function(goal, coils)
|
|
622
|
+
coils[1]:Set(goal.X.Scale)
|
|
623
|
+
coils[2]:Set(goal.X.Offset)
|
|
624
|
+
coils[3]:Set(goal.Y.Scale)
|
|
625
|
+
coils[4]:Set(goal.Y.Offset)
|
|
626
|
+
end
|
|
627
|
+
end
|
|
628
|
+
if kind == "Color3" then
|
|
629
|
+
return {
|
|
630
|
+
Coil.new(damping, speed, value.R),
|
|
631
|
+
Coil.new(damping, speed, value.G),
|
|
632
|
+
Coil.new(damping, speed, value.B),
|
|
633
|
+
}, function(coils)
|
|
634
|
+
return Color3.new(coils[1]:Get(), coils[2]:Get(), coils[3]:Get())
|
|
635
|
+
end, function(goal, coils)
|
|
636
|
+
coils[1]:Set(goal.R)
|
|
637
|
+
coils[2]:Set(goal.G)
|
|
638
|
+
coils[3]:Set(goal.B)
|
|
639
|
+
end
|
|
640
|
+
end
|
|
641
|
+
return nil, function()
|
|
642
|
+
return value
|
|
643
|
+
end, function() end
|
|
644
|
+
end
|
|
645
|
+
|
|
646
|
+
function Gleam.Spring<T>(source: Source<T>, speed: number?, damping: number?): Source<T>
|
|
647
|
+
local freq = speed or 8
|
|
648
|
+
local damp = damping or 1
|
|
649
|
+
local start = Gleam.Untrack(function()
|
|
650
|
+
return source:Get()
|
|
651
|
+
end)
|
|
652
|
+
local derived = Gleam.Source(start)
|
|
653
|
+
local coils, unpackPos, packGoal = makeCoils(start, damp, freq)
|
|
654
|
+
|
|
655
|
+
if coils == nil then
|
|
656
|
+
Gleam.Effect(function()
|
|
657
|
+
derived:Set(source:Get())
|
|
658
|
+
end)
|
|
659
|
+
return derived
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
Gleam.Effect(function()
|
|
663
|
+
local goal = source:Get()
|
|
664
|
+
packGoal(goal, coils)
|
|
665
|
+
local allSettled = true
|
|
666
|
+
for _, spring in coils do
|
|
667
|
+
if not coilSettled(spring) then
|
|
668
|
+
allSettled = false
|
|
669
|
+
break
|
|
670
|
+
end
|
|
671
|
+
end
|
|
672
|
+
if allSettled then
|
|
673
|
+
derived:Set(unpackPos(coils))
|
|
674
|
+
return
|
|
675
|
+
end
|
|
676
|
+
local conn: RBXScriptConnection
|
|
677
|
+
conn = RunService.Heartbeat:Connect(function(dt)
|
|
678
|
+
local done = true
|
|
679
|
+
for _, spring in coils do
|
|
680
|
+
spring:Step(dt)
|
|
681
|
+
if not coilSettled(spring) then
|
|
682
|
+
done = false
|
|
683
|
+
end
|
|
684
|
+
end
|
|
685
|
+
if done then
|
|
686
|
+
for _, spring in coils do
|
|
687
|
+
spring.Position = spring.Goal
|
|
688
|
+
spring.Velocity = 0
|
|
689
|
+
end
|
|
690
|
+
derived:Set(unpackPos(coils))
|
|
691
|
+
if conn.Connected then
|
|
692
|
+
conn:Disconnect()
|
|
693
|
+
end
|
|
694
|
+
else
|
|
695
|
+
derived:Set(unpackPos(coils))
|
|
696
|
+
end
|
|
697
|
+
end)
|
|
698
|
+
local scope = peek()
|
|
699
|
+
if scope then
|
|
700
|
+
scope.Sweep:Add(conn)
|
|
701
|
+
end
|
|
702
|
+
end)
|
|
703
|
+
|
|
704
|
+
return derived
|
|
705
|
+
end
|
|
706
|
+
|
|
707
|
+
function Gleam.Apply(instance: Instance): (props: { [any]: any }) -> Instance
|
|
708
|
+
return function(props)
|
|
709
|
+
local sweep = getSweep(instance)
|
|
710
|
+
if not sweep then
|
|
711
|
+
sweep = Sweep.new()
|
|
712
|
+
sweep:LinkToInstance(instance)
|
|
713
|
+
setSweep(instance, sweep)
|
|
714
|
+
end
|
|
715
|
+
pushSweepScope(sweep)
|
|
716
|
+
applyProps(instance, props)
|
|
717
|
+
pop()
|
|
718
|
+
return instance
|
|
719
|
+
end
|
|
720
|
+
end
|
|
721
|
+
|
|
722
|
+
function Gleam.Action(fn: (instance: Instance) -> ()): Action
|
|
723
|
+
return {
|
|
724
|
+
_gleamAction = true,
|
|
725
|
+
Run = fn,
|
|
726
|
+
}
|
|
727
|
+
end
|
|
728
|
+
|
|
729
|
+
return Gleam
|