Skip to content

Commit

Permalink
Update badger
Browse files Browse the repository at this point in the history
  • Loading branch information
gaymeowing committed Feb 25, 2025
1 parent 36fa35d commit 507002c
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions libs/badger/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export type Badge = {
type PlayerInfo = {
threads_waiting_for_id: { [number]: { thread } },
threads_waiting_for_all: { thread }?,
has_been_destroyed: true?,
owned: { [number]: true? },
has_been_destroyed: true?,
ids_to_check: { number },
amount_checked: number,
check_success: boolean,
Expand All @@ -32,8 +32,10 @@ local AWARD = BadgeService.AwardBadge
local IDS = {} :: { number }
local PAIR_INCREMENT = 9
local NULL = nil :: any
-- BadgeService:CheckUserBadgesAsync() allows 5 requests per player each minute
-- so every 12 seconds we should be trying to fetch
--[[
BadgeService:CheckUserBadgesAsync() allows 5 requests per player each minute
so every 12 seconds we should be trying to fetch
--]]
local FETCH_DELAY = 12
local TOTAL_IDS = 0

Expand All @@ -55,24 +57,6 @@ local function GET_INFO(player: Player): PlayerInfo?
return info
end

local function HAS_BADGE(player: Player, badge: Badge, info: PlayerInfo): boolean
local id = badge.id

if info.amount_checked >= badge.index then
return info.owned[id] :: any
else
local waitlists = info.threads_waiting_for_id
local threads = waitlists[id]

if threads then
table.insert(threads, coroutine.running())
else
waitlists[id] = { coroutine.running() }
end
return coroutine.yield()
end
end

local function GET_IDS_OWNED(player: Player): { [number]: true? }?
local info = GET_INFO(player)

Expand Down Expand Up @@ -164,10 +148,25 @@ end
function badger.has(player: Player, badge: Badge): boolean
local info = GET_INFO(player)

return if info then
HAS_BADGE(player, badge, info)
if info then
local id = badge.id

if info.amount_checked >= badge.index then
return info.owned[id] :: any
else
false
local waitlists = info.threads_waiting_for_id
local threads = waitlists[id]

if threads then
table.insert(threads, coroutine.running())
else
waitlists[id] = { coroutine.running() }
end
return coroutine.yield()
end
else
return false
end
end

--[[
Expand Down

0 comments on commit 507002c

Please sign in to comment.