Skip to content

Commit

Permalink
Merge pull request #472 from Quenty/users/quenty/drag_fix
Browse files Browse the repository at this point in the history
fix: Fix drag model in color picker code
  • Loading branch information
Quenty authored May 14, 2024
2 parents 08385f1 + 3ac5e73 commit 7e9141d
Show file tree
Hide file tree
Showing 26 changed files with 615 additions and 575 deletions.
34 changes: 17 additions & 17 deletions src/buttondragmodel/src/Client/ButtonDragModel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ function ButtonDragModel.new(initialButton)
self._button = self._maid:Add(ValueObject.new(nil))

self._absoluteSize = self._maid:Add(ValueObject.new(Vector2.zero, "Vector2"))
self._isDragging = self._maid:Add(ValueObject.new(false, "boolean"))
self._isPressed = self._maid:Add(ValueObject.new(false, "boolean"))
self._clampWithinButton = self._maid:Add(ValueObject.new(false, "boolean"))

self._activePositions = {}

self._maid:GiveTask(self._dragPosition.Changed:Connect(function()
self._isDragging.Value = self._dragPosition.Value ~= nil
self._isPressed.Value = self._dragPosition.Value ~= nil
end))

self.DragPositionChanged = self._dragPosition.Changed
self.IsDraggingChanged = self._isDragging.Changed
self.IsDraggingChanged = self._isPressed.Changed

if initialButton then
self:SetButton(initialButton)
Expand All @@ -62,20 +62,29 @@ function ButtonDragModel.new(initialButton)
return self
end

--[=[
Returns true if pressed
@return boolean
]=]
function ButtonDragModel:IsPressed()
return self._isPressed.Value
end

--[=[
Observes if anything is pressing down on the button itself
@return Observable<boolean>
]=]
function ButtonDragModel:ObserveIsDragging()
return self._isDragging:Observe()
function ButtonDragModel:ObserveIsPressed()
return self._isPressed:Observe()
end

--[=[
@return Observable<Brio<true>>
]=]
function ButtonDragModel:ObserveIsDraggingBrio()
return self._isDragging:ObserveBrio(function(value)
function ButtonDragModel:ObserveIsPressedBrio()
return self._isPressed:ObserveBrio(function(value)
return value
end)
end
Expand All @@ -94,15 +103,6 @@ function ButtonDragModel:GetDragDelta()
return self._dragDelta.Value
end

--[=[
Returns true if pressed
@return boolean
]=]
function ButtonDragModel:GetIsPressed()
return self._isDragging.Value
end

--[=[
Returns the scale position on the Gui from 0 to 1
Expand Down Expand Up @@ -323,7 +323,7 @@ function ButtonDragModel:_updateCurrentPosition()

if self._clampWithinButton.Value then
x = math.clamp(x, 0, 1)
y = math.clamp(x, 0, 1)
y = math.clamp(y, 0, 1)
end

local position = Vector2.new(x, y)
Expand Down
10 changes: 9 additions & 1 deletion src/clipcharacters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@
"Quenty"
],
"dependencies": {
"@quenty/baseobject": "file:../baseobject",
"@quenty/brio": "file:../brio",
"@quenty/characterutils": "file:../characterutils",
"@quenty/loader": "file:../loader",
"@quenty/maid": "file:../maid",
"@quenty/remoting": "file:../remoting"
"@quenty/playerutils": "file:../playerutils",
"@quenty/remoting": "file:../remoting",
"@quenty/servicebag": "file:../servicebag",
"@quenty/statestack": "file:../statestack",
"@quenty/table": "file:../table",
"@quenty/valueobject": "file:../valueobject"
},
"publishConfig": {
"access": "public"
Expand Down
80 changes: 80 additions & 0 deletions src/clipcharacters/src/Client/ClipCharacters.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--[=[
Clip characters locally on the client of other clients so they don't interfer with physics.
@class ClipCharacters
]=]

local require = require(script.Parent.loader).load(script)

local BaseObject = require("BaseObject")
local ClipCharactersServiceConstants = require("ClipCharactersServiceConstants")
local RxBrioUtils = require("RxBrioUtils")
local RxCharacterUtils = require("RxCharacterUtils")
local RxPlayerUtils = require("RxPlayerUtils")

local ClipCharacters = setmetatable({}, BaseObject)
ClipCharacters.ClassName = "ClipCharacters"
ClipCharacters.__index = ClipCharacters

--[=[
Prevents characters from clipping together
@return ClipCharacters
]=]
function ClipCharacters.new()
local self = setmetatable(BaseObject.new(), ClipCharacters)

self._maid:GiveTask(RxPlayerUtils.observePlayersBrio():Pipe({
RxBrioUtils.flatMapBrio(function(player)
return RxCharacterUtils.observeLastCharacterBrio(player)
end)
}):Subscribe(function(brio)
if brio:IsDead() then
return
end

local maid, character = brio:ToMaidAndValue()
self:_setupCharacter(maid, character)
end))

return self
end

function ClipCharacters:_onDescendantAdded(originalTable, descendant)
if not originalTable[descendant] and descendant:IsA("BasePart") then
originalTable[descendant] = descendant.CollisionGroup
descendant.CollisionGroup = ClipCharactersServiceConstants.COLLISION_GROUP_NAME
end
end

function ClipCharacters:_onDescendantRemoving(originalTable, descendant)
if originalTable[descendant] then
descendant.CollisionGroup = originalTable[descendant]
originalTable[descendant] = nil
end
end

function ClipCharacters:_setupCharacter(maid, character)
local originalTable = {}

maid:GiveTask(character.DescendantAdded:Connect(function(descendant)
self:_onDescendantAdded(originalTable, descendant)
end))

maid:GiveTask(character.DescendantRemoving:Connect(function(descendant)
self:_onDescendantRemoving(originalTable, descendant)
end))

-- Cleanup
maid:GiveTask(function()
for descendant, _ in pairs(originalTable) do
self:_onDescendantRemoving(originalTable, descendant)
end
end)

-- Initialize
for _, descendant in pairs(character:GetDescendants()) do
self:_onDescendantAdded(originalTable, descendant)
end
end

return ClipCharacters
47 changes: 47 additions & 0 deletions src/clipcharacters/src/Client/ClipCharactersServiceClient.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--[=[
@class ClipCharactersServiceClient
]=]

local require = require(script.Parent.loader).load(script)

local ClipCharacters = require("ClipCharacters")
local Maid = require("Maid")
local StateStack = require("StateStack")

local ClipCharactersServiceClient = {}
ClipCharactersServiceClient.ServiceName = "ClipCharactersServiceClient"

function ClipCharactersServiceClient:Init(serviceBag)
assert(not self._serviceBag, "Already initialized")
self._serviceBag = assert(serviceBag, "No serviceBag")
self._maid = Maid.new()

self._disableCollisions = self._maid:Add(StateStack.new(false, "boolean"))
end

--[=[
Disables collisions between default geometry and other charaters which stops some random physics
glitches from occuring.
]=]
function ClipCharactersServiceClient:PushDisableCharacterCollisionsWithDefault()
return self._disableCollisions:PushState(true)
end

function ClipCharactersServiceClient:Start()
self._maid:GiveTask(self._disableCollisions:ObserveBrio(function(value)
return value
end):Subscribe(function(brio)
if brio:IsDead() then
return
end

local maid = brio:ToMaid()
maid:GiveTask(ClipCharacters.new())
end))
end

function ClipCharactersServiceClient:Destroy()
self._maid:DoCleaning()
end

return ClipCharactersServiceClient
32 changes: 32 additions & 0 deletions src/clipcharacters/src/Server/ClipCharactersService.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--[=[
@class ClipCharactersService
]=]

local require = require(script.Parent.loader).load(script)

local PhysicsService = game:GetService("PhysicsService")

local Maid = require("Maid")
local ClipCharactersServiceConstants = require("ClipCharactersServiceConstants")

local ClipCharactersService = {}
ClipCharactersService.ServiceName = "ClipCharactersService"

function ClipCharactersService:Init(serviceBag)
assert(not self._serviceBag, "Already initialized")
self._serviceBag = assert(serviceBag, "No serviceBag")
self._maid = Maid.new()

self:_setupPhysicsGroup()
end

function ClipCharactersService:_setupPhysicsGroup()
PhysicsService:RegisterCollisionGroup(ClipCharactersServiceConstants.COLLISION_GROUP_NAME)
PhysicsService:CollisionGroupSetCollidable(ClipCharactersServiceConstants.COLLISION_GROUP_NAME, "Default", false)
end

function ClipCharactersService:Destroy()
self._maid:DoCleaning()
end

return ClipCharactersService
Loading

0 comments on commit 7e9141d

Please sign in to comment.