Skip to content

Commit

Permalink
feat: Add RxTeamUtils.observePlayerTeam(player) and RxTeamUtils.obser…
Browse files Browse the repository at this point in the history
…vePlayerTeamColor(player)
  • Loading branch information
Quenty committed Feb 18, 2025
1 parent 267f976 commit 046d6cd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
29 changes: 29 additions & 0 deletions src/teamutils/src/Shared/RxTeamUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,38 @@ local Observable = require("Observable")
local Maid = require("Maid")
local Brio = require("Brio")
local RxBrioUtils = require("RxBrioUtils")
local RxInstanceUtils = require("RxInstanceUtils")
local Rx = require("Rx")

local RxTeamUtils = {}

function RxTeamUtils.observePlayerTeam(player)
return Rx.combineLatest({
team = RxInstanceUtils.observeProperty(player, "Team");
neutral = RxInstanceUtils.observeProperty(player, "Neutral")
}):Pipe({
Rx.map(function(state)
if state.neutral then
return nil
end

return state.team
end)
})
end

function RxTeamUtils.observePlayerTeamColor(player)
return RxTeamUtils.observePlayerTeam(player):Pipe({
Rx.switchMap(function(team)
if team then
return RxInstanceUtils.observeProperty(team, "TeamColor")
else
return Rx.of(nil)
end
end)
})
end

--[=[
Observes all players on a taem.
Expand Down
16 changes: 12 additions & 4 deletions src/teamutils/src/Shared/TeamUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
local TeamUtils = {}

function TeamUtils.areTeamMates(playerA, playerB)
if playerA.Neutral or playerB.Neutral then
local teamA = TeamUtils.getTeam(playerA)
local teamB = TeamUtils.getTeam(playerB)
if not teamA or not teamB then
return false
end
if not playerA.Team or not playerB.Team then
return false

return teamA == teamB
end

function TeamUtils.getTeam(player)
if player.Neutral then
return nil
end
return playerA.Team == playerB.Team

return player.Team
end

return TeamUtils

0 comments on commit 046d6cd

Please sign in to comment.