Skip to content

Commit

Permalink
Organized + Ported to Cold Fusion v5
Browse files Browse the repository at this point in the history
  • Loading branch information
nightcycle committed Oct 2, 2022
1 parent 3a81766 commit d9e5c53
Show file tree
Hide file tree
Showing 27 changed files with 1,046 additions and 1,087 deletions.
7 changes: 7 additions & 0 deletions scripts/sourceServe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# A sample Bash script
echo Starting Sourcemap Update # This is a comment, too!
rojo sourcemap test.project.json --output sourcemap.json
echo Restarting Rojo
rojo serve test.project.json
echo Done
2 changes: 1 addition & 1 deletion sourcemap.json

Large diffs are not rendered by default.

52 changes: 28 additions & 24 deletions src/BillboardFrame/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,55 @@ local packages = package.Parent
local Util = require(package.Util)

local Types = require(package.Types)
type ParameterValue<T> = Types.ParameterValue<T>

local ColdFusion = require(packages.coldfusion)
type Fuse = ColdFusion.Fuse
type State<T> = ColdFusion.State<T>
type ValueState<T> = ColdFusion.ValueState<T>
type CanBeState<T> = ColdFusion.CanBeState<T>

local Maid = require(packages.maid)
type Maid = Maid.Maid

export type BillboardFrameParameters = Types.FrameParameters & {
Parent: ParameterValue<Instance>?,
Position: ParameterValue<Vector3>?,
Size: ParameterValue<Vector2>?,
LightInfluence: ParameterValue<number>?,
AlwaysOnTop: ParameterValue<boolean>?,
MaxDistance: ParameterValue<number>?,
AnchorPoint: ParameterValue<Vector2>?,
Parent: CanBeState<Instance>?,
Position: CanBeState<Vector3>?,
Size: CanBeState<Vector2>?,
LightInfluence: CanBeState<number>?,
AlwaysOnTop: CanBeState<boolean>?,
MaxDistance: CanBeState<number>?,
AnchorPoint: CanBeState<Vector2>?,
}

export type BillboardFrame = Frame

function Constructor(config: BillboardFrameParameters): BillboardFrame
-- init workspace
local _Maid = Maid.new()
local _Fuse = ColdFusion.fuse(_Maid)
local _Computed = _Fuse.Computed
local _Value = _Fuse.Value
local _import = _Fuse.import
local _new = _Fuse.new
local _mount = _Fuse.mount
local _import = _Fuse.import
local _OUT = _Fuse.OUT
local _REF = _Fuse.REF
local _CHILDREN = _Fuse.CHILDREN
local _ON_EVENT = _Fuse.ON_EVENT
local _ON_PROPERTY = _Fuse.ON_PROPERTY
local _Value = _Fuse.Value
local _Computed = _Fuse.Computed

local P: any = _import(config.Parent, nil); local Parent: State<Instance> = P

local v3Def: any = Vector3.new(0,0,0)
local v2Def: any = Vector2.new(0,0)
local PO: any = _import(config.Position, v3Def); local Position: State<Vector3> = PO
local S: any = _import(config.Size, v2Def); local Size: State<Vector2> = S
-- unload config states
local Parent: State<Instance?> = _import(config.Parent, nil :: Instance?) :: any
local Position = _import(config.Position :: any, Vector3.new(0,0,0)) :: State<Vector3>
local Size: State<Vector2> = _import(config.Size :: any, Vector2.new(0,0)) :: any
local LightInfluence = _import(config.LightInfluence, 0)
local AlwaysOnTop = _import(config.AlwaysOnTop, false)
local MaxDistance = _import(config.MaxDistance, 100)
local AnchorPoint = _import(config.AnchorPoint, Vector2.new(0.5,0.5))

local partParent: any = workspace


-- constructing instances
local Part: any = _new "Part"{
Parent = partParent,
Parent = workspace,
Position = Position,
Transparency = 1,
Size = Vector3.new(1,1,1)*0.05,
Expand All @@ -60,7 +64,6 @@ function Constructor(config: BillboardFrameParameters): BillboardFrame
}

local SurfaceGui = _new "BillboardGui" {
-- Name = Name,
Parent = Parent,
Adornee = Part,
AlwaysOnTop = AlwaysOnTop,
Expand All @@ -72,6 +75,7 @@ function Constructor(config: BillboardFrameParameters): BillboardFrame
MaxDistance = MaxDistance,
}

-- assemble final parameters
local parameters: any = {
Parent = SurfaceGui,
Position = UDim2.fromScale(0.5,0.5),
Expand All @@ -90,8 +94,8 @@ function Constructor(config: BillboardFrameParameters): BillboardFrame
end
end

local Output = _new "Frame" (parameters)

-- construct output instance
local Output: Frame = _new "Frame" (parameters) :: any
Util.cleanUpPrep(_Maid, Output)

return Output
Expand Down
79 changes: 43 additions & 36 deletions src/BoardFrame/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,79 @@ local packages = package.Parent
local Util = require(package.Util)

local Types = require(package.Types)
type ParameterValue<T> = Types.ParameterValue<T>

local ColdFusion = require(packages.coldfusion)
type Fuse = ColdFusion.Fuse
type State<T> = ColdFusion.State<T>
type ValueState<T> = ColdFusion.ValueState<T>
type CanBeState<T> = ColdFusion.CanBeState<T>

local Maid = require(packages.maid)
type Maid = Maid.Maid

local math = require(packages:WaitForChild("math"))

export type BoardFrameParameters = Types.ViewportFrameParameters & {
-- Color: ParameterValue<Color3>?,
PixelsPerStud: ParameterValue<number>?,
CanvasPosition: ParameterValue<Vector2>?,
CanvasTransparency: ParameterValue<number>?,
CanvasColor: ParameterValue<Color3>?,
CanvasMaterial: ParameterValue<string>?,
CanvasMaterialVariant: ParameterValue<string>?,
LockPosition: ParameterValue<boolean>?,
LockZoom: ParameterValue<boolean>?,
Zoom: ParameterValue<number>?,
MinZoom: ParameterValue<number>?,
MaxZoom: ParameterValue<number>?,
ZoomSpeed: ParameterValue<number>?,
CameraHeight: ParameterValue<number>?,
-- Color: CanBeState<Color3>?,
PixelsPerStud: CanBeState<number>?,
CanvasPosition: CanBeState<Vector2>?,
CanvasTransparency: CanBeState<number>?,
CanvasColor: CanBeState<Color3>?,
CanvasMaterial: CanBeState<string>?,
CanvasMaterialVariant: CanBeState<string>?,
LockPosition: CanBeState<boolean>?,
LockZoom: CanBeState<boolean>?,
Zoom: CanBeState<number>?,
MinZoom: CanBeState<number>?,
MaxZoom: CanBeState<number>?,
ZoomSpeed: CanBeState<number>?,
CameraHeight: CanBeState<number>?,
}

export type BoardFrame = ViewportFrame

function Constructor(config: BoardFrameParameters): BoardFrame
-- init workspace
local _Maid = Maid.new()
local _Fuse = ColdFusion.fuse(_Maid)
local _Computed = _Fuse.Computed
local _Value = _Fuse.Value
local _import = _Fuse.import
local _new = _Fuse.new

-- local Color = _import(config.Color, Color3.new(0.3,0,0))
local _mount = _Fuse.mount
local _import = _Fuse.import
local _OUT = _Fuse.OUT
local _REF = _Fuse.REF
local _CHILDREN = _Fuse.CHILDREN
local _ON_EVENT = _Fuse.ON_EVENT
local _ON_PROPERTY = _Fuse.ON_PROPERTY
local _Value = _Fuse.Value
local _Computed = _Fuse.Computed

-- unload config states
local Size = _import(config.Size, UDim2.fromScale(1,1))
local Position = _import(config.Position, UDim2.fromScale(0.5,0.5))
local AnchorPoint = _import(config.AnchorPoint, Vector2.new(0.5,0.5))

local PixelsPerStud = _import(config.PixelsPerStud, 20)
local CanvasPosition = _Value(if typeof(config.CanvasPosition) == "Vector2" then config.CanvasPosition elseif typeof(config.CanvasPosition) == "table" then config.CanvasPosition:Get() else Vector2.new(0,0))
local CanvasTransparency = _import(config.CanvasTransparency, 0)
local CanvasColor = _import(config.CanvasColor, Color3.new(1,1,1))
local CanvasMaterial = _import(config.CanvasMaterial, "SmoothPlastic")
local CanvasMaterialVariant = _import(config.CanvasMaterialVariant, "")

local LockPosition = _import(config.LockPosition, false)
local LockZoom = _import(config.LockZoom, false)

local Zoom = _Value(if typeof(config.Zoom) == "number" then config.Zoom elseif typeof(config.Zoom) == "table" then config.Zoom:Get() else 1)
local MinZoom = _import(config.MinZoom, 1)
local MaxZoom = _import(config.MaxZoom, 10)
local ZoomSpeed = _import(config.ZoomSpeed, 4)
local CameraHeight = _import(config.CameraHeight, 100)

-- init internal states
local Zoom = _Value(if typeof(config.Zoom) == "number" then config.Zoom elseif typeof(config.Zoom) == "table" then config.Zoom:Get() else 1)
local Delta = _Value(1/60)
local AbsoluteSize = _Value(Vector2.new(0,0))
local CanvasSize = _Computed(function(absSize: Vector2, pxRatio: number)
return absSize / pxRatio
end, AbsoluteSize, PixelsPerStud) --_import(config.CanvasSize, Vector2.new(60,40))

local SizeRatio = _Computed(function(absSize: Vector2)
return absSize.X / absSize.Y
end, AbsoluteSize)

local CameraHeight = _import(config.CameraHeight, 100)
local CameraFieldOfView = _Computed(function(zoom: number, canvasSize: Vector2, z: number)
local y = canvasSize.Y
local goalY = y / zoom
Expand Down Expand Up @@ -113,17 +116,21 @@ function Constructor(config: BoardFrameParameters): BoardFrame
end
return Vector2.new(x,y)
end, CanvasPosition, CameraWindowSize, CanvasSize)
local CameraCFrame = _Computed(AbsoluteCanvasPosition, CameraHeight, CameraFieldOfView, function(canvasPos: Vector2, height: number, fov: number)
local CameraCFrame = _Computed(function(canvasPos: Vector2, height: number, fov: number)
local pos = Vector3.new(canvasPos.X, canvasPos.Y, height)
return CFrame.new(pos, Vector3.new(canvasPos.X, canvasPos.Y, 0))
end)
end, AbsoluteCanvasPosition, CameraHeight, CameraFieldOfView)

-- constructing instances
local Camera = _Fuse.new "Camera" {
CFrame = CameraCFrame,
FieldOfView = CameraFieldOfView,--:Tween(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut),
FieldOfView = CameraFieldOfView,
}
local WorldModel: any = _Fuse.new "WorldModel" {
Name = "Canvas",
}

-- assemble final parameters
local parameters: any = {
Parent = _import(config.Parent, nil),
Name = _import(config.Name, script.Name),
Expand All @@ -133,7 +140,7 @@ function Constructor(config: BoardFrameParameters): BoardFrame
AnchorPoint = AnchorPoint,
Transparency = 1,
CurrentCamera = Camera,
Children = {
[_CHILDREN] = {
WorldModel,
Camera,
}
Expand All @@ -159,8 +166,8 @@ function Constructor(config: BoardFrameParameters): BoardFrame
end
end

-- print("Parameters", parameters, self)
local Output = _Fuse.new("ViewportFrame")(parameters)
-- construct output instance
local Output: ViewportFrame = _Fuse.new("ViewportFrame")(parameters) :: any
Util.cleanUpPrep(_Maid, Output)

local _Canvas = _Fuse.new "Part" {
Expand All @@ -175,17 +182,17 @@ function Constructor(config: BoardFrameParameters): BoardFrame
Transparency = CanvasTransparency,
Color = CanvasColor,
["CFrame"] = CFrame.new(Vector3.new(0,0,-1), Vector3.new(0,0,1)),
Size = _Computed(CanvasSize, function(size)
Size = _Computed(function(size: Vector2)
return Vector3.new(size.X, size.Y, 0.01)
end),
end, CanvasSize),
}
local PreviousMousePosition = _Value(Vector2.new(0,0))
local MousePosition = _Value(Vector2.new(0,0))
local MouseDelta = _Computed(function(mPos:Vector2, pMPos:Vector2)
return pMPos - mPos
end, MousePosition, PreviousMousePosition)

local IsHovering = _Computed(function(mPos)
local IsHovering = _Computed(function(mPos: Vector2)
local sGui = Output:FindFirstAncestorWhichIsA("BasePlayerGui")
if not sGui then return false end
assert(sGui ~= nil)
Expand Down
Loading

0 comments on commit d9e5c53

Please sign in to comment.