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,433 @@
|
|
|
1
|
+
--!native
|
|
2
|
+
--!optimize 2
|
|
3
|
+
--!strict
|
|
4
|
+
-- Bloom — GUI manager + effects. ColorSequence paths are kept. One Heartbeat.
|
|
5
|
+
|
|
6
|
+
local RunService = game:GetService("RunService")
|
|
7
|
+
local UserInputService = game:GetService("UserInputService")
|
|
8
|
+
local Players = game:GetService("Players")
|
|
9
|
+
|
|
10
|
+
local Bloom = {}
|
|
11
|
+
Bloom.__index = Bloom
|
|
12
|
+
|
|
13
|
+
Bloom.Shine = "Shine"
|
|
14
|
+
Bloom.Rainbow = "Rainbow"
|
|
15
|
+
Bloom.ChromeStroke = "ChromeStroke"
|
|
16
|
+
Bloom.Grow = "Grow"
|
|
17
|
+
Bloom.Lift = "Lift"
|
|
18
|
+
Bloom.Bounce = "Bounce"
|
|
19
|
+
Bloom.Shrink = "Shrink"
|
|
20
|
+
Bloom.Punch = "Punch"
|
|
21
|
+
|
|
22
|
+
export type Options = {
|
|
23
|
+
Speed: number?,
|
|
24
|
+
Size: number?,
|
|
25
|
+
Gradient: ColorSequence | Color3 | UIGradient?,
|
|
26
|
+
Transparency: NumberSequence | number?,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type BloomHandle = typeof(setmetatable(
|
|
30
|
+
{} :: {
|
|
31
|
+
Instance: GuiObject,
|
|
32
|
+
Pause: (self: any) -> (),
|
|
33
|
+
Resume: (self: any) -> (),
|
|
34
|
+
Destroy: (self: any) -> (),
|
|
35
|
+
},
|
|
36
|
+
Bloom
|
|
37
|
+
))
|
|
38
|
+
|
|
39
|
+
local active: { any } = {}
|
|
40
|
+
local stepped: RBXScriptConnection? = nil
|
|
41
|
+
|
|
42
|
+
local function asSequence(color: ColorSequence | Color3 | UIGradient?): ColorSequence
|
|
43
|
+
if color == nil then
|
|
44
|
+
return ColorSequence.new(Color3.new(1, 1, 1))
|
|
45
|
+
end
|
|
46
|
+
if typeof(color) == "ColorSequence" then
|
|
47
|
+
return color
|
|
48
|
+
end
|
|
49
|
+
if typeof(color) == "Color3" then
|
|
50
|
+
return ColorSequence.new(color)
|
|
51
|
+
end
|
|
52
|
+
if typeof(color) == "Instance" and color:IsA("UIGradient") then
|
|
53
|
+
return color.Color
|
|
54
|
+
end
|
|
55
|
+
return ColorSequence.new(Color3.new(1, 1, 1))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
local function ensureStepped()
|
|
59
|
+
if stepped then
|
|
60
|
+
return
|
|
61
|
+
end
|
|
62
|
+
stepped = RunService.Heartbeat:Connect(function(dt)
|
|
63
|
+
for _, job in active do
|
|
64
|
+
if job.Paused or not job.Tick then
|
|
65
|
+
continue
|
|
66
|
+
end
|
|
67
|
+
job:Tick(dt)
|
|
68
|
+
end
|
|
69
|
+
end)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
local function visible(object: Instance): boolean
|
|
73
|
+
if object.Parent == nil then
|
|
74
|
+
return false
|
|
75
|
+
end
|
|
76
|
+
local current: Instance? = object
|
|
77
|
+
while current and current ~= game do
|
|
78
|
+
if current:IsA("GuiObject") and not current.Visible then
|
|
79
|
+
return false
|
|
80
|
+
end
|
|
81
|
+
if (current:IsA("LayerCollector")) and (current :: LayerCollector).Enabled == false then
|
|
82
|
+
return false
|
|
83
|
+
end
|
|
84
|
+
current = current.Parent
|
|
85
|
+
end
|
|
86
|
+
return true
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
local MOTION: { [string]: { Peak: number, Lift: number, Bounce: boolean } } = {
|
|
90
|
+
Grow = { Peak = 1.08, Lift = 0, Bounce = false },
|
|
91
|
+
Lift = { Peak = 1.04, Lift = 8, Bounce = false },
|
|
92
|
+
Bounce = { Peak = 1.06, Lift = 0, Bounce = true },
|
|
93
|
+
Shrink = { Peak = 0.96, Lift = 0, Bounce = false },
|
|
94
|
+
Punch = { Peak = 0.92, Lift = 0, Bounce = true },
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
local CHROME = ColorSequence.new({
|
|
98
|
+
ColorSequenceKeypoint.new(0, Color3.fromRGB(168, 172, 186)),
|
|
99
|
+
ColorSequenceKeypoint.new(0.22, Color3.fromRGB(255, 255, 255)),
|
|
100
|
+
ColorSequenceKeypoint.new(0.5, Color3.fromRGB(148, 156, 176)),
|
|
101
|
+
ColorSequenceKeypoint.new(0.78, Color3.fromRGB(255, 255, 255)),
|
|
102
|
+
ColorSequenceKeypoint.new(1, Color3.fromRGB(168, 172, 186)),
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
local function scaleSize(original: UDim2, scale: number): UDim2
|
|
106
|
+
return UDim2.new(original.X.Scale * scale, original.X.Offset * scale, original.Y.Scale * scale, original.Y.Offset * scale)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
local function bindHandle(job: any): BloomHandle
|
|
110
|
+
table.insert(active, job)
|
|
111
|
+
ensureStepped()
|
|
112
|
+
return setmetatable(job, Bloom)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
function Bloom.Stop(t: number, color: Color3): ColorSequenceKeypoint
|
|
116
|
+
return ColorSequenceKeypoint.new(t, color)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
function Bloom.Gradient(...: ColorSequenceKeypoint): ColorSequence
|
|
120
|
+
return ColorSequence.new({ ... })
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
function Bloom.Play(target: GuiObject, preset: string, options: Options?): BloomHandle
|
|
124
|
+
local opts = options or {}
|
|
125
|
+
local motion = MOTION[preset]
|
|
126
|
+
if motion then
|
|
127
|
+
local original = target.Size
|
|
128
|
+
local originPos = target.Position
|
|
129
|
+
local speed = opts.Speed or if motion.Bounce then 1.6 else 1.1
|
|
130
|
+
local peak = motion.Peak
|
|
131
|
+
local lift = motion.Lift
|
|
132
|
+
local job
|
|
133
|
+
job = {
|
|
134
|
+
Instance = target,
|
|
135
|
+
Paused = false,
|
|
136
|
+
Offset = 0,
|
|
137
|
+
Tick = function(self, dt: number)
|
|
138
|
+
if not visible(target) then
|
|
139
|
+
return
|
|
140
|
+
end
|
|
141
|
+
self.Offset += dt * speed
|
|
142
|
+
local wave = math.sin(self.Offset * math.pi * 2)
|
|
143
|
+
if motion.Bounce then
|
|
144
|
+
wave = math.abs(wave)
|
|
145
|
+
else
|
|
146
|
+
wave = (wave + 1) * 0.5
|
|
147
|
+
end
|
|
148
|
+
target.Size = scaleSize(original, 1 + (peak - 1) * wave)
|
|
149
|
+
if lift ~= 0 then
|
|
150
|
+
target.Position = originPos - UDim2.fromOffset(0, lift * wave)
|
|
151
|
+
end
|
|
152
|
+
end,
|
|
153
|
+
Pause = function(self)
|
|
154
|
+
self.Paused = true
|
|
155
|
+
end,
|
|
156
|
+
Resume = function(self)
|
|
157
|
+
self.Paused = false
|
|
158
|
+
end,
|
|
159
|
+
Destroy = function(self)
|
|
160
|
+
if self._dead then
|
|
161
|
+
return
|
|
162
|
+
end
|
|
163
|
+
self._dead = true
|
|
164
|
+
self.Paused = true
|
|
165
|
+
self.Tick = nil
|
|
166
|
+
if target.Parent then
|
|
167
|
+
target.Size = original
|
|
168
|
+
target.Position = originPos
|
|
169
|
+
end
|
|
170
|
+
local index = table.find(active, self)
|
|
171
|
+
if index then
|
|
172
|
+
table.remove(active, index)
|
|
173
|
+
end
|
|
174
|
+
end,
|
|
175
|
+
}
|
|
176
|
+
target.Destroying:Once(function()
|
|
177
|
+
job:Destroy()
|
|
178
|
+
end)
|
|
179
|
+
return bindHandle(job)
|
|
180
|
+
end
|
|
181
|
+
local sequence = asSequence(opts.Gradient)
|
|
182
|
+
if preset == Bloom.Rainbow and opts.Gradient == nil then
|
|
183
|
+
sequence = ColorSequence.new({
|
|
184
|
+
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)),
|
|
185
|
+
ColorSequenceKeypoint.new(0.16, Color3.fromRGB(255, 127, 0)),
|
|
186
|
+
ColorSequenceKeypoint.new(0.33, Color3.fromRGB(255, 255, 0)),
|
|
187
|
+
ColorSequenceKeypoint.new(0.5, Color3.fromRGB(0, 255, 0)),
|
|
188
|
+
ColorSequenceKeypoint.new(0.66, Color3.fromRGB(0, 127, 255)),
|
|
189
|
+
ColorSequenceKeypoint.new(0.83, Color3.fromRGB(139, 0, 255)),
|
|
190
|
+
ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 0, 0)),
|
|
191
|
+
})
|
|
192
|
+
elseif preset == Bloom.ChromeStroke and opts.Gradient == nil then
|
|
193
|
+
sequence = CHROME
|
|
194
|
+
end
|
|
195
|
+
local gradient = Instance.new("UIGradient")
|
|
196
|
+
gradient.Color = sequence
|
|
197
|
+
if typeof(opts.Transparency) == "NumberSequence" then
|
|
198
|
+
gradient.Transparency = opts.Transparency
|
|
199
|
+
elseif typeof(opts.Transparency) == "number" then
|
|
200
|
+
gradient.Transparency = NumberSequence.new(opts.Transparency)
|
|
201
|
+
end
|
|
202
|
+
if typeof(opts.Gradient) == "Instance" and (opts.Gradient :: UIGradient):IsA("UIGradient") then
|
|
203
|
+
gradient.Transparency = (opts.Gradient :: UIGradient).Transparency
|
|
204
|
+
gradient.Rotation = (opts.Gradient :: UIGradient).Rotation
|
|
205
|
+
end
|
|
206
|
+
gradient.Parent = target
|
|
207
|
+
local stroke: UIStroke? = nil
|
|
208
|
+
if string.find(preset, "Stroke", 1, true) then
|
|
209
|
+
stroke = Instance.new("UIStroke")
|
|
210
|
+
stroke.Thickness = opts.Size or 2
|
|
211
|
+
stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
|
|
212
|
+
stroke.LineJoinMode = Enum.LineJoinMode.Round
|
|
213
|
+
stroke.Parent = target
|
|
214
|
+
gradient.Parent = stroke
|
|
215
|
+
end
|
|
216
|
+
local speed = opts.Speed or 0.4
|
|
217
|
+
local job
|
|
218
|
+
job = {
|
|
219
|
+
Instance = target,
|
|
220
|
+
Paused = false,
|
|
221
|
+
Offset = 0,
|
|
222
|
+
Tick = function(self, dt: number)
|
|
223
|
+
if not visible(target) then
|
|
224
|
+
return
|
|
225
|
+
end
|
|
226
|
+
self.Offset = (self.Offset + dt * speed) % 2
|
|
227
|
+
gradient.Offset = Vector2.new(self.Offset - 1, 0)
|
|
228
|
+
end,
|
|
229
|
+
Pause = function(self)
|
|
230
|
+
self.Paused = true
|
|
231
|
+
end,
|
|
232
|
+
Resume = function(self)
|
|
233
|
+
self.Paused = false
|
|
234
|
+
end,
|
|
235
|
+
Destroy = function(self)
|
|
236
|
+
if self._dead then
|
|
237
|
+
return
|
|
238
|
+
end
|
|
239
|
+
self._dead = true
|
|
240
|
+
self.Paused = true
|
|
241
|
+
self.Tick = nil
|
|
242
|
+
gradient:Destroy()
|
|
243
|
+
if stroke then
|
|
244
|
+
stroke:Destroy()
|
|
245
|
+
end
|
|
246
|
+
local index = table.find(active, self)
|
|
247
|
+
if index then
|
|
248
|
+
table.remove(active, index)
|
|
249
|
+
end
|
|
250
|
+
end,
|
|
251
|
+
}
|
|
252
|
+
target.Destroying:Once(function()
|
|
253
|
+
job:Destroy()
|
|
254
|
+
end)
|
|
255
|
+
return bindHandle(job)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
function Bloom.Fade(element: GuiObject, show: boolean, speed: number?)
|
|
259
|
+
element.Visible = true
|
|
260
|
+
local tween = game:GetService("TweenService"):Create(element, TweenInfo.new(speed or 0.25), {
|
|
261
|
+
BackgroundTransparency = if show then 0 else 1,
|
|
262
|
+
})
|
|
263
|
+
tween:Play()
|
|
264
|
+
if not show then
|
|
265
|
+
task.delay(speed or 0.25, function()
|
|
266
|
+
element.Visible = false
|
|
267
|
+
end)
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
function Bloom.Slide(element: GuiObject, show: boolean, speed: number?)
|
|
272
|
+
Bloom.Fade(element, show, speed)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
function Bloom.Zoom(element: GuiObject, show: boolean, speed: number?)
|
|
276
|
+
local original = element.Size
|
|
277
|
+
if show then
|
|
278
|
+
element.Visible = true
|
|
279
|
+
element.Size = UDim2.new(original.X.Scale * 0.9, original.X.Offset, original.Y.Scale * 0.9, original.Y.Offset)
|
|
280
|
+
game:GetService("TweenService"):Create(element, TweenInfo.new(speed or 0.25), { Size = original }):Play()
|
|
281
|
+
else
|
|
282
|
+
game:GetService("TweenService")
|
|
283
|
+
:Create(element, TweenInfo.new(speed or 0.25), {
|
|
284
|
+
Size = UDim2.new(original.X.Scale * 0.9, original.X.Offset, original.Y.Scale * 0.9, original.Y.Offset),
|
|
285
|
+
})
|
|
286
|
+
:Play()
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
function Bloom.Bounce(element: GuiObject, speed: number?)
|
|
291
|
+
local original = element.Size
|
|
292
|
+
local up = UDim2.new(original.X.Scale * 1.06, original.X.Offset, original.Y.Scale * 1.06, original.Y.Offset)
|
|
293
|
+
local tween = game:GetService("TweenService"):Create(element, TweenInfo.new(speed or 0.12, Enum.EasingStyle.Back, Enum.EasingDirection.Out), { Size = up })
|
|
294
|
+
tween:Play()
|
|
295
|
+
tween.Completed:Once(function()
|
|
296
|
+
game:GetService("TweenService"):Create(element, TweenInfo.new(speed or 0.12), { Size = original }):Play()
|
|
297
|
+
end)
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
function Bloom.Hover(element: GuiObject, kind: string?)
|
|
301
|
+
local original = element.Size
|
|
302
|
+
element.MouseEnter:Connect(function()
|
|
303
|
+
local scale = if kind == Bloom.Lift then 1.04 else 1.08
|
|
304
|
+
game:GetService("TweenService"):Create(element, TweenInfo.new(0.12), {
|
|
305
|
+
Size = UDim2.new(original.X.Scale * scale, original.X.Offset, original.Y.Scale * scale, original.Y.Offset),
|
|
306
|
+
}):Play()
|
|
307
|
+
end)
|
|
308
|
+
element.MouseLeave:Connect(function()
|
|
309
|
+
game:GetService("TweenService"):Create(element, TweenInfo.new(0.12), { Size = original }):Play()
|
|
310
|
+
end)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
function Bloom.Press(element: GuiObject, kind: string?)
|
|
314
|
+
if not element:IsA("GuiButton") then
|
|
315
|
+
return
|
|
316
|
+
end
|
|
317
|
+
local original = element.Size
|
|
318
|
+
element.MouseButton1Down:Connect(function()
|
|
319
|
+
local scale = if kind == Bloom.Punch then 0.92 else 0.96
|
|
320
|
+
game:GetService("TweenService"):Create(element, TweenInfo.new(0.08), {
|
|
321
|
+
Size = UDim2.new(original.X.Scale * scale, original.X.Offset, original.Y.Scale * scale, original.Y.Offset),
|
|
322
|
+
}):Play()
|
|
323
|
+
end)
|
|
324
|
+
element.MouseButton1Up:Connect(function()
|
|
325
|
+
game:GetService("TweenService"):Create(element, TweenInfo.new(0.08), { Size = original }):Play()
|
|
326
|
+
end)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
function Bloom.Ripple(element: GuiObject)
|
|
330
|
+
if not element:IsA("GuiButton") then
|
|
331
|
+
return
|
|
332
|
+
end
|
|
333
|
+
element.MouseButton1Click:Connect(function()
|
|
334
|
+
local ripple = Instance.new("Frame")
|
|
335
|
+
ripple.BackgroundTransparency = 0.6
|
|
336
|
+
ripple.BackgroundColor3 = Color3.new(1, 1, 1)
|
|
337
|
+
ripple.Size = UDim2.fromOffset(8, 8)
|
|
338
|
+
ripple.AnchorPoint = Vector2.new(0.5, 0.5)
|
|
339
|
+
ripple.Position = UDim2.fromScale(0.5, 0.5)
|
|
340
|
+
ripple.Parent = element
|
|
341
|
+
local corner = Instance.new("UICorner")
|
|
342
|
+
corner.CornerRadius = UDim.new(1, 0)
|
|
343
|
+
corner.Parent = ripple
|
|
344
|
+
game:GetService("TweenService")
|
|
345
|
+
:Create(ripple, TweenInfo.new(0.35), { Size = UDim2.fromScale(1.4, 1.4), BackgroundTransparency = 1 })
|
|
346
|
+
:Play()
|
|
347
|
+
task.delay(0.35, function()
|
|
348
|
+
ripple:Destroy()
|
|
349
|
+
end)
|
|
350
|
+
end)
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
function Bloom.Tilt(element: GuiObject, degrees: number?)
|
|
354
|
+
local max = degrees or 8
|
|
355
|
+
local connection = RunService.RenderStepped:Connect(function()
|
|
356
|
+
if not visible(element) then
|
|
357
|
+
return
|
|
358
|
+
end
|
|
359
|
+
local player = Players.LocalPlayer
|
|
360
|
+
local mouse = player and player:GetMouse()
|
|
361
|
+
if not mouse then
|
|
362
|
+
return
|
|
363
|
+
end
|
|
364
|
+
local pos = element.AbsolutePosition
|
|
365
|
+
local size = element.AbsoluteSize
|
|
366
|
+
local cx = pos.X + size.X / 2
|
|
367
|
+
local cy = pos.Y + size.Y / 2
|
|
368
|
+
local dx = ((mouse.X - cx) / math.max(size.X, 1)) * max
|
|
369
|
+
local dy = ((mouse.Y - cy) / math.max(size.Y, 1)) * max
|
|
370
|
+
element.Rotation = math.clamp(dx * 0.15, -max, max)
|
|
371
|
+
local gradient = element:FindFirstChildOfClass("UIGradient")
|
|
372
|
+
if gradient then
|
|
373
|
+
gradient.Rotation = 45 + dy
|
|
374
|
+
end
|
|
375
|
+
end)
|
|
376
|
+
return connection
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
function Bloom.Depth(element: GuiObject)
|
|
380
|
+
Bloom.Hover(element, Bloom.Lift)
|
|
381
|
+
local shadow = Instance.new("UIStroke")
|
|
382
|
+
shadow.Thickness = 2
|
|
383
|
+
shadow.Transparency = 0.6
|
|
384
|
+
shadow.Parent = element
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
function Bloom.Flip(element: GuiObject, speed: number?)
|
|
388
|
+
local original = element.Size
|
|
389
|
+
local tween = game:GetService("TweenService"):Create(element, TweenInfo.new((speed or 0.2) / 2), {
|
|
390
|
+
Size = UDim2.new(0, 0, original.Y.Scale, original.Y.Offset),
|
|
391
|
+
})
|
|
392
|
+
tween:Play()
|
|
393
|
+
tween.Completed:Once(function()
|
|
394
|
+
game:GetService("TweenService"):Create(element, TweenInfo.new((speed or 0.2) / 2), { Size = original }):Play()
|
|
395
|
+
end)
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
function Bloom.Viewport(frame: GuiObject, model: Instance)
|
|
399
|
+
local Stage = require(script.Parent.Stage)
|
|
400
|
+
return Stage.Attach(frame, model)
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
function Bloom.Type(container: Frame, label: TextLabel, text: string)
|
|
404
|
+
label.Text = text
|
|
405
|
+
label.MaxVisibleGraphemes = 0
|
|
406
|
+
task.spawn(function()
|
|
407
|
+
for i = 1, #text do
|
|
408
|
+
label.MaxVisibleGraphemes = i
|
|
409
|
+
task.wait(0.03)
|
|
410
|
+
end
|
|
411
|
+
end)
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
function Bloom.Sequence(steps: { { fn: any, args: { any }?, wait: number? } })
|
|
415
|
+
task.spawn(function()
|
|
416
|
+
for _, step in steps do
|
|
417
|
+
if step.wait then
|
|
418
|
+
task.wait(step.wait)
|
|
419
|
+
end
|
|
420
|
+
if step.fn then
|
|
421
|
+
step.fn(table.unpack(step.args or {}))
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
end)
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
Bloom.FrameSlide = Bloom.Slide
|
|
428
|
+
Bloom.FrameZoom = Bloom.Zoom
|
|
429
|
+
Bloom.FrameBounce = Bloom.Bounce
|
|
430
|
+
Bloom.SetButtonStyle = Bloom.Hover
|
|
431
|
+
Bloom.ShowText = Bloom.Type
|
|
432
|
+
|
|
433
|
+
return Bloom
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
--!native
|
|
2
|
+
--!optimize 2
|
|
3
|
+
--!strict
|
|
4
|
+
-- Coil — Fraktality damped spring. Frequency is Hz.
|
|
5
|
+
-- Gleam.Spring: Coil.new, :Set, :Get, :Step — do not rename those.
|
|
6
|
+
|
|
7
|
+
local Coil = {}
|
|
8
|
+
Coil.__index = Coil
|
|
9
|
+
|
|
10
|
+
local TAU = 2 * math.pi
|
|
11
|
+
local SNAP_DT = 1
|
|
12
|
+
local DECAY_SNAP = 50
|
|
13
|
+
local CRITICAL_EPS = 1e-5
|
|
14
|
+
|
|
15
|
+
export type Coil = typeof(setmetatable(
|
|
16
|
+
{} :: {
|
|
17
|
+
Damping: number,
|
|
18
|
+
Frequency: number,
|
|
19
|
+
Goal: any,
|
|
20
|
+
Position: any,
|
|
21
|
+
Velocity: any,
|
|
22
|
+
},
|
|
23
|
+
Coil
|
|
24
|
+
))
|
|
25
|
+
|
|
26
|
+
local function pack(value: any): { number }
|
|
27
|
+
local kind = typeof(value)
|
|
28
|
+
if kind == "number" then
|
|
29
|
+
return { value }
|
|
30
|
+
elseif kind == "Vector3" then
|
|
31
|
+
return { value.X, value.Y, value.Z }
|
|
32
|
+
elseif kind == "Vector2" then
|
|
33
|
+
return { value.X, value.Y }
|
|
34
|
+
elseif kind == "Color3" then
|
|
35
|
+
return { value.R, value.G, value.B }
|
|
36
|
+
elseif kind == "UDim2" then
|
|
37
|
+
return { value.X.Scale, value.X.Offset, value.Y.Scale, value.Y.Offset }
|
|
38
|
+
elseif kind == "UDim" then
|
|
39
|
+
return { value.Scale, value.Offset }
|
|
40
|
+
end
|
|
41
|
+
error("Coil: expected number, Vector3, Vector2, Color3, UDim2, or UDim")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
local function unpackKind(kind: string, components: { number }): any
|
|
45
|
+
if kind == "number" then
|
|
46
|
+
return components[1]
|
|
47
|
+
elseif kind == "Vector3" then
|
|
48
|
+
return Vector3.new(components[1], components[2], components[3])
|
|
49
|
+
elseif kind == "Vector2" then
|
|
50
|
+
return Vector2.new(components[1], components[2])
|
|
51
|
+
elseif kind == "Color3" then
|
|
52
|
+
return Color3.new(components[1], components[2], components[3])
|
|
53
|
+
elseif kind == "UDim2" then
|
|
54
|
+
return UDim2.new(components[1], components[2], components[3], components[4])
|
|
55
|
+
elseif kind == "UDim" then
|
|
56
|
+
return UDim.new(components[1], components[2])
|
|
57
|
+
end
|
|
58
|
+
return components[1]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
local function zeroLike(value: any): any
|
|
62
|
+
local kind = typeof(value)
|
|
63
|
+
if kind == "number" then
|
|
64
|
+
return 0
|
|
65
|
+
elseif kind == "Vector3" then
|
|
66
|
+
return Vector3.zero
|
|
67
|
+
elseif kind == "Vector2" then
|
|
68
|
+
return Vector2.zero
|
|
69
|
+
elseif kind == "Color3" then
|
|
70
|
+
return Color3.new(0, 0, 0)
|
|
71
|
+
elseif kind == "UDim2" then
|
|
72
|
+
return UDim2.new()
|
|
73
|
+
elseif kind == "UDim" then
|
|
74
|
+
return UDim.new()
|
|
75
|
+
end
|
|
76
|
+
return 0
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
local function stepScalar(position: number, velocity: number, goal: number, damping: number, omega: number, dt: number): (number, number)
|
|
80
|
+
if omega <= 0 then
|
|
81
|
+
return position, velocity
|
|
82
|
+
end
|
|
83
|
+
local envelope = damping * omega * dt
|
|
84
|
+
if dt >= SNAP_DT or envelope > DECAY_SNAP then
|
|
85
|
+
return goal, 0
|
|
86
|
+
end
|
|
87
|
+
local x = position - goal
|
|
88
|
+
local v = velocity
|
|
89
|
+
if damping < 1 - CRITICAL_EPS then
|
|
90
|
+
local wd = omega * math.sqrt(1 - damping * damping)
|
|
91
|
+
if wd == 0 then
|
|
92
|
+
return goal, 0
|
|
93
|
+
end
|
|
94
|
+
local e = math.exp(-damping * omega * dt)
|
|
95
|
+
local c1 = x
|
|
96
|
+
local c2 = (v + damping * omega * x) / wd
|
|
97
|
+
local wt = wd * dt
|
|
98
|
+
local cos = math.cos(wt)
|
|
99
|
+
local sin = math.sin(wt)
|
|
100
|
+
return goal + e * (c1 * cos + c2 * sin),
|
|
101
|
+
-e * ((c1 * damping * omega - c2 * wd) * cos + (c1 * wd + c2 * damping * omega) * sin)
|
|
102
|
+
elseif damping <= 1 + CRITICAL_EPS then
|
|
103
|
+
local e = math.exp(-omega * dt)
|
|
104
|
+
return goal + e * (x + (v + omega * x) * dt), e * (v * (1 - omega * dt) - omega * omega * x * dt)
|
|
105
|
+
end
|
|
106
|
+
local disc = math.sqrt(damping * damping - 1)
|
|
107
|
+
local r1 = -omega * (damping - disc)
|
|
108
|
+
local r2 = -omega * (damping + disc)
|
|
109
|
+
local denom = r2 - r1
|
|
110
|
+
if denom == 0 then
|
|
111
|
+
local e = math.exp(-omega * dt)
|
|
112
|
+
return goal + e * (x + (v + omega * x) * dt), e * (v * (1 - omega * dt) - omega * omega * x * dt)
|
|
113
|
+
end
|
|
114
|
+
local c2 = (v - r1 * x) / denom
|
|
115
|
+
local c1 = x - c2
|
|
116
|
+
local e1 = math.exp(r1 * dt)
|
|
117
|
+
local e2 = math.exp(r2 * dt)
|
|
118
|
+
return goal + c1 * e1 + c2 * e2, c1 * r1 * e1 + c2 * r2 * e2
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
function Coil.new(dampingRatio: number, frequency: number, position: any): Coil
|
|
122
|
+
return setmetatable({
|
|
123
|
+
Damping = dampingRatio,
|
|
124
|
+
Frequency = frequency,
|
|
125
|
+
Goal = position,
|
|
126
|
+
Position = position,
|
|
127
|
+
Velocity = zeroLike(position),
|
|
128
|
+
}, Coil)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
function Coil.Vector(dampingRatio: number, frequency: number, position: Vector3): Coil
|
|
132
|
+
return Coil.new(dampingRatio, frequency, position)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
function Coil.UDim(dampingRatio: number, frequency: number, position: UDim2): Coil
|
|
136
|
+
return Coil.new(dampingRatio, frequency, position)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
Coil.UDim2 = Coil.UDim
|
|
140
|
+
|
|
141
|
+
function Coil.Color(dampingRatio: number, frequency: number, position: Color3): Coil
|
|
142
|
+
return Coil.new(dampingRatio, frequency, position)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
function Coil:Set(goal: any)
|
|
146
|
+
self.Goal = goal
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
Coil.SetGoal = Coil.Set
|
|
150
|
+
|
|
151
|
+
function Coil:Get(): any
|
|
152
|
+
return self.Position
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
function Coil:Impulse(velocity: any)
|
|
156
|
+
local kind = typeof(self.Position)
|
|
157
|
+
if kind == "number" then
|
|
158
|
+
self.Velocity += velocity
|
|
159
|
+
return
|
|
160
|
+
end
|
|
161
|
+
local current = pack(self.Velocity)
|
|
162
|
+
if typeof(velocity) == "number" then
|
|
163
|
+
for i = 1, #current do
|
|
164
|
+
current[i] += velocity
|
|
165
|
+
end
|
|
166
|
+
else
|
|
167
|
+
local delta = pack(velocity)
|
|
168
|
+
local n = math.min(#current, #delta)
|
|
169
|
+
for i = 1, n do
|
|
170
|
+
current[i] += delta[i]
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
self.Velocity = unpackKind(kind, current)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
function Coil:Step(dt: number)
|
|
177
|
+
if typeof(dt) ~= "number" or dt ~= dt or dt <= 0 then
|
|
178
|
+
return
|
|
179
|
+
end
|
|
180
|
+
local frequency = self.Frequency
|
|
181
|
+
if typeof(frequency) ~= "number" then
|
|
182
|
+
return
|
|
183
|
+
end
|
|
184
|
+
local omega = frequency * TAU
|
|
185
|
+
if omega <= 0 then
|
|
186
|
+
return
|
|
187
|
+
end
|
|
188
|
+
local kind = typeof(self.Position)
|
|
189
|
+
if kind == "number" then
|
|
190
|
+
local position, velocity = stepScalar(self.Position, self.Velocity, self.Goal, self.Damping, omega, dt)
|
|
191
|
+
self.Position = position
|
|
192
|
+
self.Velocity = velocity
|
|
193
|
+
return
|
|
194
|
+
end
|
|
195
|
+
local p = pack(self.Position)
|
|
196
|
+
local v = pack(self.Velocity)
|
|
197
|
+
local g = pack(self.Goal)
|
|
198
|
+
local n = math.min(#p, #v, #g)
|
|
199
|
+
for i = 1, n do
|
|
200
|
+
local nextP, nextV = stepScalar(p[i], v[i], g[i], self.Damping, omega, dt)
|
|
201
|
+
p[i] = nextP
|
|
202
|
+
v[i] = nextV
|
|
203
|
+
end
|
|
204
|
+
self.Position = unpackKind(kind, p)
|
|
205
|
+
self.Velocity = unpackKind(kind, v)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
function Coil:Update(dt: number): any
|
|
209
|
+
self:Step(dt)
|
|
210
|
+
return self.Position
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
Coil.New = Coil.new
|
|
214
|
+
|
|
215
|
+
return Coil
|