@quenty/fakeskybox 11.15.0 → 11.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,167 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- Allow transitions between skyboxes
4
- @class FakeSkybox
5
- ]=]
6
-
7
- local require = require(script.Parent.loader).load(script)
8
-
9
- local Workspace = game:GetService("Workspace")
10
-
11
- local AccelTween = require("AccelTween")
12
- local FakeSkyboxSide = require("FakeSkyboxSide")
13
- local Maid = require("Maid")
14
- local Signal = require("Signal")
15
-
16
- local SKYBOX_PROPERTY_IMAGE_MAP = {}
17
- do
18
- local properties = {
19
- Top = "Up",
20
- Bottom = "Dn",
21
-
22
- -- Bind backwards
23
- Right = "Lf",
24
- Left = "Rt",
25
-
26
- Front = "Ft",
27
- Back = "Bk",
28
- }
29
- for Surface, Direction in properties do
30
- SKYBOX_PROPERTY_IMAGE_MAP[Enum.NormalId[Surface]] = "Skybox" .. Direction
31
- end
32
- end
33
-
34
- local FakeSkybox = {}
35
- FakeSkybox.__index = FakeSkybox
36
- FakeSkybox.ClassName = "FakeSkybox"
37
- FakeSkybox._partSize = 1024
38
-
39
- --[=[
40
- Creates a new FakeSkybox
41
- @param skybox Skybox
42
- @return FakeSkybox
43
- ]=]
44
- function FakeSkybox.new(skybox)
45
- local self = setmetatable({}, FakeSkybox)
46
-
47
- self._maid = Maid.new()
48
-
49
- self._parentFolder = Instance.new("Folder")
50
- self._parentFolder.Name = "Skybox"
51
- self._maid:GiveTask(self._parentFolder)
52
-
53
- self._sides = {}
54
- for _, NormalId in Enum.NormalId:GetEnumItems() do
55
- self._sides[NormalId] = FakeSkyboxSide.new(self._partSize, NormalId, self._parentFolder)
56
- --self._maid[NormalId] = self._sides[NormalId]
57
- end
58
-
59
- self._visible = false
60
- self.VisibleChanged = Signal.new()
61
-
62
- self._percentVisible = AccelTween.new(0.25)
63
- self._percentVisible.t = 0
64
- self._percentVisible.p = 0
65
-
66
- if skybox then
67
- self:SetSkybox(skybox)
68
- end
69
-
70
- self._parentFolder.Parent = Workspace.CurrentCamera
71
-
72
- return self
73
- end
74
-
75
- --[=[
76
- @param partSize number
77
- @return FakeSkybox -- self
78
- ]=]
79
- function FakeSkybox:SetPartSize(partSize)
80
- self._partSize = partSize or error("No partSize")
81
-
82
- for _, side in self._sides do
83
- side:SetPartSize(self._partSize)
84
- end
85
-
86
- return self
87
- end
88
-
89
- --[=[
90
- @param doNotAnimate boolean
91
- ]=]
92
- function FakeSkybox:Show(doNotAnimate: boolean?)
93
- if self._visible then
94
- return
95
- end
96
-
97
- self._visible = true
98
- self._percentVisible.t = 1
99
-
100
- if doNotAnimate then
101
- self._percentVisible.p = 1
102
- end
103
- self.VisibleChanged:Fire(self._visible, doNotAnimate)
104
- end
105
-
106
- --[=[
107
- @param doNotAnimate boolean
108
- ]=]
109
- function FakeSkybox:Hide(doNotAnimate: boolean?)
110
- if not self._visible then
111
- return
112
- end
113
-
114
- self._visible = false
115
- self._percentVisible.t = 0
116
-
117
- if doNotAnimate then
118
- self._percentVisible.p = 0
119
- end
120
- self.VisibleChanged:Fire(self._visible, doNotAnimate)
121
- end
122
-
123
- --[=[
124
- @param skybox Skybox
125
- @return FakeSkybox -- self
126
- ]=]
127
- function FakeSkybox:SetSkybox(skybox)
128
- self._skybox = skybox or error("No skybox")
129
-
130
- for normal, side in self._sides do
131
- local propertyName = SKYBOX_PROPERTY_IMAGE_MAP[normal]
132
- side:SetImage(skybox[propertyName])
133
- end
134
-
135
- return self
136
- end
137
-
138
- --[=[
139
- Returns whether the skybox is visible.
140
- @return boolean
141
- ]=]
142
- function FakeSkybox:IsVisible(): boolean
143
- return self._visible
144
- end
145
-
146
- --[=[
147
- Updates the rendering
148
- @param baseCFrame CFrame
149
- ]=]
150
- function FakeSkybox:UpdateRender(baseCFrame: CFrame)
151
- local transparency = 1 - self._percentVisible.p
152
-
153
- for _, side in self._sides do
154
- side:UpdateRender(baseCFrame)
155
- side:SetTransparency(transparency)
156
- end
157
- end
158
-
159
- --[=[
160
- Cleans up the fake skybox
161
- ]=]
162
- function FakeSkybox:Destroy()
163
- self._maid:DoCleaning()
164
- self._maid = nil
165
- end
166
-
167
- return FakeSkybox
@@ -1,89 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class FakeSkyboxSide
4
- ]=]
5
-
6
- local FakeSkyboxSide = {}
7
- FakeSkyboxSide.__index = FakeSkyboxSide
8
- FakeSkyboxSide.ClassName = "FakeSkyboxSide"
9
- FakeSkyboxSide.CanvasSize = 1024
10
- FakeSkyboxSide.PartWidth = 1
11
-
12
- function FakeSkyboxSide.new(PartSize, Normal, Parent)
13
- local self = setmetatable({}, FakeSkyboxSide)
14
-
15
- self.PartSize = PartSize or error("No PartSize")
16
- self.Transparency = 1
17
- self.Normal = Normal or error("No Normal")
18
-
19
- self.Part = Instance.new("Part")
20
- self.Part.Name = "SkyboxSide" .. self.Normal.Name
21
- self.Part.Anchored = true
22
- self.Part.Transparency = 1
23
- self.Part.CanCollide = false
24
-
25
- self.SurfaceGui = Instance.new("SurfaceGui")
26
- self.SurfaceGui.Adornee = self.Part
27
- self.SurfaceGui.CanvasSize = Vector2.new(self.CanvasSize, self.CanvasSize)
28
- self.SurfaceGui.LightInfluence = 0
29
- self.SurfaceGui.Face = Enum.NormalId.Front
30
- self.SurfaceGui.Parent = self.Part
31
-
32
- local ImageLabel = Instance.new("ImageLabel")
33
- ImageLabel.AnchorPoint = Vector2.new(0.5, 0.5)
34
- ImageLabel.Position = UDim2.fromScale(0.5, 0.5)
35
- ImageLabel.Size = UDim2.fromScale(1, 1)
36
- ImageLabel.ImageTransparency = self.Transparency
37
- ImageLabel.BackgroundColor3 = Color3.new(0, 0, 0)
38
- ImageLabel.BackgroundTransparency = 1
39
- ImageLabel.BorderSizePixel = 0
40
-
41
- ImageLabel.Parent = self.SurfaceGui
42
- self.ImageLabel = ImageLabel
43
-
44
- self:UpdateSizing()
45
-
46
- self.Part.Parent = Parent
47
-
48
- return self
49
- end
50
-
51
- function FakeSkyboxSide:SetPartSize(PartSize)
52
- self.PartSize = PartSize or error("No PartSize")
53
- self:UpdateSizing()
54
-
55
- return self
56
- end
57
-
58
- function FakeSkyboxSide:UpdateSizing()
59
- self.Part.Size = Vector3.new(self.PartSize, self.PartSize, self.PartWidth)
60
-
61
- local Direction = Vector3.FromNormalId(self.Normal)
62
- local Offset = Direction * self.PartWidth / 2
63
-
64
- self.Relative = CFrame.new(Direction * (self.PartSize / 2) + Offset) * CFrame.new(Vector3.zero, -Direction)
65
-
66
- if self.Normal == Enum.NormalId.Bottom then
67
- -- Hack
68
- self.Relative = self.Relative * CFrame.Angles(0, 0, math.pi)
69
- end
70
- end
71
-
72
- function FakeSkyboxSide:SetImage(Image)
73
- self.ImageLabel.Image = Image
74
-
75
- return self
76
- end
77
-
78
- function FakeSkyboxSide:SetTransparency(Transparency)
79
- self.Transparency = Transparency or error("No Transparency")
80
- self.ImageLabel.ImageTransparency = Transparency
81
-
82
- return self
83
- end
84
-
85
- function FakeSkyboxSide:UpdateRender(RelativeCFrame)
86
- self.Part.CFrame = RelativeCFrame * self.Relative
87
- end
88
-
89
- return FakeSkyboxSide