-
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #472 from Quenty/users/quenty/drag_fix
fix: Fix drag model in color picker code
- Loading branch information
Showing
26 changed files
with
615 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
src/clipcharacters/src/Client/ClipCharactersServiceClient.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.