Skip to content

Commit

Permalink
Spidertron corpses keep correct color
Browse files Browse the repository at this point in the history
  • Loading branch information
tburrows13 committed Jul 16, 2022
1 parent 5f69953 commit 979dc8b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 76 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 1.8.6
Date: ???
Bugfixes:
- Spidertron corpses now keep the spidertron's color (thanks to PrestonLeeC for providing the solution!)
---------------------------------------------------------------------------------------------------
Version: 1.8.5
Date: 17 May 2022
Bugfixes:
Expand Down
11 changes: 10 additions & 1 deletion control.lua
Expand Up @@ -9,7 +9,7 @@ end
spidertron_lib = require "scripts.spidertron_lib"
require "scripts.hidden-spidertron"
require "scripts.auto-sort"
require "scripts.create-corpse"
local create_corpse = require "scripts.create-corpse"
require "scripts.disconnect-remote"
require "scripts.remote-pipette"
require "scripts.open-inventory"
Expand All @@ -36,6 +36,13 @@ script.on_event(defines.events.on_gui_opened,
end
)

script.on_event(defines.events.on_entity_destroyed,
function(event)
recall_spidertron.on_entity_destroyed(event)
create_corpse.on_entity_destroyed(event)
end
)

script.on_init(
function()
global.stored_spidertrons = {} -- Indexed by player.index
Expand All @@ -46,6 +53,7 @@ script.on_init(

global.last_spidertron = {} -- Indexed by player.index
global.destroy_registrations = {} -- Indexed by registration number
global.corpse_destroy_registrations = {} -- Indexed by registration number

global.vehicle_to_enter_this_tick = {} -- Indexed by game.tick

Expand All @@ -64,6 +72,7 @@ script.on_configuration_changed(
-- Added in 1.4.0
global.last_spidertron = global.last_spidertron or {}
global.destroy_registrations = global.destroy_registrations or {}
global.corpse_destroy_registrations = global.corpse_destroy_registrations or {}

global.vehicle_to_enter_this_tick = global.vehicle_to_enter_this_tick or {}
global.player_last_driving_change_tick = nil -- Removed in v1.4.0
Expand Down
61 changes: 1 addition & 60 deletions prototypes/corpse.lua
Expand Up @@ -13,66 +13,7 @@ if settings.startup["spidertron-enhancements-enable-corpse"].value then
open_sound = { filename = "__base__/sound/character-corpse-open.ogg", volume = 0.5 },
close_sound = { filename = "__base__/sound/character-corpse-close.ogg", volume = 0.5 },
render_layer = "corpse",
pictures =
{
{
layers =
{
{
filename = "__base__/graphics/entity/spidertron/remnants/spidertron-remnants.png",
line_length = 1,
width = 224,
height = 224,
frame_count = 1,
variation_count = 1,
axially_symmetrical = false,
direction_count = 1,
shift = util.by_pixel(0, 0),
hr_version =
{
filename = "__base__/graphics/entity/spidertron/remnants/hr-spidertron-remnants.png",
line_length = 1,
width = 448,
height = 448,
frame_count = 1,
variation_count = 1,
axially_symmetrical = false,
direction_count = 1,
shift = util.by_pixel(0, 0),
scale = 0.5
}
},
{
priority = "low",
filename = "__base__/graphics/entity/spidertron/remnants/mask/spidertron-remnants-mask.png",
width = 184,
height = 176,
frame_count = 1,
-- tint = { r = 0.869, g = 0.5 , b = 0.130, a = 0.5 },
apply_runtime_tint = true,
direction_count = 1,
shift = util.by_pixel(9, 1),
hr_version=
{
priority = "low",
filename = "__base__/graphics/entity/spidertron/remnants/mask/hr-spidertron-remnants-mask.png",
width = 366,
height = 350,
frame_count = 1,
--tint = { r = 0.869, g = 0.5 , b = 0.130, a = 0.5 },
apply_runtime_tint = true,
direction_count = 1,
shift = util.by_pixel(9, 1),
scale = 0.5
}
}
}
}
}
picture = util.empty_sprite() -- Graphics are provided by "corpse" entity
}
}

-- Better to hide existing corpse graphics than to remove the corpse entity
--data.raw["spider-vehicle"]["spidertron"].corpse = nil
data.raw.corpse["spidertron-remnants"].animation = nil
end
16 changes: 16 additions & 0 deletions scripts/create-corpse.lua
Expand Up @@ -76,6 +76,9 @@ function on_spidertron_died(spidertron)
local transferred = corpse_inventory[i].transfer_stack(temp_inventory[i])
end

local reg_id = script.register_on_entity_destroyed(corpse)
global.corpse_destroy_registrations[reg_id] = {position = corpse.position, surface = corpse.surface}

temp_inventory.destroy()
end
end
Expand All @@ -89,3 +92,16 @@ script.on_event(defines.events.on_entity_died,
end,
{{filter = "type", type = "spider-vehicle"}}
)

local function on_entity_destroyed(event)
local corpse_data = global.corpse_destroy_registrations[event.registration_number]
if corpse_data then
local corpse = corpse_data.surface.find_entity("spidertron-remnants", corpse_data.position)
if corpse then
corpse.destroy()
end
global.corpse_destroy_registrations[event.registration_number] = nil
end
end

return {on_entity_destroyed = on_entity_destroyed}
27 changes: 12 additions & 15 deletions scripts/recall-last-spidertron.lua
Expand Up @@ -46,24 +46,21 @@ script.on_event(defines.events.on_player_used_spider_remote,
end
)

script.on_event(defines.events.on_entity_destroyed,
function(event)
local player_index = global.destroy_registrations[event.registration_number]
if player_index then
local player = game.get_player(player_index)
if player then
local spidertron = global.last_spidertron[player.index]
if not (spidertron and spidertron.valid) then
player.set_shortcut_toggled(SHORTCUT_NAME, false)
player.set_shortcut_available(SHORTCUT_NAME, false)
global.last_spidertron[player.index] = nil
end
local function on_entity_destroyed(event)
local player_index = global.destroy_registrations[event.registration_number]
if player_index then
local player = game.get_player(player_index)
if player then
local spidertron = global.last_spidertron[player.index]
if not (spidertron and spidertron.valid) then
player.set_shortcut_toggled(SHORTCUT_NAME, false)
player.set_shortcut_available(SHORTCUT_NAME, false)
global.last_spidertron[player.index] = nil
end
end

global.destroy_registrations[event.registration_number] = nil
end
)
end

local function on_shortcut_pressed(event)
local player = game.get_player(event.player_index)
Expand Down Expand Up @@ -122,4 +119,4 @@ script.on_event(defines.events.on_player_created,
end
)

return {on_init = on_init}
return {on_init = on_init, on_entity_destroyed = on_entity_destroyed}

0 comments on commit 979dc8b

Please sign in to comment.