1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-04 00:15:45 +02:00

added highscores

This commit is contained in:
MewMew 2019-11-04 19:57:02 +01:00
parent 3f1df45b87
commit 486f995872
2 changed files with 103 additions and 5 deletions

View File

@ -1,5 +1,7 @@
require "modules.no_turrets"
local RPG = require "modules.rpg"
local Tabs = require 'comfy_panel.main'
local Map_score = require "modules.map_score"
local unit_raffle = require "maps.biter_hatchery.raffle_tables"
local map_functions = require "tools.map_functions"
local Terrain = require "maps.biter_hatchery.terrain"
@ -238,27 +240,30 @@ local function on_entity_died(event)
if global.game_reset_tick then return end
if event.entity.type ~= "unit-spawner" then return end
local gui_str
local str
if event.entity.force.name == "east" then
game.print("East lost their Hatchery.", {100, 100, 100})
gui_str = ">>>> West team has won the game!!! <<<<"
str = ">>>> West team has won the game!!! <<<<"
for _, player in pairs(game.forces.east.connected_players) do
player.play_sound{path="utility/game_lost", volume_modifier=0.85}
end
for _, player in pairs(game.forces.west.connected_players) do
player.play_sound{path="utility/game_won", volume_modifier=0.85}
player.play_sound{path="utility/game_won", volume_modifier=0.85}
Map_score.set_score(player, Map_score.get_score(player) + 1)
end
else
game.print("West lost their Hatchery.", {100, 100, 100})
gui_str = ">>>> East team has won the game!!! <<<<"
str = ">>>> East team has won the game!!! <<<<"
for _, player in pairs(game.forces.west.connected_players) do
player.play_sound{path="utility/game_lost", volume_modifier=0.85}
end
for _, player in pairs(game.forces.east.connected_players) do
player.play_sound{path="utility/game_won", volume_modifier=0.85}
Map_score.set_score(player, Map_score.get_score(player) + 1)
end
end
game.print(string.upper(str), {250, 120, 0})
game.print("Next round starting in 30 seconds..", {150, 150, 150})
for _, player in pairs(game.forces.spectator.connected_players) do
@ -268,7 +273,8 @@ local function on_entity_died(event)
for _, player in pairs(game.connected_players) do
for _, child in pairs(player.gui.left.children) do child.destroy() end
player.gui.left.add({type = "frame", name = "biter_hatchery_game_won", caption = gui_str})
Tabs.comfy_panel_call_tab(player, "Map Scores")
--player.gui.left.add({type = "frame", name = "biter_hatchery_game_won", caption = str})
end
end

92
modules/map_score.lua Normal file
View File

@ -0,0 +1,92 @@
local Public = {}
local function get_sorted_score()
local list = {}
for player_index, score_points in pairs(global.custom_highscore.score_list) do
table.insert(list, {name = game.players[player_index].name, points = score_points})
end
local list_size = #list
if list_size == 0 then return list end
table.sort(list, function (a, b) return a.points > b.points end)
return list
end
local score_list = (function (player, frame)
local highscore = global.custom_highscore
frame.clear()
frame.style.padding = 4
frame.style.margin = 0
local line = frame.add { type = "line"}
line.style.top_margin = 4
line.style.bottom_margin = 4
local label = frame.add ({ type = "label", caption = highscore.caption})
label.style.font = "heading-1"
label.style.minimal_width = 780
label.style.horizontal_align = "center"
label.style.vertical_align = "center"
local line = frame.add { type = "line"}
line.style.top_margin = 4
line.style.bottom_margin = 4
local scroll_pane = frame.add { type = "scroll-pane", name = "scroll_pane", direction = "vertical", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"}
scroll_pane.style.maximal_height = 320
scroll_pane.style.minimal_height = 320
local t = scroll_pane.add {type = "table", column_count = 3}
local label = t.add ({ type = "label", caption = "#"})
label.style.minimal_width = 30
label.style.font = "heading-2"
label.style.padding = 3
local label = t.add ({ type = "label", caption = "Player:"})
label.style.minimal_width = 160
label.style.font = "heading-2"
label.style.padding = 3
local label = t.add ({ type = "label", caption = "Won rounds:"})
label.style.minimal_width = 160
label.style.font = "heading-2"
label.style.padding = 3
for key, score in pairs(get_sorted_score()) do
local label = t.add ({ type = "label", caption = key})
label.style.font = "heading-2"
label.style.padding = 1
local label = t.add ({ type = "label", caption = score.name})
label.style.font = "heading-2"
label.style.padding = 1
label.style.font_color = game.players[score.name].chat_color
local label = t.add ({ type = "label", caption = score.points})
label.style.font = "heading-2"
label.style.padding = 1
end
end
)
function Public.set_score(player, count)
local score_list = global.custom_highscore.score_list
score_list[player.index] = count
end
function Public.get_score(player)
local score_list = global.custom_highscore.score_list
if not score_list[player.index] then score_list[player.index] = 0 end
return score_list[player.index]
end
local function on_init()
global.custom_highscore = {
caption = "Highscores of the session:",
score_list = {},
}
end
comfy_panel_tabs["Map Scores"] = score_list
local event = require 'utils.event'
event.on_init(on_init)
return Public