Add joinable legacy code

This commit is contained in:
Cooldude2606
2024-09-23 23:01:52 +01:00
parent 2a1206c498
commit d24555d805
24 changed files with 144 additions and 126 deletions

View File

@@ -4,6 +4,13 @@
-- all files which are loaded (including the config files) are present in ./config/file_loader.lua
-- this file is the landing point for all scenarios please DO NOT edit directly, further comments are to aid development
local _xpcall = xpcall
xpcall = function (func, error_handler, ...)
local rtn = { _xpcall(func, error_handler, ...) }
if not rtn[1] then error(rtn[2]) end
return table.unpack(rtn)
end
log('[START] -----| Explosive Gaming Scenario Loader |-----')
log('[INFO] Setting up lua environment')

View File

@@ -125,7 +125,7 @@ Gui.element(function(_, parent, caption, tooltip, add_alignment, name, label_nam
header.add{
name = label_name or 'header_label',
type = 'label',
style = 'heading_1_label',
style = 'frame_title',
caption = caption,
tooltip = tooltip
}
@@ -173,7 +173,7 @@ Gui.element(function(_, parent, caption, tooltip, add_alignment, name)
footer.add{
name = 'footer_label',
type = 'label',
style = 'heading_1_label',
style = 'frame_title',
caption = caption,
tooltip = tooltip
}
@@ -201,13 +201,14 @@ Gui.element(function(_, parent, name, _)
name = name,
type = 'frame'
}
frame.style.horizontally_stretchable = false
-- Return the container
return frame.add{
name = 'container',
type = 'frame',
direction = 'vertical',
style = 'window_content_frame_packed'
style = 'inside_shallow_frame_packed'
}
end)
:style(function(style, element, _,width)
@@ -258,7 +259,6 @@ Gui.element(function(_, parent, width, caption, tooltip)
type = 'label',
caption = caption,
tooltip = tooltip,
style = 'description_label'
}
local style = label.style
@@ -290,7 +290,7 @@ Gui.element(function(_, parent, width, caption, tooltip)
type = 'label',
caption = caption,
tooltip = tooltip,
style = 'heading_1_label'
style = 'frame_title'
}
Gui.bar(title_flow)

View File

@@ -18,7 +18,7 @@ Event.add(defines.events.on_player_created, function(event)
-- spawn items
for item, callback in pairs(items) do
if type(callback) == 'function' then
local stats = player.force.item_production_statistics
local stats = player.force.get_item_production_statistics(player.surface)
local made = stats.get_input_count(item)
local success, count = pcall(callback, made, stats.get_input_count, player)
count = math.floor(count)

View File

@@ -24,10 +24,10 @@ end)
local speech_bubble_async =
Async.register(function(data)
local message =
data.entity.surface.create_entity{
data.ent.surface.create_entity{
name = 'compi-speech-bubble',
text = messages[data.name][data.msg_number],
source = data.entity,
source = data.ent,
position = {0, 0},
}
@@ -88,8 +88,8 @@ end
-- @tparam string location the location tag that is in the config file
function Public.spawn_compilatron(surface, location)
local position = locations[location]
local pos = surface.find_non_colliding_position('compilatron', position, 1.5, 0.5)
local compi = surface.create_entity {name='compilatron', position=pos, force=game.forces.neutral}
local pos = surface.find_non_colliding_position('small-biter', position, 1.5, 0.5)
local compi = surface.create_entity {name='small-biter', position=pos, force=game.forces.neutral}
Public.add_compilatron(compi, location)
end

View File

@@ -143,7 +143,7 @@ local function spawn_area(surface, position)
local fill_tile = surface.get_tile(position).name
-- Make sure a non water tile is used for each tile
if surface.get_tile(position).collides_with('player-layer') then fill_tile = 'landfill' end
if surface.get_tile(position).collides_with('player') then fill_tile = 'landfill' end
if decon_tile == nil then decon_tile = fill_tile end
local tiles_to_make = {}
@@ -156,7 +156,7 @@ local function spawn_area(surface, position)
if dst < tr2 then
-- If it is inside the decon radius always set the tile
table.insert(tiles_to_make, {name=decon_tile, position=pos})
elseif dst < fr2 and surface.get_tile(pos).collides_with('player-layer') then
elseif dst < fr2 and surface.get_tile(pos).collides_with('player') then
-- If it is inside the fill radius only set the tile if it is water
table.insert(tiles_to_make, {name=fill_tile, position=pos})
end

View File

@@ -15,12 +15,12 @@ local function item_parse(input, _, reject)
local lower_input = input:lower():gsub(' ', '-')
-- Simple Case - internal name is given
local item = game.item_prototypes[lower_input]
local item = prototypes.item[lower_input]
if item then return item end
-- Second Case - rich text is given
local item_name = input:match('%[item=([0-9a-z-]+)%]')
item = game.item_prototypes[item_name]
item = prototypes.item[item_name]
if item then return item end
-- No item found, we do not attempt to search all prototypes as this will be expensive

View File

@@ -96,9 +96,12 @@ end
-- @tparam string item_name the name of the item that you want the data about
-- @treturn table contains total made, used and net
function Production.get_production_total(force, item_name)
local stats = force.item_production_statistics
local made = stats.get_input_count(item_name) or 0
local used = stats.get_output_count(item_name) or 0
local made, used = 0, 0
for _, surface in pairs(game.surfaces) do
local stats = force.get_item_production_statistics(surface)
made = made + stats.get_input_count(item_name)
used = used + stats.get_output_count(item_name)
end
return {
made=made,
@@ -114,9 +117,12 @@ end
-- @tparam defines.flow_precision_index precision the precision that you want the data given to
-- @treturn table contains made, used and net
function Production.get_production(force, item_name, precision)
local stats = force.item_production_statistics.get_flow_count
local made = stats{name=item_name, input=true, precision_index=precision} or 0
local used = stats{name=item_name, input=false, precision_index=precision} or 0
local made, used = 0, 0
for _, surface in pairs(game.surfaces) do
local stats = force.get_item_production_statistics(surface).get_flow_count
made = made + stats{name=item_name, category="input", precision_index=precision}
used = used + stats{name=item_name, category="output", precision_index=precision}
end
return {
made=made,

View File

@@ -110,7 +110,7 @@ Gui.element(function(definition, parent, target)
local label = parent.add{
type = 'label',
style = 'heading_1_label',
style = 'frame_title',
caption = 'Following '..target.name..'.\nClick here or press esc to stop following.',
name = definition.name
}

View File

@@ -573,7 +573,7 @@ local function handle_circuit_interfaces()
-- Set the item signals based on stored items
for item_name, count in pairs(vlayer_data.storage.items) do
if game.item_prototypes[item_name] and count > 0 then
if prototypes.item[item_name] and count > 0 then
circuit_oc.set_signal(signal_index, {signal={type='item', name=item_name}, count=count})
signal_index = signal_index + 1
if signal_index > max_signals then

View File

@@ -27,7 +27,7 @@ function pl.pl(type, target, amount)
return
end
local stats = target.force.item_production_statistics
local stats = target.force.get_item_production_statistics(target.surface)
for k, v in pairs(config.request) do
local v_min = math.ceil(v.min * amount)

View File

@@ -6,74 +6,77 @@ local lib = {}
lib.collect_production = function()
for _, force in pairs(game.forces) do
---@class ItemStats
---@field count number
general.data.output[force.name].production = {}
for _, surface in pairs(game.surfaces) do
---@class ItemStats
---@field count number
---@class ProductionStatistics
---@field item_input table<string, ItemStats>
---@field item_output table<string, ItemStats>
---@field fluid_input table<string, ItemStats>
---@field fluid_output table<string, ItemStats>
---@field kill_input table<string, ItemStats>
---@field kill_output table<string, ItemStats>
---@field build_input table<string, ItemStats>
---@field build_output table<string, ItemStats>
local stats = {
item_input = {},
item_output = {},
fluid_input = {},
fluid_output = {},
kill_input = {},
kill_output = {},
build_input = {},
build_output = {},
}
---@class ProductionStatistics
---@field item_input table<string, ItemStats>
---@field item_output table<string, ItemStats>
---@field fluid_input table<string, ItemStats>
---@field fluid_output table<string, ItemStats>
---@field kill_input table<string, ItemStats>
---@field kill_output table<string, ItemStats>
---@field build_input table<string, ItemStats>
---@field build_output table<string, ItemStats>
local stats = {
item_input = {},
item_output = {},
fluid_input = {},
fluid_output = {},
kill_input = {},
kill_output = {},
build_input = {},
build_output = {},
}
for name, count in pairs(force.item_production_statistics.input_counts) do
local itemstats = stats.item_input[name] or {}
itemstats.count = count
stats.item_input[name] = itemstats
end
for name, count in pairs(force.item_production_statistics.output_counts) do
local itemstats = stats.item_output[name] or {}
itemstats.count = count
stats.item_output[name] = itemstats
end
for name, count in pairs(force.get_item_production_statistics(surface).input_counts) do
local itemstats = stats.item_input[name] or {}
itemstats.count = count
stats.item_input[name] = itemstats
end
for name, count in pairs(force.get_item_production_statistics(surface).output_counts) do
local itemstats = stats.item_output[name] or {}
itemstats.count = count
stats.item_output[name] = itemstats
end
for name, count in pairs(force.fluid_production_statistics.input_counts) do
local fluidstats = stats.fluid_input[name] or {}
fluidstats.count = count
stats.fluid_input[name] = fluidstats
end
for name, count in pairs(force.fluid_production_statistics.output_counts) do
local fluidstats = stats.fluid_output[name] or {}
fluidstats.count = count
stats.fluid_output[name] = fluidstats
end
for name, count in pairs(force.get_fluid_production_statistics(surface).input_counts) do
local fluidstats = stats.fluid_input[name] or {}
fluidstats.count = count
stats.fluid_input[name] = fluidstats
end
for name, count in pairs(force.get_fluid_production_statistics(surface).output_counts) do
local fluidstats = stats.fluid_output[name] or {}
fluidstats.count = count
stats.fluid_output[name] = fluidstats
end
for name, count in pairs(force.kill_count_statistics.input_counts) do
local killstats = stats.kill_input[name] or {}
killstats.count = count
stats.kill_input[name] = killstats
end
for name, count in pairs(force.kill_count_statistics.output_counts) do
local killstats = stats.kill_output[name] or {}
killstats.count = count
stats.kill_output[name] = killstats
end
for name, count in pairs(force.get_kill_count_statistics(surface).input_counts) do
local killstats = stats.kill_input[name] or {}
killstats.count = count
stats.kill_input[name] = killstats
end
for name, count in pairs(force.get_kill_count_statistics(surface).output_counts) do
local killstats = stats.kill_output[name] or {}
killstats.count = count
stats.kill_output[name] = killstats
end
for name, count in pairs(force.entity_build_count_statistics.input_counts) do
local buildstats = stats.build_input[name] or {}
buildstats.count = count
stats.build_input[name] = buildstats
end
for name, count in pairs(force.entity_build_count_statistics.output_counts) do
local buildstats = stats.build_output[name] or {}
buildstats.count = count
stats.build_output[name] = buildstats
end
for name, count in pairs(force.get_entity_build_count_statistics(surface).input_counts) do
local buildstats = stats.build_input[name] or {}
buildstats.count = count
stats.build_input[name] = buildstats
end
for name, count in pairs(force.get_entity_build_count_statistics(surface).output_counts) do
local buildstats = stats.build_output[name] or {}
buildstats.count = count
stats.build_output[name] = buildstats
end
general.data.output[force.name].production = stats
general.data.output[force.name].production[surface.name] = stats
end
end
end

View File

@@ -31,9 +31,9 @@ end
local toggle_section =
Gui.element{
type = 'sprite-button',
sprite = 'utility/expand_dark',
hovered_sprite = 'utility/expand',
sprite = 'utility/expand',
tooltip = {'autofill.toggle-section-tooltip'},
style = "frame_action_button",
name = Gui.unique_static_name
}
:style(Gui.sprite_style(20))
@@ -42,12 +42,10 @@ Gui.element{
local flow_name = header_flow.caption
local flow = header_flow.parent.parent[flow_name]
if Gui.toggle_visible_state(flow) then
element.sprite = 'utility/collapse_dark'
element.hovered_sprite = 'utility/collapse'
element.sprite = 'utility/collapse'
element.tooltip = {'autofill.toggle-section-collapse-tooltip'}
else
element.sprite = 'utility/expand_dark'
element.hovered_sprite = 'utility/expand'
element.sprite = 'utility/expand'
element.tooltip = {'autofill.toggle-section-tooltip'}
end
end)

View File

@@ -7,6 +7,7 @@ local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local config = require("modules.exp_legacy.config.bonus") --- @dep config.bonus
local vlayer = require("modules.exp_legacy.modules.control.vlayer")
local format_number = require("util").format_number --- @dep util
local bonus_container

View File

@@ -11,7 +11,7 @@ local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local rolling_stocks = {}
local function landfill_init()
for name, _ in pairs(game.get_filtered_entity_prototypes({{filter = 'rolling-stock'}})) do
for name, _ in pairs(prototypes.get_entity_filtered{{filter = 'rolling-stock'}}) do
rolling_stocks[name] = true
end
end
@@ -103,9 +103,10 @@ local function landfill_gui_add_landfill(blueprint)
if not (rolling_stocks[ent.name] or ent.name == 'offshore-pump') then
-- curved rail, special
if ent.name ~= 'curved-rail' then
local box = game.entity_prototypes[ent.name].collision_box or game.entity_prototypes[ent.name].selection_box
local proto = prototypes.entity[ent.name]
local box = proto.collision_box or proto.selection_box
if game.entity_prototypes[ent.name].collision_mask['ground-tile'] == nil then
if proto.collision_mask['ground-tile'] == nil then
if ent.direction then
if ent.direction ~= defines.direction.north then
box = rotate_bounding_box(box)

View File

@@ -32,8 +32,8 @@ end
local prod_module_names = {}
local function get_module_name()
for name, item in pairs(game.item_prototypes) do
if item.module_effects and item.module_effects.productivity and item.module_effects.productivity.bonus > 0 then
for name, item in pairs(prototypes.item) do
if item.module_effects and item.module_effects.productivity and item.module_effects.productivity > 0 then
prod_module_names[#prod_module_names + 1] = name
end
end
@@ -124,7 +124,7 @@ Selection.on_selection(SelectionModuleArea, function(event)
['p'] = {}
}
for j=1, game.entity_prototypes[mma].module_inventory_size, 1 do
for j=1, prototypes.entity[mma].module_inventory_size, 1 do
local mmo = scroll_table['module_mm_' .. i .. '_' .. j].elem_value
if mmo then
@@ -161,7 +161,7 @@ local function row_set(player, element)
if scroll_table[element .. '0'].elem_value then
for i=1, config.module_slot_max do
if i <= game.entity_prototypes[scroll_table[element .. '0'].elem_value].module_inventory_size then
if i <= prototypes.entity[scroll_table[element .. '0'].elem_value].module_inventory_size then
if config.machine[scroll_table[element .. '0'].elem_value].prod then
scroll_table[element .. i].elem_filters = elem_filter.prod

View File

@@ -27,7 +27,7 @@ config.set_datastores(SelectedPlayer, SelectedAction)
local open_action_bar =
Gui.element{
type = 'sprite-button',
sprite = 'utility/expand_dots_white',
sprite = 'utility/expand_dots',
tooltip = {'player-list.open-action-bar'},
style = 'frame_button',
name = Gui.unique_static_name

View File

@@ -130,7 +130,7 @@ end)
Event.on_nth_tick(60, function()
for _, player in pairs(game.connected_players) do
local frame = Gui.get_left_element(player, production_container)
local stat = player.force.item_production_statistics
local stat = player.force.get_item_production_statistics(player.surface)
local precision_value = precision[frame.container['production_st'].disp.table['production_0_e'].selected_index]
local table = frame.container['production_st'].disp.table
@@ -139,8 +139,8 @@ Event.on_nth_tick(60, function()
local item = table[production_prefix .. '_e'].elem_value
if item then
local add = stat.get_flow_count{name=item, input=true, precision_index=precision_value, count=false} / 60
local minus = stat.get_flow_count{name=item, input=false, precision_index=precision_value, count=false} / 60
local add = math.floor(stat.get_flow_count{name=item, category="input", precision_index=precision_value, count=false} / 6) / 10
local minus = math.floor(stat.get_flow_count{name=item, category="output", precision_index=precision_value, count=false} / 6) / 10
local sum = add - minus
table[production_prefix .. '_1'].caption = format_n(add)

View File

@@ -81,14 +81,15 @@ Gui.element(function(_, parent, server_id, wrong_version)
local flow = parent.add{ name = server_id, type = 'flow' }
local button = flow.add{
type = 'sprite-button',
sprite = 'utility/circuit_network_panel_white', --- network panel white, warning white, download white
hovered_sprite = 'utility/circuit_network_panel_black', --- network panel black, warning black, download black
tooltip = {'readme.servers-connect-'..status, wrong_version}
sprite = 'utility/circuit_network_panel',
hovered_sprite = 'utility/circuit_network_panel',
tooltip = {'readme.servers-connect-'..status, wrong_version},
style = "frame_action_button"
}
if status == 'Offline' or status == 'Current' then
button.enabled = false
button.sprite = 'utility/circuit_network_panel_black'
button.sprite = 'utility/circuit_network_panel'
elseif status == 'Version' then
button.enabled = false
button.sprite = 'utility/shuffle'
@@ -119,9 +120,9 @@ Gui.element(function(_, parent)
-- Set up the top flow with logos
local top_flow = container.add{ type='flow' }
top_flow.add{ type='sprite', sprite='file/modules/gui/logo.png' }
top_flow.add{ type='sprite', sprite='file/modules/exp_legacy/modules/gui/logo.png' }
local top_vertical_flow = top_flow.add{ type='flow', direction='vertical' }
top_flow.add{ type='sprite', sprite='file/modules/gui/logo.png' }
top_flow.add{ type='sprite', sprite='file/modules/exp_legacy/modules/gui/logo.png' }
top_vertical_flow.style.horizontal_align = 'center'
-- Add the title and description to the top flow
@@ -415,7 +416,7 @@ Gui.element(function(definition, parent)
local left_side =
left_alignment.add{
type = 'frame',
style = 'frame_without_right_side'
style = 'character_gui_left_side'
}
left_side.style.vertically_stretchable = true
left_side.style.padding = 0

View File

@@ -153,7 +153,7 @@ local function research_gui_update()
local res_i = res_n + i - 3
if res['disp'][res_i] then
res_disp[i]['name'] = {'expcom-res.res-name', res['disp'][res_i]['raw_name'], game.technology_prototypes[res['disp'][res_i]['raw_name']].localised_name}
res_disp[i]['name'] = {'expcom-res.res-name', res['disp'][res_i]['raw_name'], prototypes.technology[res['disp'][res_i]['raw_name']].localised_name}
if research.time[res_i] == 0 then
res_disp[i]['target'] = res['disp'][res_i].target_disp

View File

@@ -423,9 +423,10 @@ end
local toggle_section =
Gui.element{
type = 'sprite-button',
sprite = 'utility/expand_dark',
sprite = 'utility/expand',
hovered_sprite = 'utility/expand',
tooltip = {'rocket-info.toggle-section-tooltip'},
style = "frame_action_button",
name = Gui.unique_static_name
}
:style(Gui.sprite_style(20))
@@ -434,12 +435,10 @@ Gui.element{
local flow_name = header_flow.caption
local flow = header_flow.parent.parent[flow_name]
if Gui.toggle_visible_state(flow) then
element.sprite = 'utility/collapse_dark'
element.hovered_sprite = 'utility/collapse'
element.sprite = 'utility/collapse'
element.tooltip = {'rocket-info.toggle-section-collapse-tooltip'}
else
element.sprite = 'utility/expand_dark'
element.hovered_sprite = 'utility/expand'
element.sprite = 'utility/expand'
element.tooltip = {'rocket-info.toggle-section-tooltip'}
end
end)
@@ -523,7 +522,7 @@ end)
--- Button on the top flow used to toggle the container
-- @element toggle_rocket_info
Gui.left_toolbar_button('item/satellite', {'rocket-info.main-tooltip'}, rocket_list_container, function(player)
Gui.left_toolbar_button('item/rocket-silo', {'rocket-info.main-tooltip'}, rocket_list_container, function(player)
return Roles.player_allowed(player, 'gui/rocket-info')
end)

View File

@@ -299,7 +299,7 @@ Gui.element(function(definition, parent)
type = 'label',
caption = null_time_short,
tooltip = null_time_long,
style = 'heading_1_label'
style = 'frame_title'
}
-- Update the eta

View File

@@ -114,8 +114,9 @@ local no_tasks_found =
local center =
header.add {
type = "flow",
style = "centering_horizontal_flow"
}
center.style.vertical_align = "center"
center.style.horizontal_align = "center"
center.style.horizontally_stretchable = true
center.add {
name = "header_label",
@@ -156,7 +157,7 @@ local subfooter_label =
return parent.add {
name = "footer_label",
type = "label",
style = "heading_1_label",
style = "frame_title",
caption = caption
}
end
@@ -240,7 +241,7 @@ local task_view_edit_button =
Gui.element {
type = "button",
name = Gui.unique_static_name,
caption = {"", "[img=utility/rename_icon_normal] ", {"task-list.edit"}},
caption = {"", "[img=utility/rename_icon] ", {"task-list.edit"}},
tooltip = {"task-list.edit-tooltip"},
style = "shortcut_bar_button"
}:style(Styles.footer_button):on_click(
@@ -257,8 +258,8 @@ local task_view_edit_button =
local task_view_close_button =
Gui.element{
type = "sprite-button",
sprite = "utility/collapse_dark",
hovered_sprite = "utility/collapse",
sprite = "utility/collapse",
style = "frame_action_button",
tooltip = {"task-list.close-tooltip"}
}
:style(Styles.sprite22):on_click(

View File

@@ -353,6 +353,7 @@ for index, element_define in ipairs(Gui.top_elements) do
if prev_handler then prev_handler(player, element, event) end -- Kind of hacky but works
local frame = Gui.get_left_element(player, toolbar_container)
if not frame then return end -- Gui might not be loaded yet
if not frame.container then log(frame.name) log(frame.parent.name) end
local button = frame.container.scroll.list[element_define.name][element_define.name]
local toolbar_button = Gui.get_top_element(player, element_define)
copy_style(toolbar_button, button)

View File

@@ -115,7 +115,7 @@ Gui.element{
radius = config.standard_proximity_radius + 2.5,
position = position,
collision_mask = {
'item-layer', 'object-layer', 'player-layer', 'water-tile'
'item', 'object', 'player', 'water_tile'
}
}
-- Remove 1 because that is the current player
@@ -256,8 +256,8 @@ end)
-- Required fields to make it squashable and strechable.
minimal_width = 10,
maximal_width = 300,
horizontally_squashable = "on",
horizontally_stretchable = "on",
horizontally_squashable = true,
horizontally_stretchable = true,
-- Other styling
height = 22,
padding = -2,
@@ -336,7 +336,7 @@ end)
local edit_warp_button =
Gui.element{
type = 'sprite-button',
sprite = 'utility/rename_icon_normal',
sprite = 'utility/rename_icon',
tooltip = {'warp-list.edit-tooltip-none'},
style = 'shortcut_bar_button',
name = Gui.unique_static_name