1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-11 13:39:14 +02:00

Merge pull request #443 from ComfyFactory/mtn-modules-changes

Changes for Mtn v3 and modules
This commit is contained in:
Gerkiz 2023-12-08 13:53:36 +01:00 committed by GitHub
commit e8c2c10b31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 905 additions and 474 deletions

View File

@ -4,8 +4,7 @@ local Collapse = require 'modules.collapse'
local RPG = require 'modules.rpg.main'
local WD = require 'modules.wave_defense.table'
local Alert = require 'utils.alert'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local Color = require 'utils.color_presets'
local ICF = require 'maps.mountain_fortress_v3.ic.functions'
@ -40,7 +39,7 @@ local clear_breach_text_and_render = function()
end
local collapse_message =
Token.register(
Task.register(
function(data)
local pos = data.position
local message = ({'breached_wall.collapse_start'})
@ -52,7 +51,7 @@ local collapse_message =
)
local driving_state_changed_token =
Token.register(
Task.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
@ -81,7 +80,7 @@ local driving_state_changed_token =
)
local spidertron_unlocked =
Token.register(
Task.register(
function(event)
if event then
local message = ({'breached_wall.spidertron_unlocked'})
@ -94,7 +93,7 @@ local spidertron_unlocked =
)
local first_player_to_zone =
Token.register(
Task.register(
function(data)
local player = data.player
if not player or not player.valid then
@ -108,7 +107,7 @@ local first_player_to_zone =
)
local artillery_warning =
Token.register(
Task.register(
function()
local message = ({'breached_wall.artillery_warning'})
Alert.alert_all_players(10, message)
@ -137,7 +136,7 @@ local breach_wall_warning_teleport = function(player)
end
local spidertron_too_far =
Token.register(
Task.register(
function(data)
local player = data.player
local message = ({'breached_wall.cheating_through', player.name})

View File

@ -0,0 +1,163 @@
--made by Hanakocz
-- modified by gerkiz
--charge your armor equipment from nearby accumulators!
local Event = require 'utils.event'
local SpamProtection = require 'utils.spam_protection'
local BottomFrame = require 'utils.gui.bottom_frame'
local Gui = require 'utils.gui'
local Color = require 'utils.color_presets'
local Public = {}
local module_name = '[color=blue][Charging station][/color] '
local function draw_charging_gui(player, activate_custom_buttons)
local button =
player.gui.top['charging_station'] or
player.gui.top.add(
{
type = 'sprite-button',
name = 'charging_station',
sprite = 'item/battery-mk2-equipment',
tooltip = {
'modules.charging_station_tooltip'
},
style = Gui.button_style
}
)
button.style.minimal_height = 38
button.style.maximal_height = 38
if activate_custom_buttons then
if button and button.valid then
button.destroy()
end
end
end
local function discharge_accumulators(surface, position, force, power_needs)
local accumulators = surface.find_entities_filtered {name = 'accumulator', force = force, position = position, radius = 13}
local power_drained = 0
power_needs = power_needs * 1
for _, accu in pairs(accumulators) do
if accu.valid then
if accu.energy > 3000000 and power_needs > 0 then
if power_needs >= 2000000 then
power_drained = power_drained + 2000000
accu.energy = accu.energy - 2000000
power_needs = power_needs - 2000000
else
power_drained = power_drained + power_needs
accu.energy = accu.energy - power_needs
end
elseif power_needs <= 0 then
break
end
end
end
return power_drained / 1
end
local function charge(player)
local msg = player.print(module_name .. 'No valid armor to charge was found.', Color.warning)
if not player.character then
return msg
end
local armor_inventory = player.get_inventory(defines.inventory.character_armor)
if not armor_inventory.valid then
return msg
end
local armor = armor_inventory[1]
if not armor.valid_for_read then
return msg
end
local grid = armor.grid
if not grid or not grid.valid then
return msg
end
local equip = grid.equipment
for _, piece in pairs(equip) do
if piece.valid and piece.generator_power == 0 then
local energy_needs = piece.max_energy - piece.energy
if energy_needs > 0 then
local energy = discharge_accumulators(player.surface, player.position, player.force, energy_needs)
if energy > 0 then
if piece.energy + energy >= piece.max_energy then
piece.energy = piece.max_energy
else
piece.energy = piece.energy + energy
end
end
end
end
end
end
local function on_player_joined_game(event)
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
local activate_custom_buttons = BottomFrame.get('activate_custom_buttons')
draw_charging_gui(player, activate_custom_buttons)
if activate_custom_buttons then
BottomFrame.add_inner_frame(
{
player = player,
element_name = 'charging_station',
tooltip = {
'modules.charging_station_tooltip'
},
sprite = 'item/battery-mk2-equipment'
}
)
end
end
local function on_gui_click(event)
if not event then
return
end
if not event.element then
return
end
if not event.element.valid then
return
end
if event.element.name == 'charging_station' then
local player = game.players[event.player_index]
local is_spamming = SpamProtection.is_spamming(player, nil, 'Charging Station Gui Click')
if is_spamming then
return
end
charge(player)
return
end
end
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(
BottomFrame.events.bottom_quickbar_location_changed,
function(event)
local player_index = event.player_index
if not player_index then
return
end
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
local bottom_frame_data = event.data
if bottom_frame_data and bottom_frame_data.top then
draw_charging_gui(player, false)
else
draw_charging_gui(player, true)
end
end
)
return Public

View File

@ -28,5 +28,6 @@ Public.friendly_pet = require 'maps.mountain_fortress_v3.locomotive.friendly_pet
Public.market = require 'maps.mountain_fortress_v3.locomotive.market'
Public.permission_groups = require 'maps.mountain_fortress_v3.locomotive.permission_groups'
Public.spawn_locomotive = require 'maps.mountain_fortress_v3.locomotive.spawn_locomotive'
Public.charging_station = require 'maps.mountain_fortress_v3.charging_station'
return Public

View File

@ -6,9 +6,8 @@ local Server = require 'utils.server'
local RPG = require 'modules.rpg.main'
local Collapse = require 'modules.collapse'
local Alert = require 'utils.alert'
local Task = require 'utils.task'
local Task = require 'utils.task_token'
local Score = require 'utils.gui.score'
local Token = require 'utils.token'
local Discord = require 'utils.discord'
local Core = require 'utils.core'
local Diff = require 'modules.difficulty_vote_by_amount'
@ -81,7 +80,7 @@ local protect_types = {
}
local reset_game =
Token.register(
Task.register(
function(data)
local this = data.this
if this.soft_reset then
@ -442,7 +441,7 @@ local function angry_tree(entity, cause, player)
if e.can_insert(Public.piercing_rounds_magazine_ammo) then
e.insert(Public.piercing_rounds_magazine_ammo)
end
local callback = Token.get(cbl)
local callback = Task.get(cbl)
callback(e, data)
return
end
@ -482,7 +481,7 @@ local function give_coin(player)
end
local immunity_spawner =
Token.register(
Task.register(
function(data)
local entity = data.entity
if not entity or not entity.valid then
@ -497,37 +496,19 @@ local mining_events = {
function()
end,
300000,
'Nothing'
'Nothing #1'
},
{
function()
end,
16384,
'Nothing'
'Nothing #2'
},
{
function()
end,
4096,
'Nothing'
},
{
function()
end,
300000,
'Nothing'
},
{
function()
end,
32384,
'Nothing'
},
{
function()
end,
8096,
'Nothing'
'Nothing #3'
},
{
function(entity)
@ -540,33 +521,7 @@ local mining_events = {
entity.destroy()
end,
4096,
'Angry Biter_1'
},
{
function(entity)
if Public.is_around_train(entity) then
entity.destroy()
return
end
Public.buried_biter(entity.surface, entity.position)
entity.destroy()
end,
2048,
'Angry Biter_2'
},
{
function(entity)
if Public.is_around_train(entity) then
entity.destroy()
return
end
Public.buried_biter(entity.surface, entity.position)
entity.destroy()
end,
1024,
'Angry Biter_3'
'Angry Biter #1'
},
{
function(entity)
@ -579,20 +534,7 @@ local mining_events = {
entity.destroy()
end,
512,
'Angry Biter_4'
},
{
function(entity)
if Public.is_around_train(entity) then
entity.destroy()
return
end
Public.buried_biter(entity.surface, entity.position)
entity.destroy()
end,
512,
'Angry Biter_4'
'Angry Biter #2'
},
{
function(entity)
@ -605,20 +547,7 @@ local mining_events = {
entity.destroy()
end,
2048,
'Angry Worm_1'
},
{
function(entity)
if Public.is_around_train(entity) then
entity.destroy()
return
end
Public.buried_worm(entity.surface, entity.position)
entity.destroy()
end,
4096,
'Angry Worm_2'
'Angry Worm #1'
},
{
function(entity)
@ -631,54 +560,7 @@ local mining_events = {
entity.destroy()
end,
2048,
'Dangerous Trap_1'
},
{
function(entity)
if Public.is_around_train(entity) then
entity.destroy()
return
end
Public.tick_tack_trap(entity.surface, entity.position)
entity.destroy()
end,
4096,
'Dangerous Trap_2'
},
{
function(entity, index)
if Public.is_around_train(entity) then
entity.destroy()
return
end
local player = game.get_player(index)
if entity.type == 'tree' then
angry_tree(entity, player.character, player)
entity.destroy()
end
end,
4096,
'Angry Tree_1'
},
{
function(entity, index)
if Public.is_around_train(entity) then
entity.destroy()
return
end
local player = game.get_player(index)
if entity.type == 'tree' then
angry_tree(entity, player.character, player)
entity.destroy()
end
end,
2048,
'Angry Tree_2'
'Dangerous Trap #1'
},
{
function(entity, index)
@ -695,7 +577,23 @@ local mining_events = {
end
end,
1024,
'Angry Tree_3'
'Angry Tree #1'
},
{
function(entity, index)
local player = game.get_player(index)
hidden_treasure(player, entity)
end,
1024,
'Treasure Tier #1'
},
{
function(entity, index)
local player = game.get_player(index)
hidden_treasure(player, entity)
end,
512,
'Treasure Tier #2'
},
{
function(entity, index)
@ -703,7 +601,7 @@ local mining_events = {
hidden_treasure(player, entity)
end,
256,
'Treasure_Tier_1'
'Treasure Tier #3'
},
{
function(entity, index)
@ -711,7 +609,7 @@ local mining_events = {
hidden_treasure(player, entity)
end,
128,
'Treasure_Tier_2'
'Treasure Tier #4'
},
{
function(entity, index)
@ -719,7 +617,7 @@ local mining_events = {
hidden_treasure(player, entity)
end,
64,
'Treasure_Tier_3'
'Treasure Tier #5'
},
{
function(entity, index)
@ -727,7 +625,7 @@ local mining_events = {
hidden_treasure(player, entity)
end,
32,
'Treasure_Tier_4'
'Treasure Tier #6'
},
{
function(entity, index)
@ -735,27 +633,7 @@ local mining_events = {
hidden_treasure(player, entity)
end,
16,
'Treasure_Tier_5'
},
{
function(entity, index)
if Public.is_around_train(entity) then
entity.destroy()
return
end
local ent_to_create = {'biter-spawner', 'spitter-spawner'}
local position = entity.position
local surface = entity.surface
local e = surface.create_entity({name = ent_to_create[random(1, #ent_to_create)], position = position, force = 'enemy'})
e.destructible = false
Task.set_timeout_in_ticks(300, immunity_spawner, {entity = e})
Public.unstuck_player(index)
end,
1024,
'Nest'
'Treasure Tier #7'
},
{
function(entity, index)
@ -775,7 +653,27 @@ local mining_events = {
Public.unstuck_player(index)
end,
512,
'Nest'
'Nest #1'
},
{
function(entity, index)
if Public.is_around_train(entity) then
entity.destroy()
return
end
local ent_to_create = {'biter-spawner', 'spitter-spawner'}
local position = entity.position
local surface = entity.surface
local e = surface.create_entity({name = ent_to_create[random(1, #ent_to_create)], position = position, force = 'enemy'})
e.destructible = false
Task.set_timeout_in_ticks(300, immunity_spawner, {entity = e})
Public.unstuck_player(index)
end,
512,
'Nest #2'
},
{
function(entity)
@ -784,7 +682,7 @@ local mining_events = {
surface.create_entity({name = 'compilatron', position = position, force = 'player'})
end,
64,
'Friendly Compilatron'
'Friendly Compilatron #1'
},
{
function(entity)
@ -798,7 +696,7 @@ local mining_events = {
surface.create_entity({name = 'compilatron', position = position, force = 'enemy'})
end,
128,
'Enemy Compilatron'
'Enemy Compilatron #1'
},
{
function(entity)
@ -809,8 +707,8 @@ local mining_events = {
container.health = random(1, container.health)
end
end,
32,
'VSMG'
64,
'VSMG #1'
},
{
function(entity, index)
@ -822,8 +720,8 @@ local mining_events = {
local msg = ({'entity.found_car', player.name})
Alert.alert_player(player, 15, msg)
end,
16,
'Car'
32,
'Car #1'
}
}

View File

@ -1,8 +1,7 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Server = require 'utils.server'
local Token = require 'utils.token'
local Task = require 'utils.task'
local Task = require 'utils.task_token'
local Color = require 'utils.color_presets'
local ICW = require 'maps.mountain_fortress_v3.icw.main'
local Global = require 'utils.global'
@ -138,7 +137,7 @@ local function fast_remove(tbl, index)
end
local pause_waves_custom_callback_token =
Token.register(
Task.register(
function(status)
Collapse.disable_collapse(status)
local status_str = status and 'has stopped!' or 'is active once again!'
@ -278,7 +277,7 @@ local function do_magic_fluid_crafters()
end
local artillery_target_callback =
Token.register(
Task.register(
function(data)
local position = data.position
local entity = data.entity
@ -455,7 +454,7 @@ local function tick()
end
Public.deactivate_callback =
Token.register(
Task.register(
function(entity)
if entity and entity.valid then
entity.active = false
@ -466,7 +465,7 @@ Public.deactivate_callback =
)
Public.neutral_force =
Token.register(
Task.register(
function(entity)
if entity and entity.valid then
entity.force = 'neutral'
@ -475,7 +474,7 @@ Public.neutral_force =
)
Public.enemy_force =
Token.register(
Task.register(
function(entity)
if entity and entity.valid then
entity.force = 'enemy'
@ -484,7 +483,7 @@ Public.enemy_force =
)
Public.active_not_destructible_callback =
Token.register(
Task.register(
function(entity)
if entity and entity.valid then
entity.active = true
@ -495,7 +494,7 @@ Public.active_not_destructible_callback =
)
Public.disable_minable_callback =
Token.register(
Task.register(
function(entity)
if entity and entity.valid then
entity.minable = false
@ -504,7 +503,7 @@ Public.disable_minable_callback =
)
Public.disable_minable_and_ICW_callback =
Token.register(
Task.register(
function(entity)
if entity and entity.valid then
entity.minable = false
@ -514,7 +513,7 @@ Public.disable_minable_and_ICW_callback =
)
Public.disable_destructible_callback =
Token.register(
Task.register(
function(entity)
if entity and entity.valid then
entity.destructible = false
@ -523,7 +522,7 @@ Public.disable_destructible_callback =
end
)
Public.disable_active_callback =
Token.register(
Task.register(
function(entity)
if entity and entity.valid then
entity.active = false
@ -534,7 +533,7 @@ Public.disable_active_callback =
local disable_active_callback = Public.disable_active_callback
Public.refill_turret_callback =
Token.register(
Task.register(
function(turret, data)
local refill_turrets = this.refill_turrets
local callback_data = data.callback_data
@ -545,7 +544,7 @@ Public.refill_turret_callback =
)
Public.refill_artillery_turret_callback =
Token.register(
Task.register(
function(turret, data)
local refill_turrets = this.refill_turrets
local art_table = this.art_table
@ -579,7 +578,7 @@ Public.refill_artillery_turret_callback =
)
Public.refill_liquid_turret_callback =
Token.register(
Task.register(
function(turret, data)
local refill_turrets = this.refill_turrets
local callback_data = data.callback_data
@ -590,7 +589,7 @@ Public.refill_liquid_turret_callback =
)
Public.power_source_callback =
Token.register(
Task.register(
function(turret)
local power_sources = this.power_sources
power_sources[#power_sources + 1] = turret
@ -598,7 +597,7 @@ Public.power_source_callback =
)
Public.magic_item_crafting_callback =
Token.register(
Task.register(
function(entity, data)
local callback_data = data.callback_data
if not (entity and entity.valid) then
@ -653,7 +652,7 @@ Public.magic_item_crafting_callback =
)
Public.magic_item_crafting_callback_weighted =
Token.register(
Task.register(
function(entity, data)
local callback_data = data.callback_data
if not (entity and entity.valid) then
@ -800,7 +799,7 @@ local function calc_players()
end
remove_boost_movement_speed_on_respawn =
Token.register(
Task.register(
function(data)
local player = data.player
if not player or not player.valid then
@ -821,7 +820,7 @@ remove_boost_movement_speed_on_respawn =
)
local boost_movement_speed_on_respawn =
Token.register(
Task.register(
function(data)
local player = data.player
if not player or not player.valid then

View File

@ -1,7 +1,6 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local WD = require 'modules.wave_defense.table'
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
@ -233,10 +232,10 @@ local function do_place_buildings(data)
if c then
local d = {callback_data = e.callback.data}
if not d then
callback = Token.get(c)
callback = Task.get(c)
callback(entity)
else
callback = Token.get(c)
callback = Task.get(c)
callback(entity, d)
end
end
@ -325,10 +324,10 @@ local function do_place_entities(data)
end
local d = {callback_data = e.callback.data}
if not d then
callback = Token.get(c)
callback = Task.get(c)
callback(entity)
else
callback = Token.get(c)
callback = Task.get(c)
callback(entity, d)
end
end
@ -362,10 +361,10 @@ local function do_place_entities(data)
if c then
local d = {callback_data = e.callback.data}
if not d then
callback = Token.get(c)
callback = Task.get(c)
callback(entity)
else
callback = Token.get(c)
callback = Task.get(c)
callback(entity, d)
end
end
@ -474,7 +473,7 @@ local function map_gen_action(data)
end
end
local map_gen_action_token = Token.register(map_gen_action)
local map_gen_action_token = Task.register(map_gen_action)
--- Adds generation of a Chunk of the map to the queue
-- @param event <table> the event table from on_chunk_generated

View File

@ -2,8 +2,8 @@ local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Global = require 'utils.global'
local Server = require 'utils.server'
local Token = require 'utils.token'
local Gui = require 'utils.gui'
local Task = require 'utils.task_token'
local Score = require 'utils.gui.score'
local WD = require 'modules.wave_defense.table'
local Core = require 'utils.core'
@ -431,7 +431,7 @@ local function write_additional_stats(key, difficulty)
end
local get_scores =
Token.register(
Task.register(
function(data)
local value = data.value
if not this.score_table['player'] then
@ -692,7 +692,7 @@ local function show_score(data)
end -- foreach entry
end
local show_score_token = Token.register(show_score)
local show_score_token = Task.register(show_score)
local function on_gui_click(event)
local element = event.element

View File

@ -1,7 +1,6 @@
local Utils = require 'utils.core'
local Color = require 'utils.color_presets'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local IC = require 'maps.mountain_fortress_v3.ic.table'
local WPT = require 'maps.mountain_fortress_v3.table'
local RPG = require 'modules.rpg.main'
@ -624,7 +623,7 @@ local function get_persistent_player_data(player)
end
local remove_car =
Token.register(
Task.register(
function(data)
local player = data.player
local car = data.car
@ -633,7 +632,7 @@ local remove_car =
)
local find_remove_car =
Token.register(
Task.register(
function(data)
local index = data.index
local types = data.types

View File

@ -4,8 +4,7 @@ local Color = require 'utils.color_presets'
local Gui = require 'utils.gui'
local Tabs = require 'utils.gui'
local Event = require 'utils.event'
local Token = require 'utils.token'
local Task = require 'utils.task'
local Task = require 'utils.task_token'
local SpamProtection = require 'utils.spam_protection'
local Public = {}
@ -771,7 +770,7 @@ Gui.on_click(
)
local clear_misc_settings =
Token.register(
Task.register(
function(data)
local player_index = data.player_index
local misc_settings = ICT.get('misc_settings')

View File

@ -26,29 +26,32 @@ end
local function create_button(player)
local button =
player.gui.top['minimap_button'] or
player.gui.top.add(
{
type = 'sprite-button',
name = 'minimap_button',
sprite = 'utility/map',
tooltip = 'Open or close minimap.',
style = CoreGui.button_style
}
)
{
type = 'sprite-button',
name = 'minimap_button',
sprite = 'utility/map',
tooltip = 'Open or close minimap.',
style = CoreGui.button_style
}
)
button.style.minimal_height = 38
button.style.maximal_height = 38
button.visible = false
end
function Public.toggle_button(player)
if not player.gui.top['minimap_button'] then
create_button(player)
end
local button = player.gui.top['minimap_button']
if Functions.get_player_surface(player) then
button.visible = true
create_button(player)
else
button.visible = false
if button and button.valid then
button.destroy()
end
end
end

View File

@ -2,9 +2,8 @@ local Public = {}
local ICW = require 'maps.mountain_fortress_v3.icw.table'
local WPT = require 'maps.mountain_fortress_v3.table'
local Task = require 'utils.task'
local Task = require 'utils.task_token'
local Gui = require 'utils.gui'
local Token = require 'utils.token'
local SpamProtection = require 'utils.spam_protection'
local Core = require 'utils.core'
local LinkedChests = require 'maps.mountain_fortress_v3.icw.linked_chests'
@ -30,7 +29,7 @@ end
local size_of_debris = #fallout_debris
local add_chests_to_wagon_token =
Token.register(
Task.register(
function(data)
local wagon = data.wagon
local surface = data.surface
@ -108,7 +107,7 @@ local add_chests_to_wagon_token =
)
local reconstruct_all_trains =
Token.register(
Task.register(
function(data)
local icw = data.icw
Public.reconstruct_all_trains(icw)
@ -116,7 +115,7 @@ local reconstruct_all_trains =
)
local remove_non_migrated_doors_token =
Token.register(
Task.register(
function(data)
local icw = data.icw
for _, unit_data in pairs(icw.wagons) do

View File

@ -2,8 +2,7 @@ local Event = require 'utils.event'
local Color = require 'utils.color_presets'
local Global = require 'utils.global'
local Gui = require 'utils.gui'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local Where = require 'utils.commands.where'
local Math2D = require 'math2d'
local WPT = require 'maps.mountain_fortress_v3.table'
@ -54,7 +53,7 @@ function Public.set(key, value)
end
local clear_chest_token =
Token.register(
Task.register(
function(event)
local entity = event.entity
if not entity or not entity.valid then
@ -72,7 +71,7 @@ local clear_chest_token =
)
local create_clear_chest_token =
Token.register(
Task.register(
function(event)
local surface = game.get_surface('gulag')
local entity = surface.create_entity {name = 'linked-chest', position = {x = -62, y = -6}, force = game.forces.player}
@ -91,7 +90,7 @@ local create_clear_chest_token =
)
local remove_all_linked_items_token =
Token.register(
Task.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)

View File

@ -1,7 +1,6 @@
local Public = require 'maps.mountain_fortress_v3.table'
local ICW = require 'maps.mountain_fortress_v3.icw.main'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local MapFunctions = require 'tools.map_functions'
local random = math.random
@ -70,7 +69,7 @@ local function initial_cargo_boxes()
end
local place_tiles_token =
Token.register(
Task.register(
function(event)
local surface = event.surface
if not surface or not surface.valid then
@ -86,7 +85,7 @@ local place_tiles_token =
)
local set_loco_cargo =
Token.register(
Task.register(
function(data)
local surface = data.surface
if not surface or not surface.valid then

View File

@ -27,7 +27,7 @@ function Public.get_distance(position)
end
function Public.add_loot(surface, position, chest)
local loot_stats = Public.get('loot_stats')
local loot_stats = Public.get('loot_stats') -- loot_stats.normal == 48
local budget = loot_stats.normal + abs(position.y) * 1.75
budget = budget * random(25, 175) * 0.01
@ -80,7 +80,7 @@ function Public.add_loot(surface, position, chest)
end
function Public.add_loot_rare(surface, position, chest, magic)
local loot_stats = Public.get('loot_stats')
local loot_stats = Public.get('loot_stats') -- loot_stats.rare == 48
local budget = (magic * loot_stats.rare) + abs(position.y) * 1.75
budget = budget * random(25, 175) * 0.01

View File

@ -10,7 +10,6 @@ require 'modules.no_deconstruction_of_neutral_entities'
require 'modules.spawners_contain_biters'
require 'maps.mountain_fortress_v3.ic.main'
require 'modules.wave_defense.main'
require 'modules.charging_station'
local Event = require 'utils.event'
local Gui = require 'utils.gui'
@ -32,8 +31,7 @@ local Score = require 'utils.gui.score'
local Poll = require 'utils.gui.poll'
local Collapse = require 'modules.collapse'
local Difficulty = require 'modules.difficulty_vote_by_amount'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local Alert = require 'utils.alert'
local BottomFrame = require 'utils.gui.bottom_frame'
local AntiGrief = require 'utils.antigrief'
@ -106,7 +104,7 @@ local is_position_near_tbl = function(position, tbl)
end
local announce_new_map =
Token.register(
Task.register(
function()
local server_name = Server.check_server_name('Mtn Fortress')
if server_name then
@ -400,7 +398,7 @@ local chunk_load = function()
end
local collapse_message =
Token.register(
Task.register(
function(data)
local pos = data.position
local message = data.message

View File

@ -3,8 +3,7 @@ local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local RPG = require 'modules.rpg.main'
local Alert = require 'utils.alert'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local shuffle = table.shuffle_table
local random = math.random
@ -264,7 +263,7 @@ local function roll_item_stacks(remaining_budget, max_slots, blacklist)
end
local restore_mining_speed_token =
Token.register(
Task.register(
function()
local mc_rewards = Public.get('mc_rewards')
local force = game.forces.player
@ -278,7 +277,7 @@ local restore_mining_speed_token =
)
local restore_crafting_speed_token =
Token.register(
Task.register(
function()
local mc_rewards = Public.get('mc_rewards')
local force = game.forces.player
@ -292,7 +291,7 @@ local restore_crafting_speed_token =
)
local restore_movement_speed_token =
Token.register(
Task.register(
function()
local mc_rewards = Public.get('mc_rewards')
local force = game.forces.player

View File

@ -1,10 +1,9 @@
local Public = require 'maps.mountain_fortress_v3.stateful.table'
local map_name = 'boss_room'
local Token = require 'utils.token'
local Task = require 'utils.task'
local Task = require 'utils.task_token'
local blueprint_token =
Token.register(
Task.register(
function()
Public.blueprint()
end

View File

@ -1,7 +1,5 @@
local Event = require 'utils.event'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local Public = require 'maps.mountain_fortress_v3.stateful.table'
local ceil = math.ceil
@ -187,10 +185,10 @@ local function do_place_buildings(data)
if c then
local d = {callback_data = e.callback.data}
if not d then
callback = Token.get(c)
callback = Task.get(c)
callback(entity)
else
callback = Token.get(c)
callback = Task.get(c)
callback(entity, d)
end
end
@ -235,7 +233,7 @@ local function do_place_entities(data)
entity.amount = e.amount
end
if e.callback then
callback = Token.get(e.callback)
callback = Task.get(e.callback)
callback({entity = entity})
end
end
@ -259,7 +257,7 @@ local function do_place_entities(data)
entity.amount = e.amount
end
if e.callback then
callback = Token.get(e.callback)
callback = Task.get(e.callback)
callback({entity = entity})
end
end
@ -329,7 +327,7 @@ local function map_gen_action(data)
end
end
local map_gen_action_token = Token.register(map_gen_action)
local map_gen_action_token = Task.register(map_gen_action)
--- Adds generation of a Chunk of the map to the queue
-- @param event <table> the event table from on_chunk_generated

View File

@ -5,8 +5,7 @@ local Stateful = require 'maps.mountain_fortress_v3.stateful.table'
local Gui = require 'utils.gui'
local WD = require 'modules.wave_defense.table'
local Collapse = require 'modules.collapse'
local Token = require 'utils.token'
local Task = require 'utils.task'
local Task = require 'utils.task_token'
local Core = require 'utils.core'
local Server = require 'utils.server'
local LinkedChests = require 'maps.mountain_fortress_v3.icw.linked_chests'
@ -55,7 +54,7 @@ local function create_particles(surface, name, position, amount, cause_position)
end
local spread_particles_token =
Token.register(
Task.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
@ -166,7 +165,7 @@ local function refresh_frames()
end
local warn_player_sound_token =
Token.register(
Task.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
@ -299,7 +298,7 @@ local function objective_frames(stateful, player_frame, objective, data)
return
end
local callback = Token.get(objective.token)
local callback = Task.get(objective.token)
local _, objective_locale_left, objective_locale_right, tooltip_left, tooltip_right = callback()
@ -783,7 +782,7 @@ local function update_data()
for objective_index = 1, #stateful.selected_objectives do
local objective = stateful.selected_objectives[objective_index]
local objective_name = objective.name
local callback = Token.get(objective.token)
local callback = Task.get(objective.token)
local _, _, objective_locale_right, _, objective_tooltip_right = callback()
if name == objective_name and frame and frame.valid then
frame.caption = objective_locale_right
@ -979,7 +978,7 @@ local function update_raw()
for objective_index = 1, #stateful.selected_objectives do
local objective = stateful.selected_objectives[objective_index]
local objective_name = objective.name
local callback = Token.get(objective.token)
local callback = Task.get(objective.token)
local completed, _, _ = callback()
if completed and completed == true and not stateful.objectives_completed[objective_name] then
stateful.objectives_completed[objective_name] = true

View File

@ -2,7 +2,7 @@ local Global = require 'utils.global'
local Event = require 'utils.event'
local Utils = require 'utils.utils'
local Server = require 'utils.server'
local Token = require 'utils.token'
local Task = require 'utils.task_token'
local shuffle = table.shuffle_table
local WD = require 'modules.wave_defense.table'
local format_number = require 'util'.format_number
@ -11,7 +11,6 @@ local ICWF = require 'maps.mountain_fortress_v3.icw.functions'
local ICWT = require 'maps.mountain_fortress_v3.icw.table'
local Core = require 'utils.core'
local Public = require 'maps.mountain_fortress_v3.table'
local Task = require 'utils.task'
local Alert = require 'utils.alert'
local IC = require 'maps.mountain_fortress_v3.ic.table'
local RPG = require 'modules.rpg.table'
@ -336,14 +335,14 @@ local function get_killed_enemies_count(primary, secondary)
end
local move_all_players_token =
Token.register(
Task.register(
function()
Public.move_all_players()
end
)
local search_corpse_token =
Token.register(
Task.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
@ -419,14 +418,14 @@ local function on_market_item_purchased(event)
end
local empty_token =
Token.register(
Task.register(
function()
return false
end
)
local killed_enemies_token =
Token.register(
Task.register(
function()
local actual = Public.get_killed_enemies_count('biter', 'spitter')
local expected = this.objectives.killed_enemies
@ -439,7 +438,7 @@ local killed_enemies_token =
)
local research_level_selection_token =
Token.register(
Task.register(
function()
local actual = this.objectives.research_level_selection.research_count
local expected = this.objectives.research_level_selection.count
@ -451,7 +450,7 @@ local research_level_selection_token =
)
local locomotive_market_coins_spent_token =
Token.register(
Task.register(
function()
local coins = this.objectives.locomotive_market_coins_spent
local actual = coins.spent
@ -464,7 +463,7 @@ local locomotive_market_coins_spent_token =
)
local trees_farmed_token =
Token.register(
Task.register(
function()
local actual = get_entity_mined_count('tree')
local expected = this.objectives.trees_farmed
@ -476,7 +475,7 @@ local trees_farmed_token =
)
local rocks_farmed_token =
Token.register(
Task.register(
function()
local actual = get_entity_mined_count('rock')
local expected = this.objectives.rocks_farmed
@ -488,7 +487,7 @@ local rocks_farmed_token =
)
local rockets_launched_token =
Token.register(
Task.register(
function()
local actual = game.forces.player.rockets_launched
local expected = this.objectives.rockets_launched
@ -514,7 +513,7 @@ local function get_random_items()
{'copper-cable', scale(20000000, 100000000)},
{'copper-plate', scale(5000000, 80000000)},
{'electric-engine-unit', scale(30000, 200000)},
{'electronic-circuit', scale(5000000, 50000000)},
{'electronic-circuit', scale(5000000, 30000000)},
{'engine-unit', scale(90000, 750000)},
{'explosives', scale(700000, 3000000)},
{'iron-gear-wheel', scale(400000, 3000000)},
@ -809,7 +808,7 @@ local function apply_startup_settings(settings)
end
local apply_settings_token =
Token.register(
Task.register(
function(data)
local server_name_matches = Server.check_server_name('Mtn Fortress')
local settings = data and data.value or nil
@ -912,7 +911,7 @@ end
---@diagnostic disable-next-line: unused-local
local apply_settings_dev_token =
Token.register(
Task.register(
function(data)
local settings = data and data.value or nil
local current_time = 1700509719
@ -1255,7 +1254,7 @@ Public.on_market_item_purchased = on_market_item_purchased
if _DEBUG then
Event.on_init(
function()
local cbl = Token.get(apply_settings_dev_token)
local cbl = Task.get(apply_settings_dev_token)
local data = {
rounds_survived = 20,
season = 1,

View File

@ -1,12 +1,12 @@
local Public = require 'maps.mountain_fortress_v3.stateful.table'
local map_name = 'boss_room'
local Task = require 'utils.task_token'
local random = math.random
local ceil = math.ceil
local floor = math.floor
local Token = require 'utils.token'
local assign_locomotive_token =
Token.register(
Task.register(
function(event)
local entity = event.entity
if not entity or not entity.valid then

View File

@ -40,8 +40,6 @@ local nuclear_tiles = {
}
local wagon_raffle = {
'cargo-wagon',
'cargo-wagon',
'cargo-wagon',
'locomotive',
'fluid-wagon'

View File

@ -3,13 +3,15 @@
local Global = require 'utils.global'
local SpamProtection = require 'utils.spam_protection'
local Color = require 'utils.color_presets'
local Event = require 'utils.event'
local BottomFrame = require 'utils.gui.bottom_frame'
local Gui = require 'utils.gui'
local floor = math.floor
local print_color = {r = 120, g = 255, b = 0}
local Task = require 'utils.task_token'
local auto_stash_button_name = Gui.uid_name()
local floor = math.floor
local module_name = '[color=blue][Autostash][/color] '
local this = {
floating_text_y_offsets = {},
@ -36,6 +38,54 @@ local bps_blacklist = {
['blueprint'] = true
}
local on_init_token =
Task.register(
function()
local tooltip
if this.insert_into_furnace and this.insert_into_wagon then
tooltip =
'Sort your inventory into nearby chests.\nLMB: Everything, excluding quickbar items.\nRMB: Only ores to nearby chests, excluding quickbar items.\nCTRL+RMB: Fill nearby furnaces.\nSHIFT+LMB: Everything onto filtered slots to wagon.\nSHIFT+RMB: Only ores to wagon'
elseif this.insert_into_furnace then
tooltip = 'Sort your inventory into nearby chests.\nLMB: Everything, excluding quickbar items.\nRMB: Only ores to nearby chests, excluding quickbar items.\nCTRL+RMB: Fill nearby furnaces.'
elseif this.insert_into_wagon then
tooltip =
'Sort your inventory into nearby chests.\nLMB: Everything, excluding quickbar items.\nRMB: Only ores to nearby chests, excluding quickbar items.\nSHIFT+LMB: Everything onto filtered slots to wagon.\nSHIFT+RMB: Only ores to wagon'
else
tooltip = 'Sort your inventory into nearby chests.\nLMB: Everything, excluding quickbar items.\nRMB: Only ores to nearby chests, excluding quickbar items.'
end
this.tooltip = tooltip
if this.bottom_button then
local data = BottomFrame.get('bottom_quickbar_button_data')
data.sprite = 'item/wooden-chest'
data.tooltip = tooltip
end
end
)
local delay_tooltip_token =
Task.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
if Gui.get_mod_gui_top_frame() then
local frame = Gui.get_button_flow(player)[auto_stash_button_name]
if frame and frame.valid then
frame.tooltip = this.tooltip
end
else
local frame = player.gui.top[auto_stash_button_name]
if frame and frame.valid then
frame.tooltip = this.tooltip
end
end
end
)
local function create_floaty_text(surface, position, name, count)
if this.floating_text_y_offsets[position.x .. '_' .. position.y] then
this.floating_text_y_offsets[position.x .. '_' .. position.y] = this.floating_text_y_offsets[position.x .. '_' .. position.y] - 0.5
@ -454,16 +504,16 @@ local function auto_stash(player, event)
local ctrl = event.control
local shift = event.shift
if not player.character then
player.print('It seems that you are not in the realm of the living.', print_color)
player.print(module_name 'It seems that you are not in the realm of the living.', Color.warning)
return
end
if not player.character.valid then
player.print('It seems that you are not in the realm of the living.', print_color)
player.print(module_name 'It seems that you are not in the realm of the living.', Color.warning)
return
end
local inventory = player.get_main_inventory()
if inventory.is_empty() then
player.print('Inventory is empty.', print_color)
player.print(module_name 'Inventory is empty.', Color.warning)
return
end
@ -484,7 +534,7 @@ local function auto_stash(player, event)
end
if not chests.chest or not chests.chest[1] then
player.print('No valid nearby containers found.', print_color)
player.print(module_name .. 'No valid nearby containers found.', Color.warning)
return
end
@ -565,71 +615,57 @@ local function auto_stash(player, event)
end
end
local function create_gui_button(player)
local tooltip
if this.insert_into_furnace and this.insert_into_wagon then
tooltip =
'Sort your inventory into nearby chests.\nLMB: Everything, excluding quickbar items.\nRMB: Only ores to nearby chests, excluding quickbar items.\nCTRL+RMB: Fill nearby furnaces.\nSHIFT+LMB: Everything onto filtered slots to wagon.\nSHIFT+RMB: Only ores to wagon'
elseif this.insert_into_furnace then
tooltip = 'Sort your inventory into nearby chests.\nLMB: Everything, excluding quickbar items.\nRMB: Only ores to nearby chests, excluding quickbar items.\nCTRL+RMB: Fill nearby furnaces.'
elseif this.insert_into_wagon then
tooltip = 'Sort your inventory into nearby chests.\nLMB: Everything, excluding quickbar items.\nRMB: Only ores to nearby chests, excluding quickbar items.\nSHIFT+LMB: Everything onto filtered slots to wagon.\nSHIFT+RMB: Only ores to wagon'
else
tooltip = 'Sort your inventory into nearby chests.\nLMB: Everything, excluding quickbar items.\nRMB: Only ores to nearby chests, excluding quickbar items.'
end
if this.bottom_button then
local data = BottomFrame.get('bottom_quickbar_button')
-- save it for later use
data.tooltip = tooltip
data.sprite = 'item/wooden-chest'
local function create_gui_button(player, bottom_frame_data)
local tooltip = this.tooltip
local button
if data and data[player.index] then
local f = data[player.index]
if f and f.frame and f.frame.valid then
f.frame.sprite = 'item/wooden-chest'
f.frame.tooltip = tooltip
end
end
else
if Gui.get_mod_gui_top_frame() then
bottom_frame_data = bottom_frame_data or BottomFrame.get_player_data(player)
if Gui.get_mod_gui_top_frame() then
button =
Gui.add_mod_button(
player,
player,
{
type = 'sprite-button',
name = auto_stash_button_name,
sprite = 'item/wooden-chest',
tooltip = tooltip,
style = Gui.button_style
}
)
else
button =
player.gui.top[auto_stash_button_name] or
player.gui.top.add(
{
type = 'sprite-button',
name = auto_stash_button_name,
sprite = 'item/wooden-chest',
name = auto_stash_button_name,
tooltip = tooltip,
style = Gui.button_style
}
)
else
local tb = player.gui.top[auto_stash_button_name]
if tb and tb.valid then
return
button.style.font_color = {r = 0.11, g = 0.8, b = 0.44}
button.style.font = 'heading-1'
button.style.minimal_height = 40
button.style.maximal_width = 40
button.style.minimal_width = 38
button.style.maximal_height = 38
button.style.padding = 1
button.style.margin = 0
end
if this.bottom_button then
if bottom_frame_data ~= nil and not bottom_frame_data.top then
if button and button.valid then
button.destroy()
end
local b =
player.gui.top.add(
{
type = 'sprite-button',
sprite = 'item/wooden-chest',
name = auto_stash_button_name,
tooltip = tooltip,
style = Gui.button_style
}
)
b.style.font_color = {r = 0.11, g = 0.8, b = 0.44}
b.style.font = 'heading-1'
b.style.minimal_height = 40
b.style.maximal_width = 40
b.style.minimal_width = 38
b.style.maximal_height = 38
b.style.padding = 1
b.style.margin = 0
end
end
end
local function do_whitelist()
Task.delay(on_init_token, {})
local resources = game.entity_prototypes
local items = game.item_prototypes
this.whitelist = {}
@ -654,7 +690,10 @@ local function do_whitelist()
end
local function on_player_joined_game(event)
create_gui_button(game.players[event.player_index])
local player = game.get_player(event.player_index)
create_gui_button(player)
Task.delay(delay_tooltip_token, {player_index = player.index})
BottomFrame.add_inner_frame({player = player, element_name = auto_stash_button_name, tooltip = this.tooltip, sprite = 'item/wooden-chest'})
end
Gui.on_click(
@ -702,15 +741,19 @@ Event.on_init(do_whitelist)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(
BottomFrame.events.bottom_quickbar_button_name,
function(data)
local event = data.event
if not event then
BottomFrame.events.bottom_quickbar_location_changed,
function(event)
local player_index = event.player_index
if not player_index then
return
end
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
local player = event.player
auto_stash(player, event)
local bottom_frame_data = event.data
create_gui_button(player, bottom_frame_data)
end
)

View File

@ -4,6 +4,9 @@ local Server = require 'utils.server'
local Color = require 'utils.color_presets'
local Event = require 'utils.event'
local Global = require 'utils.global'
local BottomFrame = require 'utils.gui.bottom_frame'
local Gui = require 'utils.gui'
local SpamProtection = require 'utils.spam_protection'
local this = {
players = {},
@ -19,6 +22,8 @@ Global.register(
local Public = {}
local clear_corpse_button_name = Gui.uid_name()
commands.add_command(
'spaghetti',
'Does spaghett.',
@ -428,6 +433,52 @@ function Public.insert_all_items(player)
end
end
local function create_clear_corpse_frame(player, bottom_frame_data)
local button
bottom_frame_data = bottom_frame_data or BottomFrame.get_player_data(player)
if Gui.get_mod_gui_top_frame() then
button =
Gui.add_mod_button(
player,
{
type = 'sprite-button',
name = clear_corpse_button_name,
sprite = 'entity/behemoth-biter',
tooltip = {'commands.clear_corpse'},
style = Gui.button_style
}
)
else
button =
player.gui.top[clear_corpse_button_name] or
player.gui.top.add(
{
type = 'sprite-button',
sprite = 'entity/behemoth-biter',
name = clear_corpse_button_name,
tooltip = {'commands.clear_corpse'},
style = Gui.button_style
}
)
button.style.font_color = {r = 0.11, g = 0.8, b = 0.44}
button.style.font = 'heading-1'
button.style.minimal_height = 40
button.style.maximal_width = 40
button.style.minimal_width = 38
button.style.maximal_height = 38
button.style.padding = 1
button.style.margin = 0
end
if bottom_frame_data ~= nil and not bottom_frame_data.top then
if button and button.valid then
button.destroy()
end
end
end
function Public.get(key)
if key then
return this[key]
@ -471,6 +522,36 @@ Event.add(
function(event)
local player = game.players[event.player_index]
on_player_joined_game(player)
create_clear_corpse_frame(player)
BottomFrame.add_inner_frame({player = player, element_name = clear_corpse_button_name, tooltip = {'commands.clear_corpse'}, sprite = 'entity/behemoth-biter'})
end
)
Gui.on_click(
clear_corpse_button_name,
function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Clear Corpse')
if is_spamming then
return
end
clear_corpses(event)
end
)
Event.add(
BottomFrame.events.bottom_quickbar_location_changed,
function(event)
local player_index = event.player_index
if not player_index then
return
end
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
local bottom_frame_data = event.data
create_clear_corpse_frame(player, bottom_frame_data)
end
)

View File

@ -565,11 +565,11 @@ function Public.get_parent_frame(player)
end
--- This adds the given gui to the top gui.
---@param player userdata
---@param player LuaPlayer
---@param frame userdata|table
function Public.add_mod_button(player, frame)
if Public.get_button_flow(player)[frame.name] and Public.get_button_flow(player)[frame.name].valid then
return
return Public.get_button_flow(player)[frame.name]
end
Public.get_button_flow(player).add(frame)

View File

@ -1,13 +1,18 @@
local Misc = require 'utils.commands.misc'
local Event = require 'utils.event'
local Global = require 'utils.global'
local Gui = require 'utils.gui'
local SpamProtection = require 'utils.spam_protection'
local Task = require 'utils.task_token'
local Server = require 'utils.server'
local try_get_data = Server.try_get_data
-- local set_data = Server.set_data
local this = {
players = {},
storage = {},
activate_custom_buttons = false,
bottom_quickbar_button = {}
bottom_quickbar_button = {},
bottom_quickbar_button_data = {}
}
Global.register(
@ -17,68 +22,202 @@ Global.register(
end
)
local Public = {}
Public.events = {
bottom_quickbar_button_name = Event.generate_event_name('bottom_quickbar_button_name'),
bottom_quickbar_respawn_raise = Event.generate_event_name('bottom_quickbar_respawn_raise')
--- Events generated by the bottom frame module.
-- @table events
-- @field bottom_quickbar_respawn_raise The event triggered when the bottom quickbar is respawned or raised.
-- @field bottom_quickbar_location_changed The event triggered when the location of the bottom quickbar is changed.
local Public = {
events = {
bottom_quickbar_respawn_raise = Event.generate_event_name('bottom_quickbar_respawn_raise'),
bottom_quickbar_location_changed = Event.generate_event_name('bottom_quickbar_location_changed')
}
}
local set_location
local get_player_data
local bottom_dataset = 'bottom_frame_data'
local main_frame_name = Gui.uid_name()
local clear_corpse_button_name = Gui.uid_name()
local bottom_quickbar_button_name = Gui.uid_name()
function Public.get_player_data(player, remove_user_data)
if remove_user_data then
if this.players[player.index] then
this.players[player.index] = nil
local sections = {
[1] = 1,
[2] = 1,
[3] = 2,
[4] = 2,
[5] = 3,
[6] = 3,
[7] = 4,
[8] = 4,
[9] = 5,
[10] = 5,
[11] = 6,
[12] = 6
}
local restore_bottom_location_token =
Task.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
return
end
if not this.players[player.index] then
this.players[player.index] = {}
end
return this.players[player.index]
end
function Public.get(key)
if key then
return this[key]
else
return this
end
end
local state = event.state
if not state then
return
end
function Public.set(key, value)
if key and (value or value == false) then
this[key] = value
return this[key]
elseif key then
return this[key]
else
return this
end
end
local bottom_right = event.bottom_right or 'bottom_right'
local above = event.above or false
function Public.remove_player(index)
local data = get_player_data(player)
data.bottom_right = bottom_right
data.above = above
data.state = state
set_location(player, state)
end
)
local function remove_player(index)
this.players[index] = nil
this.storage[index] = nil
this.bottom_quickbar_button[index] = nil
end
function Public.reset()
local players = game.players
for i = 1, #players do
local player = players[i]
if player and player.valid then
if not player.connected then
this.players[player.index] = nil
this.bottom_quickbar_button[player.index] = nil
get_player_data = function(player, remove_user_data)
if remove_user_data then
this.players[player.index] = nil
this.storage[player.index] = nil
return
end
if not this.players[player.index] then
this.players[player.index] = {
state = 'bottom_right',
section = {},
direction = 'vertical',
row_index = 1,
row_selection = 1,
row_selection_added = 1
}
this.storage[player.index] = {}
end
return this.players[player.index], this.storage[player.index]
end
--- Refreshes all inner frames for a given player
local function refresh_inner_frames(player)
if not player or not player.valid then
return
end
local player_data, storage_data = get_player_data(player)
if not player_data or not storage_data or not player_data.frame or not player_data.frame.valid then
return
end
local main_frame = player_data.frame
local horizontal_flow = main_frame.add {type = 'flow', direction = 'horizontal'}
horizontal_flow.style.horizontal_spacing = 0
for row_index, row_index_data in pairs(storage_data) do
if row_index_data and type(row_index_data) == 'table' then
local section_row_index = player_data.section[row_index]
local vertical_flow = horizontal_flow.add {type = 'flow', direction = 'vertical'}
vertical_flow.style = 'shortcut_bar_column'
if not section_row_index then
player_data.section[row_index] = {}
section_row_index = player_data.section[row_index]
end
if not section_row_index.inside_frame or not section_row_index.inside_frame.valid then
section_row_index.inner_frame = vertical_flow
end
for row_selection, row_selection_data in pairs(row_index_data) do
if section_row_index[row_selection] and section_row_index[row_selection].valid then
section_row_index[row_selection].destroy()
end
section_row_index[row_selection] =
section_row_index.inner_frame.add {
type = 'sprite-button',
sprite = row_selection_data.sprite,
name = row_selection_data.name,
tooltip = row_selection_data.tooltip or '',
style = 'quick_bar_page_button'
}
end
end
end
end
----! Gui Functions ! ----
---Adds a new inner frame to the bottom frame
-- local BottomFrame = require 'utils.gui.bottom_frame'
-- BottomFrame.add_inner_frame({player = player, element_name = Gui.uid_name(), tooltip = 'Some tooltip', sprite = 'item/raw-fish' })
---@param data any
local function add_inner_frame(data)
if not data then
return
end
local player = data.player
local element_name = data.element_name
local tooltip = data.tooltip
local sprite = data.sprite
if not player or not player.valid then
return error('Given player was not valid', 2)
end
if not element_name then -- the element_name to pick from the row_selection
return error('Element name is missing', 2)
end
if not sprite then
return error('Sprite is missing', 2)
end
local player_data, storage_data = get_player_data(player)
if not player_data or not storage_data or not player_data.frame or not player_data.frame.valid then
return
end
if player_data.row_index > 6 then
return error('Having more than 6 rows is currently not supported.', 2)
end
local found = false
for _, row_index_data in pairs(storage_data) do
if row_index_data and type(row_index_data) == 'table' then
for _, row_selection_data in pairs(row_index_data) do
if row_selection_data and row_selection_data.name == element_name then
found = true
end
end
end
end
if found then
return
end
player_data.row_index = sections[player_data.row_selection_added]
if not storage_data[player_data.row_index] then
storage_data[player_data.row_index] = {}
end
local storage_data_section = storage_data[player_data.row_index]
storage_data_section[player_data.row_selection] = {
name = element_name,
sprite = sprite,
tooltip = tooltip
}
player_data.row_selection = player_data.row_selection + 1
player_data.row_selection_added = player_data.row_selection_added + 1
player_data.row_selection = player_data.row_selection > 2 and 1 or player_data.row_selection
end
local function destroy_frame(player)
local gui = player.gui
@ -88,7 +227,13 @@ local function destroy_frame(player)
end
end
local function create_frame(player, alignment, location, portable)
--- Creates a new frame
---@param player LuaPlayer
---@param alignment string
---@param location table
---@param data any
---@return unknown
local function create_frame(player, alignment, location, data)
local gui = player.gui
local frame = gui.screen[main_frame_name]
if frame and frame.valid then
@ -104,8 +249,6 @@ local function create_frame(player, alignment, location, portable)
direction = alignment
}
local data = Public.get_player_data(player)
if data.visible ~= nil then
if data.visible then
frame.visible = true
@ -116,16 +259,10 @@ local function create_frame(player, alignment, location, portable)
frame.style.padding = 3
frame.style.top_padding = 4
if alignment == 'vertical' then
frame.style.minimal_height = 96
end
frame.location = location
if portable then
frame.caption = ''
end
local inner_frame =
frame.add {
type = 'frame',
@ -133,33 +270,28 @@ local function create_frame(player, alignment, location, portable)
}
inner_frame.style = 'quick_bar_inner_panel'
inner_frame.add {
type = 'sprite-button',
sprite = 'entity/behemoth-biter',
name = clear_corpse_button_name,
tooltip = {'commands.clear_corpse'},
style = 'quick_bar_page_button'
}
local bottom_quickbar_button =
inner_frame.add {
type = 'sprite-button',
name = bottom_quickbar_button_name,
style = 'quick_bar_page_button'
}
this.bottom_quickbar_button[player.index] = {name = bottom_quickbar_button_name, frame = bottom_quickbar_button}
if this.bottom_quickbar_button.sprite and this.bottom_quickbar_button.tooltip then
bottom_quickbar_button.sprite = this.bottom_quickbar_button.sprite
bottom_quickbar_button.tooltip = this.bottom_quickbar_button.tooltip
frame.location = location
if data.portable then
frame.caption = ''
end
if data.top then
frame.visible = false
else
frame.visible = true
end
data.frame = inner_frame
data.parent = frame
data.section = data.section or {}
data.section_data = data.section_data or {}
data.alignment = alignment
return frame
end
local function set_location(player, state)
local data = Public.get_player_data(player)
set_location = function(player, state)
local data = get_player_data(player)
local alignment = 'vertical'
local location
@ -172,12 +304,13 @@ local function set_location(player, state)
if data.above then
location = {
x = (resolution.width / 2) - ((259) * scale),
y = (resolution.height - (150 * scale))
y = (resolution.height - (-12 + (40 * 5) * scale))
}
alignment = 'horizontal'
else
location = {
x = (resolution.width / 2) - ((54 + 444) * scale),
-- x = (resolution.width / 2) - ((54 + 528 - 44) * scale),
x = (resolution.width / 2) - ((455 + (data.row_index * 40)) * scale),
y = (resolution.height - (96 * scale))
}
end
@ -185,8 +318,9 @@ local function set_location(player, state)
elseif state == 'bottom_right' then
if data.above then
location = {
x = (resolution.width / 2) - ((-376) * scale),
y = (resolution.height - (150 * scale))
-- x = (resolution.width / 2) - ((-262 - (40 * t[data.row_index])) * scale),
x = (resolution.width / 2) - ((-460 + (data.row_index * 40)) * scale),
y = (resolution.height - (-12 + (40 * 5) * scale))
}
alignment = 'horizontal'
else
@ -203,9 +337,42 @@ local function set_location(player, state)
}
end
Event.raise(Public.events.bottom_quickbar_location_changed, {player_index = player.index, data = data})
data.state = state
create_frame(player, alignment, location, data.portable)
-- local secs = Server.get_current_time()
-- if secs ~= nil then
-- set_data(
-- bottom_dataset,
-- player.name,
-- {
-- bottom_state = data.bottom_state,
-- above = data.above,
-- state = data.state
-- }
-- )
-- end
create_frame(player, alignment, location, data)
refresh_inner_frames(player)
end
--- Sets then frame location of the given player
---@param player LuaPlayer?
---@param value boolean
local function set_top(player, value)
local data = get_player_data(player)
data.top = value or false
Public.set_location(player, 'bottom_right')
end
--- Returns the current frame location of the given player
---@param player LuaPlayer
---@return table|nil
local function get_location(player)
local data = get_player_data(player)
return data and data.state or nil
end
--- Activates the custom buttons
@ -214,39 +381,75 @@ function Public.activate_custom_buttons(value)
this.activate_custom_buttons = value or false
end
--- Fetches if the custom buttons are activated
--- Checks if custom buttons are enabled.
--- @return boolean: True if custom buttons are enabled, false otherwise.
function Public.is_custom_buttons_enabled()
return this.activate_custom_buttons
end
Gui.on_click(
clear_corpse_button_name,
function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Clear Corpse')
if is_spamming then
return
--- Toggles the player frame.
--- @param player LuaPlayer: The player entity.
--- @param state boolean: The state to set for the player frame.
function Public.toggle_player_frame(player, state)
local gui = player.gui
local frame = gui.screen[main_frame_name]
if frame and frame.valid then
local data = get_player_data(player)
if state then
data.visible = true
frame.visible = true
else
data.visible = false
frame.visible = false
end
Misc.clear_corpses(event)
end
)
end
Gui.on_click(
bottom_quickbar_button_name,
function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Custom Bottom_quickbar_button_name')
if is_spamming then
return
end
Event.raise(Public.events.bottom_quickbar_button_name, {player = event.player, event = event})
--- Retrieves the value associated with the specified key.
--- @param key any The key to retrieve the value for.
--- @return any The value associated with the key.
function Public.get(key)
if key then
return this[key]
else
return this
end
)
end
--- Sets the value of a given key.
--- @param key any The key to set.
--- @param value any The value to set for the key.
function Public.set(key, value)
if key and (value or value == false) then
this[key] = value
return this[key]
elseif key then
return this[key]
else
return this
end
end
--- Resets the bottom frame.
function Public.reset()
local players = game.players
for i = 1, #players do
local player = players[i]
if player and player.valid then
if not player.connected then
this.players[player.index] = nil
this.storage[player.index] = nil
end
end
end
end
Event.add(
defines.events.on_player_joined_game,
function(event)
if this.activate_custom_buttons then
local player = game.get_player(event.player_index)
local data = Public.get_player_data(player)
local data = get_player_data(player)
set_location(player, data.state)
end
end
@ -257,7 +460,7 @@ Event.add(
function(event)
if this.activate_custom_buttons then
local player = game.get_player(event.player_index)
local data = Public.get_player_data(player)
local data = get_player_data(player)
set_location(player, data.state)
end
end
@ -268,7 +471,7 @@ Event.add(
function(event)
local player = game.get_player(event.player_index)
if this.activate_custom_buttons then
local data = Public.get_player_data(player)
local data = get_player_data(player)
set_location(player, data.state)
end
end
@ -297,7 +500,7 @@ Event.add(
function(event)
if this.activate_custom_buttons then
local player = game.get_player(event.player_index)
local data = Public.get_player_data(player)
local data = get_player_data(player)
set_location(player, data.state)
end
end
@ -306,28 +509,10 @@ Event.add(
Event.add(
defines.events.on_player_removed,
function(event)
Public.remove_player(event.player_index)
remove_player(event.player_index)
end
)
function Public.toggle_player_frame(player, state)
local gui = player.gui
local frame = gui.screen[main_frame_name]
if frame and frame.valid then
local data = Public.get_player_data(player)
if state then
data.visible = true
frame.visible = true
else
data.visible = false
frame.visible = false
end
end
end
Public.main_frame_name = main_frame_name
Public.set_location = set_location
Gui.screen_to_bypass(main_frame_name)
Event.add(
Public.events.bottom_quickbar_respawn_raise,
function(event)
@ -337,10 +522,44 @@ Event.add(
if this.activate_custom_buttons then
local player = game.get_player(event.player_index)
local data = Public.get_player_data(player)
local data = get_player_data(player)
set_location(player, data.state)
local secs = Server.get_current_time()
if secs ~= nil then
try_get_data(bottom_dataset, bottom_dataset.index, restore_bottom_location_token)
end
end
end
)
Event.add(
Public.events.bottom_quickbar_location_changed,
function(event)
if not event or not event.player_index then
return
end
if this.activate_custom_buttons then
local player = game.get_player(event.player_index)
local data = get_player_data(player)
if data.frame and data.frame.valid then
if data.top then
data.frame.visible = false
else
data.frame.visible = true
end
end
end
end
)
Public.main_frame_name = main_frame_name
Public.get_player_data = get_player_data
Public.remove_player = remove_player
Public.set_location = set_location
Public.get_location = get_location
Public.set_top = set_top
Public.add_inner_frame = add_inner_frame
Gui.screen_to_bypass(main_frame_name)
return Public

View File

@ -138,6 +138,15 @@ local functions = {
Module[event.player_index].disabled = true
end
end,
['top_location'] = function(event)
local player = game.get_player(event.player_index)
local data = BottomFrame.get_player_data(player)
if data and data.state and not data.top then
BottomFrame.set_top(player, true)
else
BottomFrame.set_top(player, false)
end
end,
['bottom_location'] = function(event)
local player = game.get_player(event.player_index)
if event.element.switch_state == 'left' then
@ -552,6 +561,17 @@ local function build_config_gui(data)
label.style.vertical_align = 'bottom'
label.style.font_color = Color.white_smoke
local autostash = is_loaded('modules.autostash')
if autostash then
scroll_pane.add({type = 'line'})
switch_state = 'right'
local bottom_frame = BottomFrame.get_player_data(player)
if bottom_frame and bottom_frame.top then
switch_state = 'left'
end
add_switch(scroll_pane, switch_state, 'top_location', 'Position - top', 'Toggle to select if you want the bottom buttons at the top or the bottom.')
end
scroll_pane.add({type = 'line'})
switch_state = 'right'

21
utils/task_token.lua Normal file
View File

@ -0,0 +1,21 @@
-- This file simply exists to reduce the amount of require that is done
local Token = require 'utils.token'
local Task = require 'utils.task'
local Public = {}
Public.register = Token.register
Public.get = Token.get
Public.set_timeout_in_ticks = Task.set_timeout_in_ticks
Public.set_timeout_in_ticks_text = Task.set_timeout_in_ticks_text
Public.set_timeout = Task.set_timeout
Public.queue_task = Task.queue_task
Public.get_queue_speed = Task.get_queue_speed
Public.set_queue_speed = Task.set_queue_speed
Public.delay = Task.queue_task
Public.priority_delay = Task.set_timeout_in_ticks
return Public