Skip to content

Commit

Permalink
Update to 0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ZwerOxotnik committed Oct 21, 2024
1 parent f1e60a3 commit 177dfcb
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 53 deletions.
10 changes: 2 additions & 8 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
[submodule "static-libs"]
path = static-libs
url = https://github.com/ZwerOxotnik/zk-factorio-static-lib
[submodule "event-listener/branch-1/v0-9-3"]
path = event-listener/branch-1/v0-9-3
url = https://gitlab.com/ZwerOxotnik/factorio-event-listener
[submodule "event-listener/branch-1/v0-9-4"]
path = event-listener/branch-1/v0-9-4
url = https://gitlab.com/ZwerOxotnik/factorio-event-listener
[submodule "event-listener/branch-1/v0-9-5"]
path = event-listener/branch-1/v0-9-5
[submodule "event-listener/branch-1/v0-9-6"]
path = event-listener/branch-1/v0-9-6
url = https://gitlab.com/ZwerOxotnik/factorio-event-listener
14 changes: 7 additions & 7 deletions addons/adrenaline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local bonus_modifier = settings.global["adrenaline_bonus_modifier"].value or 2
local module = {}

local function reset_player_data(player)
local player_modifiers_data = global.adrenaline.players_modifiers[player.index]
local player_modifiers_data = storage.adrenaline.players_modifiers[player.index]
if player_modifier == nil then return end

local value1 = player_modifiers_data.character_mining_speed_modifier
Expand All @@ -30,7 +30,7 @@ local function reset_player_data(player)
end

-- local function reset_force_data(name)
-- local force_modifier = global.adrenaline.forces_modifiers[name]
-- local force_modifier = storage.adrenaline.forces_modifiers[name]
-- if not force_modifier then return end

-- local force = game.forces[name]
Expand All @@ -55,7 +55,7 @@ local function check_health(player)
end

local player_index = player.index
local players_modifiers = global.adrenaline.players_modifiers
local players_modifiers = storage.adrenaline.players_modifiers
if players_modifiers[player_index] == nil then
-- if #game.connected_players == 1 then
-- adrenaline.forces_modifiers[force.name] = {}
Expand Down Expand Up @@ -90,7 +90,7 @@ local function check_health(player)
end

-- local function check_forces_data()
-- local adrenaline = global.adrenaline
-- local adrenaline = storage.adrenaline
-- for _, force in pairs( game.forces ) do
-- local connected_players = force.connected_players
-- if #connected_players == 1 and adrenaline.players_modifiers[connected_players[1].index] then
Expand Down Expand Up @@ -129,7 +129,7 @@ local function on_player_left_game(event)
end

-- local function on_forces_merging(event)
-- local adrenaline = global.adrenaline
-- local adrenaline = storage.adrenaline
-- adrenaline.forces_modifiers[event.source.name] = nil
-- local connected_players = #event.source.connected_players + #event.destination.connected_players
-- if connected_players ~= 1 then
Expand All @@ -156,8 +156,8 @@ local function on_runtime_mod_setting_changed(event)
end

module.on_init = function()
global.adrenaline = global.adrenaline or {}
local data = global.adrenaline
storage.adrenaline = storage.adrenaline or {}
local data = storage.adrenaline
data.players_modifiers = data.players_modifiers or {}
-- data.forces_modifiers = data.forces_modifiers or {} -- it's not safe for MP
end
Expand Down
24 changes: 12 additions & 12 deletions addons/auto-mining.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ local am_util = require("static-libs/lualibs/control_stage/player-util")
local module = {}

local function clear_player_data(event)
global.auto_mining.players_mining[event.player_index] = nil
storage.auto_mining.players_mining[event.player_index] = nil
end

local function on_tick(event)
local players_mining = global.auto_mining.players_mining
local players_mining = storage.auto_mining.players_mining
for k, data in pairs(players_mining) do -- something is wrong
local player = game.get_player(k)
if player and player.valid and player.connected then
Expand All @@ -47,17 +47,17 @@ local function on_pre_player_mined_item(event)
if entity.type ~= "resource" then return end

if entity.amount > 1 then
global.auto_mining.players_mining[event.player_index] = {
storage.auto_mining.players_mining[event.player_index] = {
position = entity.position
}
else
local player_data = global.auto_mining.players_mining[event.player_index]
local player_data = storage.auto_mining.players_mining[event.player_index]
if player_data then
local new_position = am_util.get_new_resource_position_by_player_resource(player, entity)
if new_position == nil then
global.auto_mining.players_mining[event.player_index] = nil
storage.auto_mining.players_mining[event.player_index] = nil
else
global.auto_mining.players_mining[event.player_index] = {
storage.auto_mining.players_mining[event.player_index] = {
position = new_position
}
end
Expand All @@ -66,7 +66,7 @@ local function on_pre_player_mined_item(event)
end

local function on_player_mined_item(event)
if not global.auto_mining.players_mining[event.player_index] then return end
if not storage.auto_mining.players_mining[event.player_index] then return end
local player = game.get_player(event.player_index)
if not (player and player.valid) then return end

Expand All @@ -88,23 +88,23 @@ local function toggle_auto_mining(event)
if event.player_index == 0 then return end
local player = game.get_player(event.player_index)

if global.auto_mining.players_mining[event.player_index] then
if storage.auto_mining.players_mining[event.player_index] then
clear_player_data(event)
else
local new_position = am_util.get_resource_position_for_player(player)
if new_position == nil then
global.auto_mining.players_mining[event.player_index] = nil
storage.auto_mining.players_mining[event.player_index] = nil
else
global.auto_mining.players_mining[event.player_index] = {
storage.auto_mining.players_mining[event.player_index] = {
position = new_position
}
end
end
end

local function on_init()
global.auto_mining = global.auto_mining or {}
local data = global.auto_mining
storage.auto_mining = storage.auto_mining or {}
local data = storage.auto_mining
data.players_mining = data.players_mining or {}
end
module.on_init = on_init
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 0.17.0
Date: 02. 10. 2024
Changes:
- Updated for Factorio 2.0 (The mod may cause crashes)
---------------------------------------------------------------------------------------------------
Version: 0.16.7
Date: 02. 10. 2024
Scripting:
Expand Down
24 changes: 12 additions & 12 deletions core/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ zk_lib.remove_remote_interface = function()
end

local function update_global_data()
global.zk_lib = global.zk_lib or {}
global.zk_lib.addons = global.zk_lib.addons or {}
global.zk_lib.save_tick = global.zk_lib.save_tick or 0
storage.zk_lib = storage.zk_lib or {}
storage.zk_lib.addons = storage.zk_lib.addons or {}
storage.zk_lib.save_tick = storage.zk_lib.save_tick or 0
end

local function on_init()
Expand All @@ -30,17 +30,17 @@ local function on_init()
end

for name, _ in pairs(addons) do
if global.zk_lib.addons[name] == nil then
global.zk_lib.addons[name] = true
if storage.zk_lib.addons[name] == nil then
storage.zk_lib.addons[name] = true
end
end
end

local function on_configuration_changed(mod_data)
if global.zk_lib == nil or global.zk_lib.addons == nil then
if storage.zk_lib == nil or storage.zk_lib.addons == nil then
update_global_data()
for name, addon in pairs(addons) do
global.zk_lib.addons[name] = true
storage.zk_lib.addons[name] = true
if addon.init then -- it's a workaround to init global data because those addons don't init in some cases
addon.init()
elseif addon.on_init then
Expand All @@ -49,8 +49,8 @@ local function on_configuration_changed(mod_data)
end
else
for name, addon in pairs(addons) do
if global.zk_lib.addons[name] == nil then
global.zk_lib.addons[name] = true
if storage.zk_lib.addons[name] == nil then
storage.zk_lib.addons[name] = true
if addon.init then -- it's a workaround to init global data because those addons don't init in some cases
addon.init()
elseif addon.on_init then
Expand All @@ -61,7 +61,7 @@ local function on_configuration_changed(mod_data)
end

for _, addon_name in pairs(disabled_addons_list) do
global.zk_lib.addons[addon_name] = nil
storage.zk_lib.addons[addon_name] = nil
end
end

Expand All @@ -74,9 +74,9 @@ local function on_runtime_mod_setting_changed(event)
if settings.startup["zk-lib_" .. addon_name] == nil or settings.startup["zk-lib_" .. addon_name].value == true then
-- if safe mode is enabled then save game as an admin change state of an addon
if settings.global["zk-lib_safe-mode"].value == false then return end
if game.tick < global.zk_lib.save_tick then return end
if game.tick < storage.zk_lib.save_tick then return end

global.zk_lib.save_tick = game.tick + 4800
storage.zk_lib.save_tick = game.tick + 4800
game.auto_save()
elseif settings.startup["zk-lib_" .. addon_name] and settings.startup["zk-lib_" .. addon_name].value == false then
if event.player_index then
Expand Down
2 changes: 1 addition & 1 deletion event-listener/branch-1/experimental-version.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- By connecting this file in your code, you get the experimental version via \/
-- event_listener = require("__zk-lib__/event-listener/branch-1/experimental-version")

return require("v0-9-5/control")
return require("v0-9-6/control")
2 changes: 1 addition & 1 deletion event-listener/branch-1/last-version.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- By connecting this file in your code, you get the last version via \/
-- event_listener = require("__zk-lib__/event-listener/branch-1/branch-1/last-version")

return require("v0-9-5/control")
return require("v0-9-6/control")
2 changes: 1 addition & 1 deletion event-listener/branch-1/stable-version.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- By connecting this file in your code, you get the stable version via \/
-- event_listener = require("__zk-lib__/event-listener/branch-1/stable-version")

return require("v0-9-5/control")
return require("v0-9-6/control")
1 change: 0 additions & 1 deletion event-listener/branch-1/v0-9-3
Submodule v0-9-3 deleted from c7adaf
1 change: 0 additions & 1 deletion event-listener/branch-1/v0-9-4
Submodule v0-9-4 deleted from c7adaf
1 change: 0 additions & 1 deletion event-listener/branch-1/v0-9-5
Submodule v0-9-5 deleted from c7adaf
1 change: 1 addition & 0 deletions event-listener/branch-1/v0-9-6
Submodule v0-9-6 added at 41ab42
10 changes: 5 additions & 5 deletions experimental/lazyAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ lazyAPI.all_utility_sprite_fields = {
"technology_black", "technology_white",
"inserter_stack_size_bonus_modifier_icon",
"inserter_stack_size_bonus_modifier_constant",
"stack_inserter_capacity_bonus_modifier_icon",
"stack_inserter_capacity_bonus_modifier_constant",
"bulk_inserter_capacity_bonus_modifier_icon", --TODO: recheck
"bulk_inserter_capacity_bonus_modifier_constant", --TODO: recheck
"laboratory_speed_modifier_icon", "laboratory_speed_modifier_constant",
"character_logistic_slots_modifier_icon",
"character_logistic_slots_modifier_constant",
Expand Down Expand Up @@ -3747,7 +3747,7 @@ lazyAPI.remove_items_by_equipment = function(equipment)
local equipment_name = (type(equipment) == "string" and equipment) or equipment.name
for _, prototypes in pairs(lazyAPI.all_items) do --TODO: recheck, seems excessive
for _, item in pairs(prototypes) do
if item.placed_as_equipment_result == equipment_name then
if item.place_as_equipment_result == equipment_name then
lazyAPI.base.remove_prototype(item)
end
end
Expand Down Expand Up @@ -3777,8 +3777,8 @@ lazyAPI.replace_items_by_equipment = function(equipment, new_equipment)
local new_equipment_name = (type(new_equipment) == "string" and new_equipment) or new_equipment.name
for _, prototypes in pairs(lazyAPI.all_items) do --TODO: recheck, seems excessive
for _, item in pairs(prototypes) do
if item.placed_as_equipment_result == equipment_name then
item.placed_as_equipment_result = new_equipment_name
if item.place_as_equipment_result == equipment_name then
item.place_as_equipment_result = new_equipment_name
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zk-lib",
"version": "0.16.7",
"factorio_version": "1.1",
"version": "0.17.0",
"factorio_version": "2.0",
"title": "ZwerOxotnik's extendable mod with 8 addons",
"author": "ZwerOxotnik",
"contact": "zweroxotnik@gmail.com, discord:ZwerOxotnik",
Expand Down

0 comments on commit 177dfcb

Please sign in to comment.