1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-16 02:47:48 +02:00

Changes for Mtn v3 and minor utils files

This commit is contained in:
Gerkiz 2023-12-04 23:03:28 +01:00
parent 3ecf651bf7
commit 2e626f819d
23 changed files with 384 additions and 206 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

@ -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

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

@ -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

@ -32,8 +32,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 +105,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 +399,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
@ -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'
local function create_gui_button(player, bottom_frame_data)
local tooltip = this.tooltip
local button
if Gui.get_mod_gui_top_frame() then
button =
Gui.add_mod_button(
player,
{
type = 'sprite-button',
name = auto_stash_button_name,
sprite = 'item/wooden-chest',
tooltip = tooltip,
style = Gui.button_style
}
)
else
tooltip = 'Sort your inventory into nearby chests.\nLMB: Everything, excluding quickbar items.\nRMB: Only ores to nearby chests, excluding quickbar items.'
button =
player.gui.top[auto_stash_button_name] or
player.gui.top.add(
{
type = 'sprite-button',
sprite = 'item/wooden-chest',
name = auto_stash_button_name,
tooltip = tooltip,
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 this.bottom_button then
local data = BottomFrame.get('bottom_quickbar_button')
-- save it for later use
data.tooltip = tooltip
data.sprite = 'item/wooden-chest'
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
bottom_frame_data = bottom_frame_data or BottomFrame.get_player_data(player)
if not (this.bottom_button and bottom_frame_data ~= nil and not bottom_frame_data.top) then
if button and button.valid then
button.visible = true
end
else
if Gui.get_mod_gui_top_frame() then
Gui.add_mod_button(
player,
{
type = 'sprite-button',
name = auto_stash_button_name,
sprite = 'item/wooden-chest',
tooltip = tooltip,
style = Gui.button_style
}
)
else
local tb = player.gui.top[auto_stash_button_name]
if tb and tb.valid then
return
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
if button and button.valid then
button.visible = false
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,9 @@ 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})
end
Gui.on_click(
@ -714,4 +752,21 @@ Event.add(
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_gui_button(player, bottom_frame_data)
end
)
return Public

View File

@ -565,7 +565,7 @@ 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

View File

@ -7,7 +7,8 @@ local SpamProtection = require 'utils.spam_protection'
local this = {
players = {},
activate_custom_buttons = false,
bottom_quickbar_button = {}
bottom_quickbar_button = {},
bottom_quickbar_button_data = {}
}
Global.register(
@ -21,7 +22,8 @@ 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')
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 main_frame_name = Gui.uid_name()
@ -36,7 +38,9 @@ function Public.get_player_data(player, remove_user_data)
return
end
if not this.players[player.index] then
this.players[player.index] = {}
this.players[player.index] = {
state = 'bottom_right'
}
end
return this.players[player.index]
end
@ -80,6 +84,54 @@ end
----! Gui Functions ! ----
local function create_gui_button(player, frame_data)
local button
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
frame_data = frame_data or Public.get_player_data(player)
if not (this.activate_custom_buttons and frame_data ~= nil and not frame_data.top) then
if button and button.valid then
button.visible = true
end
else
if button and button.valid then
button.visible = false
end
end
end
local function destroy_frame(player)
local gui = player.gui
local frame = gui.screen[main_frame_name]
@ -88,7 +140,7 @@ local function destroy_frame(player)
end
end
local function create_frame(player, alignment, location, portable)
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 +156,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
@ -117,12 +167,14 @@ local function create_frame(player, alignment, location, portable)
frame.style.padding = 3
frame.style.top_padding = 4
global.a = frame
if alignment == 'vertical' then
frame.style.minimal_height = 96
end
frame.location = location
if portable then
if data.portable then
frame.caption = ''
end
@ -148,13 +200,15 @@ local function create_frame(player, alignment, location, portable)
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
if this.bottom_quickbar_button_data and this.bottom_quickbar_button_data.sprite and this.bottom_quickbar_button_data.tooltip and not data.top then
bottom_quickbar_button.sprite = this.bottom_quickbar_button_data.sprite
bottom_quickbar_button.tooltip = this.bottom_quickbar_button_data.tooltip
else
frame.destroy()
end
this.bottom_quickbar_button[player.index] = {name = bottom_quickbar_button_name, frame = bottom_quickbar_button}
return frame
end
@ -203,9 +257,28 @@ 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)
create_frame(player, alignment, location, data)
end
--- Sets then frame location of the given player
---@param player LuaPlayer?
---@param value boolean
local function set_top(player, value)
local data = Public.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 = Public.get_player_data(player)
return data and data.state or nil
end
--- Activates the custom buttons
@ -219,6 +292,22 @@ function Public.is_custom_buttons_enabled()
return this.activate_custom_buttons
end
--- Toggles 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 = Public.get_player_data(player)
if state then
data.visible = true
frame.visible = true
else
data.visible = false
frame.visible = false
end
end
end
Gui.on_click(
clear_corpse_button_name,
function(event)
@ -237,7 +326,14 @@ Gui.on_click(
if is_spamming then
return
end
Event.raise(Public.events.bottom_quickbar_button_name, {player = event.player, event = event})
local data = Public.get_player_data(event.player)
if data and data.top then
return
end
event.data = data
Event.raise(Public.events.bottom_quickbar_button_name, {event = event})
end
)
@ -248,6 +344,7 @@ Event.add(
local player = game.get_player(event.player_index)
local data = Public.get_player_data(player)
set_location(player, data.state)
create_gui_button(player, data)
end
end
)
@ -310,24 +407,6 @@ Event.add(
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)
@ -343,4 +422,25 @@ Event.add(
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 = Public.get_player_data(player)
create_gui_button(player, data)
end
end
)
Public.main_frame_name = main_frame_name
Public.set_location = set_location
Public.get_location = get_location
Public.set_top = set_top
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 autostash button 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