Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetabite committed Oct 13, 2020
1 parent d0e2877 commit 4c6ef57
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 33 deletions.
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
---------------------------------------------------------------------------------------------------
Version: 0.8.2
Date: 13.10.2020
Bugfixes:
- Fixed on_load() crash due to global manipulation
- Made constants only load as local

---------------------------------------------------------------------------------------------------
Version: 0.8.1
Date: 12.10.2020
Expand Down
1 change: 1 addition & 0 deletions scripts/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ config.SPICE_COOLDOWN = config.SPICE_DURATION
config.OVERLAY_REFRESH = 30
config.OVERLAY_TIMER = config.OVERLAY_REFRESH + 1
config.ZOOM_FACTOR = 3.0
config.VICTORY_SPICE_AMOUNT = 10000
return config
6 changes: 2 additions & 4 deletions scripts/control/forces.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local forces_table, competitor_spice_table
local VICTORY_SPICE_AMOUNT = 10000
local config = require('scripts.config')
local VICTORY_SPICE_AMOUNT = config.VICTORY_SPICE_AMOUNT

function force_created(event)
local force_index = event.force.index
Expand Down Expand Up @@ -57,19 +58,16 @@ lib.on_nth_tick = {
lib.on_init = function()
forces_table = global.forces
competitor_spice_table = global.competitor_spice
global.VICTORY_SPICE_AMOUNT = VICTORY_SPICE_AMOUNT
end

lib.on_configuration_changed = function()
forces_table = global.forces
competitor_spice_table = global.competitor_spice
global.VICTORY_SPICE_AMOUNT = VICTORY_SPICE_AMOUNT
end

lib.on_load = function ()
forces_table = global.forces
competitor_spice_table = global.competitor_spice
global.VICTORY_SPICE_AMOUNT = VICTORY_SPICE_AMOUNT
end

return lib
51 changes: 28 additions & 23 deletions scripts/control/players.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local SPICE_DURATION = config.SPICE_DURATION
local SPICE_COOLDOWN = config.SPICE_COOLDOWN
local OVERLAY_REFRESH = config.OVERLAY_REFRESH
local OVERLAY_TIMER = config.OVERLAY_TIMER
local ZOOM_FACTOR = config.ZOOM_FACTOR

function apply_spice_to_vehicle(player)
if (player.vehicle) then
Expand Down Expand Up @@ -236,30 +235,12 @@ function overlay_refresh()
tint = {r = 0.04, g = 0.18, b = 0.66},
target = player.character,
surface = player.surface,
time_to_live = OVERLAY_REFRESH + 1,
time_to_live = OVERLAY_TIMER,
player = {player}
})
end
end

function load()
players_table = global.players
spice_effects_blacklist = global.spice_effects_blacklist
render_table = global.render_table

global.SPICE_COOLDOWN = SPICE_COOLDOWN
global.SPICE_DURATION = SPICE_DURATION
global.OVERLAY_REFRESH = OVERLAY_REFRESH
global.OVERLAY_TIMER = OVERLAY_TIMER
global.ZOOM_FACTOR = ZOOM_FACTOR

if script.active_mods['Kux-Zooming'] then
if remote.interfaces['Kux-Zooming'] and remote.interfaces['Kux-Zooming']['onZoomFactorChanged'] then
remote.call('Kux-Zooming', 'onZoomFactorChanged_add', 'nauvis_melange_player', 'onZoomFactorChanged')
end
end
end

-- lib
local lib = {}

Expand All @@ -274,15 +255,39 @@ lib.events = {
}

lib.on_init = function()
load()
players_table = global.players
spice_effects_blacklist = global.spice_effects_blacklist
render_table = global.render_table

if script.active_mods['Kux-Zooming'] then
if remote.interfaces['Kux-Zooming'] and remote.interfaces['Kux-Zooming']['onZoomFactorChanged'] then
remote.call('Kux-Zooming', 'onZoomFactorChanged_add', 'nauvis_melange_player', 'onZoomFactorChanged')
end
end
end

lib.on_configuration_changed = function()
load()
players_table = global.players
spice_effects_blacklist = global.spice_effects_blacklist
render_table = global.render_table

if script.active_mods['Kux-Zooming'] then
if remote.interfaces['Kux-Zooming'] and remote.interfaces['Kux-Zooming']['onZoomFactorChanged'] then
remote.call('Kux-Zooming', 'onZoomFactorChanged_add', 'nauvis_melange_player', 'onZoomFactorChanged')
end
end
end

lib.on_load = function ()
load()
players_table = global.players
spice_effects_blacklist = global.spice_effects_blacklist
render_table = global.render_table

if script.active_mods['Kux-Zooming'] then
if remote.interfaces['Kux-Zooming'] and remote.interfaces['Kux-Zooming']['onZoomFactorChanged'] then
remote.call('Kux-Zooming', 'onZoomFactorChanged_add', 'nauvis_melange_player', 'onZoomFactorChanged')
end
end
end

lib.on_nth_tick = {
Expand Down
14 changes: 8 additions & 6 deletions scripts/control/setup.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local config = require('scripts.config')

remote.add_interface('nauvis_melange_table_defaults', {
players_default = function()
return {
Expand Down Expand Up @@ -42,22 +44,22 @@ remote.add_interface('nauvis_melange_table_defaults', {

remote.add_interface('nauvis_melange_constants', {
VICTORY_SPICE_AMOUNT = function()
return global.VICTORY_SPICE_AMOUNT
return config.VICTORY_SPICE_AMOUNT
end,
SPICE_COOLDOWN = function()
return global.SPICE_COOLDOWN
return config.SPICE_COOLDOWN
end,
SPICE_DURATION = function()
return global.SPICE_DURATION
return config.SPICE_DURATION
end,
OVERLAY_REFRESH = function()
return global.OVERLAY_REFRESH
return config.OVERLAY_REFRESH
end,
ZOOM_FACTOR = function()
return global.ZOOM_FACTOR
return config.ZOOM_FACTOR
end,
OVERLAY_TIMER = function()
return global.OVERLAY_TIMER
return config.OVERLAY_TIMER
end
})

Expand Down

0 comments on commit 4c6ef57

Please sign in to comment.