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,117 @@
|
|
|
1
|
+
--!native
|
|
2
|
+
--!optimize 2
|
|
3
|
+
--!strict
|
|
4
|
+
--[=[
|
|
5
|
+
@class Occlude
|
|
6
|
+
Raycast occlusion helper Pin can require. `WorldRoot:Raycast` from camera
|
|
7
|
+
to adornee. Default filter excludes the adornee.
|
|
8
|
+
|
|
9
|
+
Type function `Keys` — strip named fields from a table type.
|
|
10
|
+
`Keys<PlayerData, "mana">` is `{ nome: string, hp: number }`, never `any`.
|
|
11
|
+
]=]
|
|
12
|
+
type Example = { nome: string, hp: number, mana: number }
|
|
13
|
+
|
|
14
|
+
export type function Keys(t: type, k: type)
|
|
15
|
+
if not t:is("table") then
|
|
16
|
+
error(`it should be table`)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
local ocludded = {}
|
|
20
|
+
local function register(ty: type)
|
|
21
|
+
local value = ty:value()
|
|
22
|
+
if type(value) ~= "string" then
|
|
23
|
+
error(`singleton needs to be string`)
|
|
24
|
+
end
|
|
25
|
+
ocludded[value] = true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if k:is("union") then
|
|
29
|
+
for _, ty in k:components() do
|
|
30
|
+
if ty:is("singleton") then
|
|
31
|
+
register(ty)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
elseif k:is("singleton") then
|
|
35
|
+
register(k)
|
|
36
|
+
else
|
|
37
|
+
error(`k must be union or singleton`)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
local result = types.copy(t)
|
|
41
|
+
local remover = {}
|
|
42
|
+
|
|
43
|
+
for index in result:properties() do
|
|
44
|
+
local name = index:value()
|
|
45
|
+
if type(name) == "string" and ocludded[name] then
|
|
46
|
+
table.insert(remover, index)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
for _, index in remover do
|
|
51
|
+
result:setproperty(index, nil)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
return result
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
type _E3_14 = Keys<Example, "mana"> --> { nome: string, hp: number }
|
|
58
|
+
|
|
59
|
+
local Occlude = {}
|
|
60
|
+
|
|
61
|
+
local function adorneePosition(adornee: Instance): Vector3?
|
|
62
|
+
if adornee:IsA("BasePart") then
|
|
63
|
+
return adornee.Position
|
|
64
|
+
end
|
|
65
|
+
if adornee:IsA("Model") then
|
|
66
|
+
return adornee:GetPivot().Position
|
|
67
|
+
end
|
|
68
|
+
if adornee:IsA("Attachment") then
|
|
69
|
+
return adornee.WorldPosition
|
|
70
|
+
end
|
|
71
|
+
local part = adornee:FindFirstChildWhichIsA("BasePart", true)
|
|
72
|
+
if part then
|
|
73
|
+
return part.Position
|
|
74
|
+
end
|
|
75
|
+
return nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
local function rayParams(adornee: Instance, params: RaycastParams?): RaycastParams
|
|
79
|
+
if params then
|
|
80
|
+
return params
|
|
81
|
+
end
|
|
82
|
+
local created = RaycastParams.new()
|
|
83
|
+
created.FilterDescendantsInstances = { adornee }
|
|
84
|
+
created.FilterType = Enum.RaycastFilterType.Exclude
|
|
85
|
+
return created
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
function Occlude.Position(adornee: Instance): Vector3?
|
|
89
|
+
return adorneePosition(adornee)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
function Occlude.Raycast(world: WorldRoot, camera: Camera, adornee: Instance, params: RaycastParams?): RaycastResult?
|
|
93
|
+
local goal = adorneePosition(adornee)
|
|
94
|
+
if not goal then
|
|
95
|
+
return nil
|
|
96
|
+
end
|
|
97
|
+
local origin = camera.CFrame.Position
|
|
98
|
+
return world:Raycast(origin, goal - origin, rayParams(adornee, params))
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
function Occlude.IsOccluded(world: WorldRoot, camera: Camera, adornee: Instance, params: RaycastParams?, slack: number?): boolean
|
|
102
|
+
local goal = adorneePosition(adornee)
|
|
103
|
+
if not goal then
|
|
104
|
+
return true
|
|
105
|
+
end
|
|
106
|
+
local hit = Occlude.Raycast(world, camera, adornee, params)
|
|
107
|
+
if hit == nil then
|
|
108
|
+
return false
|
|
109
|
+
end
|
|
110
|
+
return (hit.Position - goal).Magnitude >= (slack or 2)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
function Occlude.Visible(world: WorldRoot, camera: Camera, adornee: Instance, params: RaycastParams?, slack: number?): boolean
|
|
114
|
+
return not Occlude.IsOccluded(world, camera, adornee, params, slack)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
return Occlude
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
--!optimize 2
|
|
2
|
+
--!strict
|
|
3
|
+
--[=[
|
|
4
|
+
@class Pin
|
|
5
|
+
World-space BillboardGui that stays on an adornee, faces the camera, and
|
|
6
|
+
hosts any GuiObject.
|
|
7
|
+
|
|
8
|
+
```lua
|
|
9
|
+
local billboard = Pin.new(part, frame, {
|
|
10
|
+
Size = UDim2.fromOffset(120, 40),
|
|
11
|
+
StudsOffset = Vector3.new(0, 3, 0),
|
|
12
|
+
MaxDistance = 80,
|
|
13
|
+
Occlude = true,
|
|
14
|
+
})
|
|
15
|
+
billboard:SetText("Hello")
|
|
16
|
+
```
|
|
17
|
+
]=]
|
|
18
|
+
local Players = game:GetService("Players")
|
|
19
|
+
local RunService = game:GetService("RunService")
|
|
20
|
+
local Workspace = game:GetService("Workspace")
|
|
21
|
+
|
|
22
|
+
local Pin = {}
|
|
23
|
+
Pin.__index = Pin
|
|
24
|
+
|
|
25
|
+
local occludeModule: any = nil
|
|
26
|
+
do
|
|
27
|
+
local sibling = script.Parent:FindFirstChild("Occlude")
|
|
28
|
+
if sibling and sibling:IsA("ModuleScript") then
|
|
29
|
+
local ok, result = pcall(require, sibling)
|
|
30
|
+
if ok then
|
|
31
|
+
occludeModule = result
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
export type Options = {
|
|
37
|
+
Name: string?,
|
|
38
|
+
Size: UDim2?,
|
|
39
|
+
StudsOffset: Vector3?,
|
|
40
|
+
StudsOffsetWorldSpace: Vector3?,
|
|
41
|
+
MaxDistance: number?,
|
|
42
|
+
MinDistance: number?,
|
|
43
|
+
AlwaysOnTop: boolean?,
|
|
44
|
+
LightInfluence: number?,
|
|
45
|
+
Parent: Instance?,
|
|
46
|
+
Occlude: boolean?,
|
|
47
|
+
Fade: boolean?,
|
|
48
|
+
Scale: boolean?,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type Pin = typeof(setmetatable(
|
|
52
|
+
{} :: {
|
|
53
|
+
Adornee: Instance,
|
|
54
|
+
Gui: GuiObject,
|
|
55
|
+
Billboard: BillboardGui,
|
|
56
|
+
_janitor: { () -> () },
|
|
57
|
+
_alive: boolean,
|
|
58
|
+
_enabled: boolean,
|
|
59
|
+
_occluded: boolean,
|
|
60
|
+
_occlude: boolean,
|
|
61
|
+
_fade: boolean,
|
|
62
|
+
_scale: boolean,
|
|
63
|
+
_baseSize: UDim2,
|
|
64
|
+
_canvas: CanvasGroup,
|
|
65
|
+
},
|
|
66
|
+
Pin
|
|
67
|
+
))
|
|
68
|
+
|
|
69
|
+
local function resolveParent(adornee: Instance, explicit: Instance?): Instance
|
|
70
|
+
if explicit then
|
|
71
|
+
return explicit
|
|
72
|
+
end
|
|
73
|
+
if adornee:IsA("BasePart") or adornee:IsA("Model") or adornee:IsA("Attachment") then
|
|
74
|
+
return adornee
|
|
75
|
+
end
|
|
76
|
+
if RunService:IsClient() then
|
|
77
|
+
local player = Players.LocalPlayer
|
|
78
|
+
local gui = player and player:FindFirstChildOfClass("PlayerGui")
|
|
79
|
+
if gui then
|
|
80
|
+
return gui
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
return Workspace
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
local function worldPosition(instance: Instance): Vector3?
|
|
87
|
+
if instance:IsA("BasePart") then
|
|
88
|
+
return instance.Position
|
|
89
|
+
end
|
|
90
|
+
if instance:IsA("Attachment") then
|
|
91
|
+
return instance.WorldPosition
|
|
92
|
+
end
|
|
93
|
+
if instance:IsA("Model") then
|
|
94
|
+
return instance:GetPivot().Position
|
|
95
|
+
end
|
|
96
|
+
local part = instance:FindFirstChildWhichIsA("BasePart", true)
|
|
97
|
+
if part then
|
|
98
|
+
return part.Position
|
|
99
|
+
end
|
|
100
|
+
return nil
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
local function occludeIgnore(target: Instance): { Instance }
|
|
104
|
+
local list = { target }
|
|
105
|
+
if RunService:IsClient() then
|
|
106
|
+
local player = Players.LocalPlayer
|
|
107
|
+
local character = player and player.Character
|
|
108
|
+
if character then
|
|
109
|
+
table.insert(list, character)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
return list
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
local function isOccluded(origin: Vector3, goal: Vector3, target: Instance): boolean
|
|
116
|
+
if occludeModule then
|
|
117
|
+
local checker = occludeModule.IsOccluded or occludeModule.Check or occludeModule.Raycast
|
|
118
|
+
if typeof(checker) == "function" then
|
|
119
|
+
local ok, blocked = pcall(checker, origin, goal, target)
|
|
120
|
+
if ok and typeof(blocked) == "boolean" then
|
|
121
|
+
return blocked
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
local params = RaycastParams.new()
|
|
126
|
+
params.FilterDescendantsInstances = occludeIgnore(target)
|
|
127
|
+
params.FilterType = Enum.RaycastFilterType.Exclude
|
|
128
|
+
local delta = goal - origin
|
|
129
|
+
if delta.Magnitude < 0.05 then
|
|
130
|
+
return false
|
|
131
|
+
end
|
|
132
|
+
local hit = Workspace:Raycast(origin, delta, params)
|
|
133
|
+
if hit == nil then
|
|
134
|
+
return false
|
|
135
|
+
end
|
|
136
|
+
return (hit.Position - goal).Magnitude >= 2
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
--[=[
|
|
140
|
+
@within Pin
|
|
141
|
+
@param adornee Instance -- Part, Model, Attachment, or any Instance with a position
|
|
142
|
+
@param gui GuiObject -- Frame / TextLabel cloned or reparented into the billboard
|
|
143
|
+
@param options Options?
|
|
144
|
+
@return Pin
|
|
145
|
+
]=]
|
|
146
|
+
function Pin.new(adornee: Instance, gui: GuiObject, options: Options?): Pin
|
|
147
|
+
local opts = options or {}
|
|
148
|
+
local billboard = Instance.new("BillboardGui")
|
|
149
|
+
billboard.Name = opts.Name or "Pin"
|
|
150
|
+
if adornee:IsA("BasePart") or adornee:IsA("Attachment") or adornee:IsA("Model") then
|
|
151
|
+
billboard.Adornee = adornee
|
|
152
|
+
end
|
|
153
|
+
local baseSize = opts.Size
|
|
154
|
+
or UDim2.fromOffset(math.max(gui.AbsoluteSize.X, 80), math.max(gui.AbsoluteSize.Y, 32))
|
|
155
|
+
billboard.Size = baseSize
|
|
156
|
+
billboard.StudsOffset = opts.StudsOffset or Vector3.new(0, 2, 0)
|
|
157
|
+
billboard.StudsOffsetWorldSpace = opts.StudsOffsetWorldSpace or Vector3.zero
|
|
158
|
+
billboard.MaxDistance = opts.MaxDistance or 120
|
|
159
|
+
-- BillboardGui has MaxDistance only; MinDistance in PinOptions is reserved / ignored.
|
|
160
|
+
billboard.AlwaysOnTop = if opts.AlwaysOnTop == nil then true else opts.AlwaysOnTop
|
|
161
|
+
billboard.LightInfluence = opts.LightInfluence or 0
|
|
162
|
+
billboard.ResetOnSpawn = false
|
|
163
|
+
billboard.Active = true
|
|
164
|
+
billboard.ClipsDescendants = false
|
|
165
|
+
billboard.Parent = resolveParent(adornee, opts.Parent)
|
|
166
|
+
|
|
167
|
+
local canvas = Instance.new("CanvasGroup")
|
|
168
|
+
canvas.Name = "PinCanvas"
|
|
169
|
+
canvas.Size = UDim2.fromScale(1, 1)
|
|
170
|
+
canvas.BackgroundTransparency = 1
|
|
171
|
+
canvas.BorderSizePixel = 0
|
|
172
|
+
canvas.GroupTransparency = 0
|
|
173
|
+
canvas.Parent = billboard
|
|
174
|
+
gui.Parent = canvas
|
|
175
|
+
|
|
176
|
+
local self = setmetatable({
|
|
177
|
+
Adornee = adornee,
|
|
178
|
+
Gui = gui,
|
|
179
|
+
Billboard = billboard,
|
|
180
|
+
_janitor = {} :: { () -> () },
|
|
181
|
+
_alive = true,
|
|
182
|
+
_enabled = true,
|
|
183
|
+
_occluded = false,
|
|
184
|
+
_occlude = if opts.Occlude == nil then true else opts.Occlude,
|
|
185
|
+
_fade = if opts.Fade == nil then true else opts.Fade,
|
|
186
|
+
_scale = if opts.Scale == nil then true else opts.Scale,
|
|
187
|
+
_baseSize = baseSize,
|
|
188
|
+
_minDistance = opts.MinDistance or 0,
|
|
189
|
+
_canvas = canvas,
|
|
190
|
+
}, Pin)
|
|
191
|
+
|
|
192
|
+
local function applyEnabled()
|
|
193
|
+
billboard.Enabled = self._enabled and not self._occluded
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
local connection = RunService.Heartbeat:Connect(function()
|
|
197
|
+
if not self._alive or not adornee.Parent then
|
|
198
|
+
return
|
|
199
|
+
end
|
|
200
|
+
if billboard.Adornee == nil then
|
|
201
|
+
local part = adornee:FindFirstChildWhichIsA("BasePart", true)
|
|
202
|
+
if part then
|
|
203
|
+
billboard.Adornee = part
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
local camera = Workspace.CurrentCamera
|
|
207
|
+
local goal = worldPosition(billboard.Adornee or adornee)
|
|
208
|
+
if not camera or not goal then
|
|
209
|
+
return
|
|
210
|
+
end
|
|
211
|
+
local origin = camera.CFrame.Position
|
|
212
|
+
local distance = (goal - origin).Magnitude
|
|
213
|
+
local maxDistance = billboard.MaxDistance
|
|
214
|
+
if maxDistance <= 0 then
|
|
215
|
+
maxDistance = 1e9
|
|
216
|
+
end
|
|
217
|
+
local minDistance = self._minDistance
|
|
218
|
+
|
|
219
|
+
if self._occlude then
|
|
220
|
+
self._occluded = isOccluded(origin, goal, billboard.Adornee or adornee)
|
|
221
|
+
else
|
|
222
|
+
self._occluded = false
|
|
223
|
+
end
|
|
224
|
+
applyEnabled()
|
|
225
|
+
|
|
226
|
+
if self._scale then
|
|
227
|
+
local scale = math.clamp(1 - (distance / maxDistance) * 0.65, 0.35, 1)
|
|
228
|
+
billboard.Size = UDim2.new(
|
|
229
|
+
self._baseSize.X.Scale * scale,
|
|
230
|
+
self._baseSize.X.Offset * scale,
|
|
231
|
+
self._baseSize.Y.Scale * scale,
|
|
232
|
+
self._baseSize.Y.Offset * scale
|
|
233
|
+
)
|
|
234
|
+
else
|
|
235
|
+
billboard.Size = self._baseSize
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
if self._fade then
|
|
239
|
+
local fadeStart = maxDistance * 0.65
|
|
240
|
+
local nearFade = if minDistance > 0 then minDistance else 0
|
|
241
|
+
local alpha = 0
|
|
242
|
+
if distance >= maxDistance then
|
|
243
|
+
alpha = 1
|
|
244
|
+
elseif distance > fadeStart then
|
|
245
|
+
alpha = (distance - fadeStart) / math.max(maxDistance - fadeStart, 0.01)
|
|
246
|
+
elseif nearFade > 0 and distance < nearFade + 4 then
|
|
247
|
+
alpha = 1 - math.clamp((distance - nearFade) / 4, 0, 1)
|
|
248
|
+
end
|
|
249
|
+
canvas.GroupTransparency = math.clamp(alpha, 0, 1)
|
|
250
|
+
else
|
|
251
|
+
canvas.GroupTransparency = 0
|
|
252
|
+
end
|
|
253
|
+
end)
|
|
254
|
+
table.insert(self._janitor, function()
|
|
255
|
+
connection:Disconnect()
|
|
256
|
+
end)
|
|
257
|
+
table.insert(self._janitor, function()
|
|
258
|
+
billboard:Destroy()
|
|
259
|
+
end)
|
|
260
|
+
|
|
261
|
+
return self
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
--[=[
|
|
265
|
+
@within Pin
|
|
266
|
+
]=]
|
|
267
|
+
function Pin:SetText(text: string)
|
|
268
|
+
if self.Gui:IsA("TextLabel") or self.Gui:IsA("TextButton") or self.Gui:IsA("TextBox") then
|
|
269
|
+
(self.Gui :: TextLabel).Text = text
|
|
270
|
+
return
|
|
271
|
+
end
|
|
272
|
+
local label = self.Gui:FindFirstChildWhichIsA("TextLabel", true)
|
|
273
|
+
if label then
|
|
274
|
+
label.Text = text
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
--[=[
|
|
279
|
+
@within Pin
|
|
280
|
+
]=]
|
|
281
|
+
function Pin:SetEnabled(enabled: boolean)
|
|
282
|
+
self._enabled = enabled
|
|
283
|
+
self.Billboard.Enabled = enabled and not self._occluded
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
--[=[
|
|
287
|
+
@within Pin
|
|
288
|
+
]=]
|
|
289
|
+
function Pin:SetMaxDistance(distance: number)
|
|
290
|
+
self.Billboard.MaxDistance = distance
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
--[=[
|
|
294
|
+
@within Pin
|
|
295
|
+
]=]
|
|
296
|
+
function Pin:Destroy()
|
|
297
|
+
if not self._alive then
|
|
298
|
+
return
|
|
299
|
+
end
|
|
300
|
+
self._alive = false
|
|
301
|
+
for _, cleanup in self._janitor do
|
|
302
|
+
cleanup()
|
|
303
|
+
end
|
|
304
|
+
table.clear(self._janitor)
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
Pin.new_ = Pin.new
|
|
308
|
+
|
|
309
|
+
return Pin
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Eryn L. K.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Eryn L. K.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|