1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-13 13:49:33 +02:00

planet_prison: fix global variable miussage.

Fixes some 'global' variable missusage.
This commit is contained in:
cogito 2020-01-15 18:53:44 +01:00
parent 198b5fd17a
commit 87eb854ace
6 changed files with 51 additions and 33 deletions

View File

@ -221,6 +221,12 @@ global.this.bp = {
merchant = require("planet_prison.bp.merchant")
}
local function init_game()
_common.init()
_layers.init()
_bp.init()
_ai.init()
_timers.init()
local map = pick_map()
local preset = global.this.presets[map.name]
global.this.surface = game.create_surface("arena", map)
@ -234,8 +240,6 @@ local function init_game()
game.difficulty_settings.technology_price_multiplier = 0.1
game.difficulty_settings.research_queue_setting = "always"
_timers.init()
_layers.init()
_layers.set_collision_mask({"water-tile"})
for _, layer in pairs(preset) do
@ -324,6 +328,7 @@ local function do_spawn_point(player)
layers = _layers,
common = _common,
timers = _timers,
func = _bp.destroy_reference,
},
surf = player.surface,
}

View File

@ -1,9 +1,6 @@
local public, this = {}, {}
local _global = require("utils.global")
local public = {}
local _common = require(".common")
_global.register(this, function(t) this = t end)
public.command = {
--[[
@param args nil
@ -16,6 +13,15 @@ public.command = {
seek_and_destroy_player = 1,
}
--[[
init - Initialize the module.
--]]
public.init = function()
if global.this == nil then
global.this = {}
end
end
local function _get_direction(src, dest)
local src_x = _common.get_axis(src, "x")
local src_y = _common.get_axis(src, "y")

View File

@ -1,9 +1,13 @@
local this, public = {}, {}
local _global = require("utils.global")
local public = {}
local _common = require(".common")
_global.register(this, function(t) this = t end)
this._bps = {}
public.init = function()
if global.this == nil then
global.this = {}
end
global.this._bps = {}
end
--[[
push_blueprint - Pushes blueprint into a list.
@ -16,7 +20,7 @@ public.push_blueprint = function(name, bp)
hook = nil,
refs = {}
}
this._bps[name] = entry
global.this._bps[name] = entry
end
--[[
@ -30,12 +34,12 @@ public.set_blueprint_hook = function(name, hook)
return
end
if this._bps[name] == nil then
if global.this._bps[name] == nil then
log("bp.set_blueprint_hook: unrecognized blueprint")
return
end
this._bps[name].hook = hook
global.this._bps[name].hook = hook
end
--[[
@ -48,7 +52,7 @@ public.get_references = function(name)
return {}
end
local object = this._bps[name]
local object = global.this._bps[name]
if object == nil then
log("bp.get_references: unrecognized blueprint")
return {}
@ -67,7 +71,7 @@ public.get_references = function(name)
return
end
local object = this._bps[name]
local object = global.this._bps[name]
if object == nil then
log("bp.get_references: unrecognized blueprint")
return
@ -116,7 +120,7 @@ public.unlink_references_filtered = function(name, query)
return
end
local object = this._bps[name]
local object = global.this._bps[name]
if object == nil then
log("bp.get_references: unrecognized blueprint")
return
@ -154,7 +158,7 @@ public.destroy_references_filtered = function(surf, name, query)
return
end
local object = this._bps[name]
local object = global.this._bps[name]
if object == nil then
log("bp.get_references: unrecognized blueprint")
return
@ -196,7 +200,7 @@ public.destroy_references = function(surf, name)
public.destroy_references_filtered(surf, name, {})
end
local function _destroy_reference(surf, ref)
global._bp_destroy_reference = function(surf, ref)
for _, ent in pairs(ref.entities) do
if ent.valid then
ent.destroy()
@ -223,11 +227,11 @@ destroy_reference - Destroys reference of a blueprint at given surface.
@param reference - Any valid reference.
--]]
public.destroy_reference = function(surf, reference)
for _, meta in pairs(this._bps) do
for _, meta in pairs(global.this._bps) do
for i = 1, #meta.refs do
local ref = meta.refs[i]
if reference.id == ref.id then
_destroy_reference(surf, ref)
global._bp_destroy_reference(surf, ref)
table.remove(meta.refs, i)
return
end
@ -301,7 +305,7 @@ public.build = function(surf, name, point, args)
return
end
local object = this._bps[name]
local object = global.this._bps[name]
if object == nil then
log("bp.set_blueprint_hook: unrecognized blueprint")
return

View File

@ -1,7 +1,10 @@
local public = {}
local _global = require("utils.global")
global.this = {}
_global.register(global.this, function(t) global.this = t end)
public.init = function()
if global.this == nil then
global.this = {}
end
end
--[[
rand_range - Return random integer within the range.

View File

@ -1,16 +1,16 @@
local public = {}
global.this = {}
local _global = require("utils.global")
local _common = require(".common")
local _simplex = require(".simplex_noise")
_global.register(global.this, function(t) global.this = t end)
global.this._grid = {}
global.this._exclusions = {}
global.this._layers = {}
global.this._collision_mask = {}
public.init = function()
if global.this == nil then
global.this = {}
end
global.this._grid = {}
global.this._exclusions = {}
global.this._layers = {}
global.this._collision_mask = {}
_simplex.init()
end
--[[

View File

@ -1,5 +1,5 @@
local public = {}
local _global = require("utils.global")
local _global = require('utils.global')
public.init = function()
if global.this == nil then