Skip to content

Commit

Permalink
add hook to override mapvote selection and update db type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
plally committed Jun 8, 2024
1 parent 65e3989 commit 7428df7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lua/mapvote/server/modules/db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function DB.AddPlayCount( map, count )
end

---@param limit number
---@return {map:string, play_count:number, last_played:number}[]
---@return {map:string, play_count:string, last_played:string}[]
function DB.GetRecentMaps( limit )
if not isnumber( limit ) then
error( "DB.GetRecentMaps: Limit was not a number (" .. tostring( limit ) .. ")" )
Expand All @@ -47,7 +47,7 @@ function DB.GetRecentMaps( limit )
return data
end

---@return {map:string, play_count:number, last_played:number}[]
---@return {map:string, play_count:string, last_played:string}[]
function DB.GetAllMaps()
local data = sql.Query( "SELECT * FROM mapvote_played_maps" )
if data == false then
Expand Down
16 changes: 9 additions & 7 deletions lua/mapvote/server/modules/map_vote.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ function MapVote.Start( length )

local maps = MapVote.getMapList()

local mapsInVote = {}

for _, map in RandomPairs( maps ) do
if MapVote.isMapAllowed( map ) then
table.insert( mapsInVote, map )

if #mapsInVote >= MapVote.config.MapLimit then break end
local mapsInVote = hook.Run( "MapVote_SelectMaps" )
if not mapsInVote then
mapsInVote = {}
for _, map in RandomPairs( maps ) do
if MapVote.isMapAllowed( map ) then
table.insert( mapsInVote, map )

if #mapsInVote >= MapVote.config.MapLimit then break end
end
end
end

Expand Down

0 comments on commit 7428df7

Please sign in to comment.