From e0e21da26fd22d9922a9f617c586ebd2eaa4487e Mon Sep 17 00:00:00 2001 From: Oarcinae Date: Tue, 26 Nov 2024 21:02:36 -0500 Subject: [PATCH] Update changelog and fix migration bug where gleba_resources was missing in nauvis config. --- changelog.txt | 3 ++ lib/separate_spawns.lua | 73 +++++++++++++++++++-------------- migrations/oarc-mod-v2.1.15.lua | 12 ++++++ 3 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 migrations/oarc-mod-v2.1.15.lua diff --git a/changelog.txt b/changelog.txt index aca547e..ed7390b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,7 +1,10 @@ --------------------------------------------------------------------------------------------------- Version: 2.1.15 Date: ???? + Bugfixes: + - Fix crash when player spawns due to missing surface configuration due to a missing migration. Changes: + - Images losslessly compressed to reduce mod size. (Thanks plexpt!) --------------------------------------------------------------------------------------------------- Version: 2.1.14 Date: 2024-11-21 diff --git a/lib/separate_spawns.lua b/lib/separate_spawns.lua index 9fe5083..e18509b 100644 --- a/lib/separate_spawns.lua +++ b/lib/separate_spawns.lua @@ -431,38 +431,44 @@ function GenerateStartingResources(surface, position) local y_offset = storage.ocfg.resource_placement.distance_to_edge local fluid_ref_pos = { x = position.x, y = position.y + radius - y_offset } - for r_name, r_data in pairs(storage.ocfg.surfaces_config[surface.name].spawn_config.fluid_resources --[[@as table]]) do + local fluid_resources = storage.ocfg.surfaces_config[surface.name].spawn_config.fluid_resources + if fluid_resources ~= nil then + for r_name, r_data in pairs(fluid_resources) do - local spacing = r_data.spacing - local oil_patch_x = fluid_ref_pos.x - (((r_data.num_patches-1) * spacing) / 2) - local oil_patch_y = fluid_ref_pos.y + local spacing = r_data.spacing + local oil_patch_x = fluid_ref_pos.x - (((r_data.num_patches-1) * spacing) / 2) + local oil_patch_y = fluid_ref_pos.y - for i = 1, r_data.num_patches do - surface.create_entity({ - name = r_name, - amount = r_data.amount, - position = { oil_patch_x, oil_patch_y } - }) - oil_patch_x = oil_patch_x + spacing + for i = 1, r_data.num_patches do + surface.create_entity({ + name = r_name, + amount = r_data.amount, + position = { oil_patch_x, oil_patch_y } + }) + oil_patch_x = oil_patch_x + spacing + end + + fluid_ref_pos.y = fluid_ref_pos.y - spacing end - - fluid_ref_pos.y = fluid_ref_pos.y - spacing end -- This places using specified offsets if auto placement is disabled. else local fluid_ref_pos = { x = position.x, y = position.y + radius } - for r_name, r_data in pairs(storage.ocfg.surfaces_config[surface.name].spawn_config.fluid_resources --[[@as table]]) do - local oil_patch_x = fluid_ref_pos.x + r_data.x_offset_start - local oil_patch_y = fluid_ref_pos.y + r_data.y_offset_start - for i = 1, r_data.num_patches do - surface.create_entity({ - name = r_name, - amount = r_data.amount, - position = { oil_patch_x, oil_patch_y } - }) - oil_patch_x = oil_patch_x + r_data.x_offset_next - oil_patch_y = oil_patch_y + r_data.y_offset_next + local fluid_resources = storage.ocfg.surfaces_config[surface.name].spawn_config.fluid_resources + if fluid_resources ~= nil then + for r_name, r_data in pairs(fluid_resources) do + local oil_patch_x = fluid_ref_pos.x + r_data.x_offset_start + local oil_patch_y = fluid_ref_pos.y + r_data.y_offset_start + for i = 1, r_data.num_patches do + surface.create_entity({ + name = r_name, + amount = r_data.amount, + position = { oil_patch_x, oil_patch_y } + }) + oil_patch_x = oil_patch_x + r_data.x_offset_next + oil_patch_y = oil_patch_y + r_data.y_offset_next + end end end end @@ -479,15 +485,22 @@ function PlaceResourcesInSemiCircle(surface, position, size_mod, amount_mod) -- Create list of resource tiles ---@type table local r_list = {} - for r_name, _ in pairs(storage.ocfg.surfaces_config[surface.name].spawn_config.solid_resources) do - if (r_name ~= "") then - table.insert(r_list, r_name) + local solid_resources = storage.ocfg.surfaces_config[surface.name].spawn_config.solid_resources + if solid_resources ~= nil then + for r_name, _ in pairs(solid_resources) do + if (r_name ~= "") then + table.insert(r_list, r_name) + end end end - for g_name,_ in pairs(storage.ocfg.surfaces_config[surface.name].spawn_config.gleba_resources) do - if (g_name ~= "") then - table.insert(r_list, g_name) + -- Gleba style resources like plants + local gleba_resources = storage.ocfg.surfaces_config[surface.name].spawn_config.gleba_resources + if gleba_resources ~= nil then + for g_name, _ in pairs(gleba_resources) do + if (g_name ~= "") then + table.insert(r_list, g_name) + end end end diff --git a/migrations/oarc-mod-v2.1.15.lua b/migrations/oarc-mod-v2.1.15.lua new file mode 100644 index 0000000..15894d5 --- /dev/null +++ b/migrations/oarc-mod-v2.1.15.lua @@ -0,0 +1,12 @@ +--Fix missing gleba_resources for the surfaces that I didn't update in 2.1.13. +if (storage.ocfg.surfaces_config["nauvis"].spawn_config.gleba_resources == nil) then + storage.ocfg.surfaces_config["nauvis"].spawn_config.gleba_resources = {} + log("Fixing nauvis config with empty gleba_resources entry.") +end + +if script.active_mods["space-age"] ~= nil then + if (storage.ocfg.surfaces_config["fulgora"].spawn_config.gleba_resources == nil) then + storage.ocfg.surfaces_config["fulgora"].spawn_config.gleba_resources = {} + log("Fixing fulgora config with empty gleba_resources entry.") + end +end \ No newline at end of file