From 0deb0613855200564247e9bd2baca0ce8480252c Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Tue, 22 Oct 2024 21:51:58 -0700 Subject: [PATCH 1/9] [FACTORIO 2.0] Renamed `global` into `storage`. --- spec/area/chunk_spec.lua | 2 +- spec/area/tile_spec.lua | 2 +- spec/entity/entity_spec.lua | 6 +-- spec/event/force_bak.lua | 86 +++++++++++++++++------------------ spec/event/player_bak.lua | 90 ++++++++++++++++++------------------- spec/game_spec.lua | 6 +-- spec/misc/queue_spec.lua | 14 +++--- stdlib/entity/entity.lua | 22 ++++----- stdlib/event/changes.lua | 8 ++-- stdlib/event/force.lua | 28 ++++++------ stdlib/event/player.lua | 34 +++++++------- stdlib/event/surface.lua | 24 +++++----- stdlib/event/trains.lua | 14 +++--- stdlib/game.lua | 14 +++--- stdlib/misc/config.lua | 14 +++--- stdlib/misc/queue.lua | 8 ++-- 16 files changed, 186 insertions(+), 186 deletions(-) diff --git a/spec/area/chunk_spec.lua b/spec/area/chunk_spec.lua index 15b45481..8047198a 100644 --- a/spec/area/chunk_spec.lua +++ b/spec/area/chunk_spec.lua @@ -20,7 +20,7 @@ describe('Chunk Spec', function() end) it('should verify getting and setting data', function() - _G.global = {} + _G.storage = {} _G.game = { surfaces = { nauvis = { index = 1, __self = 'userdata', valid = true } } } local chunk_pos = { x = 4, y = -6 } diff --git a/spec/area/tile_spec.lua b/spec/area/tile_spec.lua index c0c14831..dfadeeff 100644 --- a/spec/area/tile_spec.lua +++ b/spec/area/tile_spec.lua @@ -34,7 +34,7 @@ describe('Tile Spec', function() end) it('should verify getting and setting data', function() - _G.global = {} + _G.storage = {} _G.game = { surfaces = { nauvis = { index = 1, __self = 'userdata', valid = true } } } local tile_pos = { x = 4, y = -6 } diff --git a/spec/entity/entity_spec.lua b/spec/entity/entity_spec.lua index f4f9d987..0ebf432d 100644 --- a/spec/entity/entity_spec.lua +++ b/spec/entity/entity_spec.lua @@ -53,7 +53,7 @@ describe('Entity', function() end) it('should verify getting and setting data', function() - _G['global'] = {} + _G['storage'] = {} local entity = { name = 'fast-inserter', valid = true } assert.is_nil(Entity.get_data(entity)) @@ -76,7 +76,7 @@ describe('Entity', function() end) it('should verify getting and setting data with unit_numbers', function() - _G['global'] = {} + _G['storage'] = {} local entity = { name = 'fast-inserter', valid = true, unit_number = 13} assert.is_nil(Entity.get_data(entity)) @@ -104,7 +104,7 @@ describe('Entity', function() end) it('should verify data can be deleted', function() - _G['global'] = {} + _G['storage'] = {} local entity = { name = 'fast-inserter', valid = true } assert.is_nil(Entity.get_data(entity)) diff --git a/spec/event/force_bak.lua b/spec/event/force_bak.lua index 7f324f66..7ed87bf6 100644 --- a/spec/event/force_bak.lua +++ b/spec/event/force_bak.lua @@ -27,10 +27,10 @@ describe("Force", end } _G.game = { forces = { } } - _G.global = { forces = { }} + _G.storage = { forces = { }} setmetatable(game.forces, _mt) - setmetatable(global.forces, _mt) + setmetatable(storage.forces, _mt) end ) @@ -60,65 +60,65 @@ describe("Force", it("should load forces into the global object on init", function() - _G.global = {} + _G.storage = {} local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } end require('__stdlib__/stdlib/event/force').register_events() Event.dispatch({name = Event.core_events.init}) - for _, force_name in ipairs(global.forces) do - assert.same(game.forces[force_name].name, global.forces[force_name].name) + for _, force_name in ipairs(storage.forces) do + assert.same(game.forces[force_name].name, storage.forces[force_name].name) end end ) it("should load forces into the global object on configuration changed", function() - _G.global = {} + _G.storage = {} local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } end require('__stdlib__/stdlib/event/force').register_events() Event.dispatch({name = Event.core_events.configuration_changed, test = "TEST"}) - for _, force_name in ipairs(global.forces) do - assert.same(game.forces[force_name].name, global.forces[force_name].name) + for _, force_name in ipairs(storage.forces) do + assert.same(game.forces[force_name].name, storage.forces[force_name].name) end end ) it("should load forces into the global object when forces are created in the game object", function() - _G.global = {} + _G.storage = {} local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } Event.dispatch({name = defines.events.on_force_created}) - assert.same(game.forces[force_name].name, global.forces[force_name].name) + assert.same(game.forces[force_name].name, storage.forces[force_name].name) end end ) - it(".get should retrieve forces from game.forces and global.forces", + it(".get should retrieve forces from game.forces and storage.forces", function() local Force = require('__stdlib__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } - global.forces[force_name] = { index = force_name, name = force_name, data = "Data" .. force_name } + storage.forces[force_name] = { index = force_name, name = force_name, data = "Data" .. force_name } end for _, force_name in ipairs(force_names) do local force_game, force_global = Force.get(force_name) assert.same({index = force_name, name = force_name}, force_game) assert.same({index = force_name, name = force_name, data = "Data" .. force_name}, force_global) - assert.equal(force_game.index, force_global.index) - assert.equal(force_game.name, force_global.name) + assert.equal(force_game.index, force_storage.index) + assert.equal(force_game.name, force_storage.name) end end ) - it(".get should add a force into global.forces if the force is in game.forces but does not exist in global.forces", + it(".get should add a force into storage.forces if the force is in game.forces but does not exist in storage.forces", function() local Force = require('__stdlib__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} @@ -129,41 +129,41 @@ describe("Force", local force_game, force_global = Force.get(force_name) assert.same({index = force_name, name = force_name, valid = true}, force_game) assert.same({index = force_name, name = force_name}, force_global) - assert.equal(force_game.index, force_global.index) - assert.equal(force_game.name, force_global.name) + assert.equal(force_game.index, force_storage.index) + assert.equal(force_game.name, force_storage.name) end end ) - it(".add_data_all should merge a copy of the passed data to all forces in global.forces", + it(".add_data_all should merge a copy of the passed data to all forces in storage.forces", function() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do - global.forces[force_name] = { index = force_name, name = force_name, data = "Data" .. force_name } + storage.forces[force_name] = { index = force_name, name = force_name, data = "Data" .. force_name } end local Force = require('__stdlib__/stdlib/event/force').register_events() local data = {a = "abc", b = "def"} Force.add_data_all(data) for _, force_name in ipairs(force_names) do - assert.equal(data.a, global.forces[force_name].a) - assert.equal(data.b, global.forces[force_name].b) + assert.equal(data.a, storage.forces[force_name].a) + assert.equal(data.b, storage.forces[force_name].b) end end ) - it(".init should initialize global.forces", + it(".init should initialize storage.forces", function() local Force = require('__stdlib__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } end - assert.is_same({}, global.forces) + assert.is_same({}, storage.forces) for _, force_name in ipairs(force_names) do Force.init({index = force_name}) - assert.same({index = force_name, name = game.forces[force_name].name}, global.forces[force_name]) + assert.same({index = force_name, name = game.forces[force_name].name}, storage.forces[force_name]) end - assert.is_equal(#game.forces, #global.forces) + assert.is_equal(#game.forces, #storage.forces) end ) @@ -173,11 +173,11 @@ describe("Force", local force_names = {"ForceOne", "ForceTwo", "ForceThree", "ForceFour"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } - global.forces[force_name] = { index = force_name, name = force_name, data = "Data" .. force_name } + storage.forces[force_name] = { index = force_name, name = force_name, data = "Data" .. force_name } end for i, force_name in ipairs(force_names) do - assert.is_not_nil(global.forces[force_name].data) + assert.is_not_nil(storage.forces[force_name].data) if i == 1 then Force.init(game.forces[force_name], true) @@ -189,50 +189,50 @@ describe("Force", Force.init(force_name, true) end - assert.is_nil(global.forces[force_name].data) - assert.same({index = force_name, name = game.forces[force_name].name}, global.forces[force_name]) + assert.is_nil(storage.forces[force_name].data) + assert.same({index = force_name, name = game.forces[force_name].name}, storage.forces[force_name]) end end ) - it(".init should iterate all game.forces[index] and initialize global.forces[index] when nil is passed", + it(".init should iterate all game.forces[index] and initialize storage.forces[index] when nil is passed", function() local Force = require('__stdlib__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } end - assert.same({}, global.forces) + assert.same({}, storage.forces) Force.init(nil) - assert.equal(#game.forces, #global.forces) + assert.equal(#game.forces, #storage.forces) for _, force_name in ipairs(force_names) do - assert.same({index = game.forces[force_name].index, name = game.forces[force_name].name}, global.forces[force_name]) + assert.same({index = game.forces[force_name].index, name = game.forces[force_name].name}, storage.forces[force_name]) end end ) - it(".init should iterate all game.forces[index] and re-init global.forces[index] when event is nil and overwrite is true", + it(".init should iterate all game.forces[index] and re-init storage.forces[index] when event is nil and overwrite is true", function() local Force = require('__stdlib__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } - global.forces[force_name] = { index = force_name, name = force_name, data = "Data" .. force_name } + storage.forces[force_name] = { index = force_name, name = force_name, data = "Data" .. force_name } end - assert.equal(#game.forces, #global.forces) + assert.equal(#game.forces, #storage.forces) for _, force_name in ipairs(force_names) do - assert.is_not_nil(global.forces[force_name].data) + assert.is_not_nil(storage.forces[force_name].data) end Force.init(nil, true) - assert.equal(#game.forces, #global.forces) + assert.equal(#game.forces, #storage.forces) for _, force_name in ipairs(force_names) do - assert.is_nil(global.forces[force_name].data) - assert.same({index = force_name, name = game.forces[force_name].name}, global.forces[force_name]) + assert.is_nil(storage.forces[force_name].data) + assert.same({index = force_name, name = game.forces[force_name].name}, storage.forces[force_name]) end end ) - it(".init should initialize global.forces for all existing game.forces even if a single game.forces[index] is not a valid force", + it(".init should initialize storage.forces for all existing game.forces even if a single game.forces[index] is not a valid force", --If a force isn"t valid then it won"t add it to global table --Additionally game.forces won"t return invalid forces (TBD) function() @@ -243,8 +243,8 @@ describe("Force", end Force.init({force = "fake"}) for _, force_name in ipairs(force_names) do - assert.is_not_nil(global.forces[force_name]) - assert.same({index = force_name, name = game.forces[force_name].name}, global.forces[force_name]) + assert.is_not_nil(storage.forces[force_name]) + assert.same({index = force_name, name = game.forces[force_name].name}, storage.forces[force_name]) end end ) diff --git a/spec/event/player_bak.lua b/spec/event/player_bak.lua index 32002481..5c57032c 100644 --- a/spec/event/player_bak.lua +++ b/spec/event/player_bak.lua @@ -36,7 +36,7 @@ describe( end } _G.game = {players = {}, connected_players = {}} - _G.global = {players = {}} + _G.storage = {players = {}} setmetatable(game.players, _mt) setmetatable(game.connected_players, _mt) @@ -86,15 +86,15 @@ describe( it( 'should load players into the global object on init', function() - _G.global = {} + _G.storage = {} local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} end require('__stdlib__/stdlib/event/player').register_events() Event.dispatch({name = Event.core_events.init}) - for player_index in ipairs(global.players) do - assert.same(game.players[player_index].name, global.players[player_index].name) + for player_index in ipairs(storage.players) do + assert.same(game.players[player_index].name, storage.players[player_index].name) end end ) @@ -102,15 +102,15 @@ describe( it( 'should load players into the global object on configuration changed', function() - _G.global = {} + _G.storage = {} local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} end require('__stdlib__/stdlib/event/player').register_events() Event.dispatch({name = Event.core_events.configuration_changed, test = 'TEST'}) - for player_index in ipairs(global.players) do - assert.same(game.players[player_index].name, global.players[player_index].name) + for player_index in ipairs(storage.players) do + assert.same(game.players[player_index].name, storage.players[player_index].name) end end ) @@ -118,13 +118,13 @@ describe( it( 'should load players into the global object when players are created in the game object', function() - _G.global = {} + _G.storage = {} require('__stdlib__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} Event.dispatch({name = defines.events.on_player_created}) - assert.same(game.players[player_index].name, global.players[player_index].name) + assert.same(game.players[player_index].name, storage.players[player_index].name) end end ) @@ -135,38 +135,38 @@ describe( local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} - global.players[player_index] = {index = player_index, name = player_name} + storage.players[player_index] = {index = player_index, name = player_name} end - assert.equal(#game.players, #global.players) + assert.equal(#game.players, #storage.players) for player_index in ipairs(player_names) do - assert.same(game.players[player_index].name, global.players[player_index].name) + assert.same(game.players[player_index].name, storage.players[player_index].name) Event.dispatch({name = defines.events.on_player_removed, player_index = player_index}) - assert.is_nil(global.players[player_index]) + assert.is_nil(storage.players[player_index]) end end ) it( - '.get should retrieve player objects from game.players and global.players objects', + '.get should retrieve player objects from game.players and storage.players objects', function() local Player = require('__stdlib__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} - global.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} + storage.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} end for player_index, player_name in ipairs(player_names) do local player_game, player_global = Player.get(player_index) assert.same({index = player_index, name = player_name}, player_game) assert.same({index = player_index, name = player_name, data = 'Data' .. player_index}, player_global) - assert.equal(player_game.player_index, player_global.player_index) - assert.equal(player_game.name, player_global.name) + assert.equal(player_game.player_index, player_storage.player_index) + assert.equal(player_game.name, player_storage.name) end end ) it( - '.get should add a player into global.players if the player is in game.players but does not exist in global.players', + '.get should add a player into storage.players if the player is in game.players but does not exist in storage.players', function() local Player = require('__stdlib__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} @@ -188,14 +188,14 @@ describe( function() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do - global.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} + storage.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} end local Player = require('__stdlib__/stdlib/event/player').register_events() local data = {a = 'abc', b = 'def'} Player.add_data_all(data) for player_index, _ in ipairs(player_names) do - assert.equal(data.a, global.players[player_index].a) - assert.equal(data.b, global.players[player_index].b) + assert.equal(data.a, storage.players[player_index].a) + assert.equal(data.b, storage.players[player_index].b) end end ) @@ -207,11 +207,11 @@ describe( local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} - global.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} + storage.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} end for player_index, _ in ipairs(player_names) do Player.remove({player_index = player_index}) - assert.is_nil(global.players[player_index]) + assert.is_nil(storage.players[player_index]) end end ) @@ -224,13 +224,13 @@ describe( for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} end - assert.is_not_equal(#game.players, #global.players) - assert.is_same({}, global.players) + assert.is_not_equal(#game.players, #storage.players) + assert.is_same({}, storage.players) for player_index, _ in ipairs(player_names) do Player.init({player_index = player_index}) - assert.same({index = player_index, name = game.players[player_index].name}, global.players[player_index]) + assert.same({index = player_index, name = game.players[player_index].name}, storage.players[player_index]) end - assert.is_equal(#game.players, #global.players) + assert.is_equal(#game.players, #storage.players) end ) @@ -241,58 +241,58 @@ describe( local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} - global.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} + storage.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} end for player_index, _ in ipairs(player_names) do - assert.is_not_nil(global.players[player_index].data) + assert.is_not_nil(storage.players[player_index].data) Player.init({player_index = player_index}, true) - assert.is_nil(global.players[player_index].data) - assert.same({index = player_index, name = game.players[player_index].name}, global.players[player_index]) + assert.is_nil(storage.players[player_index].data) + assert.same({index = player_index, name = game.players[player_index].name}, storage.players[player_index]) end end ) it( - '.init should iterate all game.players[index] and initialize global.players[index] when nil is passed', + '.init should iterate all game.players[index] and initialize storage.players[index] when nil is passed', function() local Player = require('__stdlib__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} end - assert.same({}, global.players) + assert.same({}, storage.players) Player.init(nil) - assert.equal(#game.players, #global.players) + assert.equal(#game.players, #storage.players) for player_index, _ in ipairs(player_names) do - assert.same({index = game.players[player_index].index, name = game.players[player_index].name}, global.players[player_index]) + assert.same({index = game.players[player_index].index, name = game.players[player_index].name}, storage.players[player_index]) end end ) it( - '.init should iterate all game.players[index] and re-init global.players[index] when event is nil and overwrite is true', + '.init should iterate all game.players[index] and re-init storage.players[index] when event is nil and overwrite is true', function() local Player = require('__stdlib__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} - global.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} + storage.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} end - assert.equal(#game.players, #global.players) + assert.equal(#game.players, #storage.players) for player_index, _ in ipairs(player_names) do - assert.is_not_nil(global.players[player_index].data) + assert.is_not_nil(storage.players[player_index].data) end Player.init(nil, true) - assert.equal(#game.players, #global.players) + assert.equal(#game.players, #storage.players) for player_index, _ in ipairs(player_names) do - assert.is_nil(global.players[player_index].data) - assert.same({index = player_index, name = game.players[player_index].name}, global.players[player_index]) + assert.is_nil(storage.players[player_index].data) + assert.same({index = player_index, name = game.players[player_index].name}, storage.players[player_index]) end end ) it( - '.init should initialize global.players for all existing game.players even if a single game.players[index] is not a valid player', + '.init should initialize storage.players for all existing game.players even if a single game.players[index] is not a valid player', --If a player isn"t valid then it won"t add it to global table --Additionally game.players won"t return invalid players (TBD) function() @@ -303,8 +303,8 @@ describe( end Player.init({player_index = 4}) for player_index, _ in ipairs(player_names) do - assert.is_not_nil(global.players[player_index]) - assert.same({index = player_index, name = game.players[player_index].name}, global.players[player_index]) + assert.is_not_nil(storage.players[player_index]) + assert.same({index = player_index, name = game.players[player_index].name}, storage.players[player_index]) end end ) diff --git a/spec/game_spec.lua b/spec/game_spec.lua index 2f5c5c81..03289041 100644 --- a/spec/game_spec.lua +++ b/spec/game_spec.lua @@ -21,12 +21,12 @@ describe("Game Spec", end } _G.game = { players = { }, connected_players = { }, forces = { } } - _G.global = { players = { }, forces = { }} + _G.storage = { players = { }, forces = { }} setmetatable(game.players, _mt) - setmetatable(global.players, _mt) + setmetatable(storage.players, _mt) setmetatable(game.forces, _mt) - setmetatable(global.forces, _mt) + setmetatable(storage.forces, _mt) end ) diff --git a/spec/misc/queue_spec.lua b/spec/misc/queue_spec.lua index af13dd81..a6d487cf 100644 --- a/spec/misc/queue_spec.lua +++ b/spec/misc/queue_spec.lua @@ -266,18 +266,18 @@ describe('Queue', function() end) describe('load', function() - _G.global = {} - --Factorio does not save metatables in global so we need to to re-add them on load ourselves + _G.storage = {} + --Factorio does not save metatables in storage so we need to to re-add them on load ourselves it('should re-add the metatatables', function() assert.same(tostring(getmetatable(queue1).__index), tostring(getmetatable(queue2).__index)) setmetatable(queue1, nil) setmetatable(queue2, nil) assert.not_truthy(getmetatable(queue1)) - _G.global.queue1 = queue1 - _G.global.queue2 = queue2 - Queue.load(_G.global.queue1) - Queue.load(_G.global.queue2) - assert.truthy(_G.global.queue1) + _G.storage.queue1 = queue1 + _G.storage.queue2 = queue2 + Queue.load(_G.storage.queue1) + Queue.load(_G.storage.queue2) + assert.truthy(_G.storage.queue1) assert.same(tostring(getmetatable(queue1).__index), tostring(getmetatable(queue2).__index)) end) end) diff --git a/stdlib/entity/entity.lua b/stdlib/entity/entity.lua index 685e8435..c9199f98 100644 --- a/stdlib/entity/entity.lua +++ b/stdlib/entity/entity.lua @@ -32,20 +32,20 @@ end -- @treturn ?|nil|Mixed the user data, or nil if no data exists for the entity function Entity.get_data(entity) assert(entity, 'missing entity argument') - if not global._entity_data then + if not storage._entity_data then return nil end local unit_number = entity.unit_number if unit_number then - return global._entity_data[unit_number] + return storage._entity_data[unit_number] else local entity_name = entity.name - if not global._entity_data[entity_name] then + if not storage._entity_data[entity_name] then return nil end - local entity_category = global._entity_data[entity_name] + local entity_category = storage._entity_data[entity_name] for _, entity_data in pairs(entity_category) do if Entity._are_equal(entity_data.entity, entity) then return entity_data.data @@ -64,22 +64,22 @@ end function Entity.set_data(entity, data) assert(entity, 'missing entity argument') - if not global._entity_data then - global._entity_data = {} + if not storage._entity_data then + storage._entity_data = {} end local unit_number = entity.unit_number if unit_number then - local prev = global._entity_data[unit_number] - global._entity_data[unit_number] = data + local prev = storage._entity_data[unit_number] + storage._entity_data[unit_number] = data return prev else local entity_name = entity.name - if not global._entity_data[entity_name] then - global._entity_data[entity_name] = {} + if not storage._entity_data[entity_name] then + storage._entity_data[entity_name] = {} end - local entity_category = global._entity_data[entity_name] + local entity_category = storage._entity_data[entity_name] for i = #entity_category, 1, -1 do local entity_data = entity_category[i] diff --git a/stdlib/event/changes.lua b/stdlib/event/changes.lua index 97f216c4..8ab2dbfe 100644 --- a/stdlib/event/changes.lua +++ b/stdlib/event/changes.lua @@ -96,7 +96,7 @@ function Changes.on_init() for ver in pairs(versions) do list[ver] = cur_version end - global._changes = list + storage._changes = list end end @@ -117,14 +117,14 @@ function Changes.on_configuration_changed(event) end function Changes.on_mod_changed(this_mod_changes) - global._changes = global._changes or {} + storage._changes = storage._changes or {} local old = this_mod_changes.old_version if old then -- Find the last installed version local versions = {} for _, path in pairs(Changes.mod_versions) do for ver, fun in pairs(path) do - if not global._changes[ver] then + if not storage._changes[ver] then versions[ver] = this_mod_changes.new_version fun() log('Migration completed for version ' .. ver) @@ -134,7 +134,7 @@ function Changes.on_mod_changed(this_mod_changes) table.each( versions, function(v, k) - global._changes[k] = v + storage._changes[k] = v end ) end diff --git a/stdlib/event/force.lua b/stdlib/event/force.lua index e0b6f0eb..b51ed45d 100644 --- a/stdlib/event/force.lua +++ b/stdlib/event/force.lua @@ -1,6 +1,6 @@ --- Force global creation. ---

All new forces will be added to the `global.forces` table. ---

This modules events should be registered after any other Init functions but before any scripts needing `global.players`. +--

All new forces will be added to the `storage.forces` table. +--

This modules events should be registered after any other Init functions but before any scripts needing `storage.players`. --

This modules can register the following events: `on_force_created`, and `on_forces_merging`. -- @module Event.Force -- @usage @@ -44,7 +44,7 @@ function Force.additional_data(...) return Force end ---- Get `game.forces[name]` & `global.forces[name]`, or create `global.forces[name]` if it doesn't exist. +--- Get `game.forces[name]` & `storage.forces[name]`, or create `storage.forces[name]` if it doesn't exist. -- @tparam string|LuaForce force the force to get data for -- @treturn LuaForce the force instance -- @treturn table the force's global data @@ -56,17 +56,17 @@ end function Force.get(force) force = Game.get_force(force) assert(force, 'force is missing') - return game.forces[force.name], global.forces and global.forces[force.name] or Force.init(force.name) + return game.forces[force.name], storage.forces and storage.forces[force.name] or Force.init(force.name) end ---- Merge a copy of the passed data to all forces in `global.forces`. +--- Merge a copy of the passed data to all forces in `storage.forces`. -- @tparam table data a table containing variables to merge -- @usage -- local data = {a = "abc", b = "def"} -- Force.add_data_all(data) function Force.add_data_all(data) table.each( - global.forces, + storage.forces, function(v) table.merge(v, table.deepcopy(data)) end @@ -78,19 +78,19 @@ end -- @tparam[opt] string|table event table or a string containing force name -- @tparam[opt=false] boolean overwrite the force data function Force.init(event, overwrite) - global.forces = global.forces or {} + storage.forces = storage.forces or {} local force = Game.get_force(event) if force then - if not global.forces[force.name] or (global.forces[force.name] and overwrite) then - global.forces[force.name] = new(force.name) - return global.forces[force.name] + if not storage.forces[force.name] or (storage.forces[force.name] and overwrite) then + storage.forces[force.name] = new(force.name) + return storage.forces[force.name] end else for name in pairs(game.forces) do - if not global.forces[name] or (global.forces[name] and overwrite) then - global.forces[name] = new(name) + if not storage.forces[name] or (storage.forces[name] and overwrite) then + storage.forces[name] = new(name) end end end @@ -99,12 +99,12 @@ end function Force.dump_data() game.write_file(Force.get_file_path('Force/force_data.lua'), 'return ' .. inspect(Force._new_force_data, { longkeys = true, arraykeys = true })) - game.write_file(Force.get_file_path('Force/global.lua'), 'return ' .. inspect(global.forces or nil, { longkeys = true, arraykeys = true })) + game.write_file(Force.get_file_path('Force/storage.lua'), 'return ' .. inspect(storage.forces or nil, { longkeys = true, arraykeys = true })) end --- When forces are merged, just remove the original forces data function Force.merged(event) - global.forces[event.source_name] = nil + storage.forces[event.source_name] = nil end function Force.register_init() diff --git a/stdlib/event/player.lua b/stdlib/event/player.lua index 93648f13..a78a6091 100644 --- a/stdlib/event/player.lua +++ b/stdlib/event/player.lua @@ -40,7 +40,7 @@ function Player.additional_data(...) return Player end ---- Get `game.players[index]` & `global.players[index]`, or create `global.players[index]` if it doesn't exist. +--- Get `game.players[index]` & `storage.players[index]`, or create `storage.players[index]` if it doesn't exist. -- @tparam number|string|LuaPlayer player the player index to get data for -- @treturn LuaPlayer the player instance -- @treturn table the player's global data @@ -49,22 +49,22 @@ end -- local player, player_data = Player.get(event.player_index) function Player.get(player) player = Game.get_player(player) - return player, global.players and global.players[player.index] or Player.init(player.index) + return player, storage.players and storage.players[player.index] or Player.init(player.index) end --- Get the players saved data table. Creates it if it doesn't exsist. -- @tparam number index The player index to get data for -- @treturn table the player's global data function Player.pdata(index) - return global.players and global.players[index] or Player.init(index) + return storage.players and storage.players[index] or Player.init(index) end ---- Merge a copy of the passed data to all players in `global.players`. +--- Merge a copy of the passed data to all players in `storage.players`. -- @tparam table data a table containing variables to merge -- @usage local data = {a = 'abc', b = 'def'} -- Player.add_data_all(data) function Player.add_data_all(data) - local pdata = global.players + local pdata = storage.players table.each( pdata, function(v) @@ -76,7 +76,7 @@ end --- Remove data for a player when they are deleted. -- @tparam table event event table containing the `player_index` function Player.remove(event) - global.players[event.player_index] = nil + storage.players[event.player_index] = nil end --- Init or re-init a player or players. @@ -84,33 +84,33 @@ end -- @tparam[opt] number|table|string|LuaPlayer event -- @tparam[opt=false] boolean overwrite the player data function Player.init(event, overwrite) - -- Create the global.players table if it doesn't exisit - global.players = global.players or {} + -- Create the storage.players table if it doesn't exisit + storage.players = storage.players or {} --get a valid player object or nil local player = Game.get_player(event) if player then --If player is not nil then we are working with a valid player. - if not global.players[player.index] or (global.players[player.index] and overwrite) then - global.players[player.index] = new(player.index) - return global.players[player.index] + if not storage.players[player.index] or (storage.players[player.index] and overwrite) then + storage.players[player.index] = new(player.index) + return storage.players[player.index] end else --Check all players for index in pairs(game.players) do - if not global.players[index] or (global.players[index] and overwrite) then - global.players[index] = new(index) + if not storage.players[index] or (storage.players[index] and overwrite) then + storage.players[index] = new(index) end end end - if global._print_queue then + if storage._print_queue then table.each( - global._print_queue, + storage._print_queue, function(msg) game.print(tostring(msg)) end ) - global._print_queue = nil + storage._print_queue = nil end return Player end @@ -122,7 +122,7 @@ end function Player.dump_data() game.write_file(Player.get_file_path('Player/player_data.lua'), 'return ' .. inspect(Player._new_player_data, { longkeys = true, arraykeys = true })) - game.write_file(Player.get_file_path('Player/global.lua'), 'return ' .. inspect(global.players or nil, { longkeys = true, arraykeys = true })) + game.write_file(Player.get_file_path('Player/storage.lua'), 'return ' .. inspect(storage.players or nil, { longkeys = true, arraykeys = true })) end function Player.register_init() diff --git a/stdlib/event/surface.lua b/stdlib/event/surface.lua index 4e67a84d..4cef2de0 100644 --- a/stdlib/event/surface.lua +++ b/stdlib/event/surface.lua @@ -1,6 +1,6 @@ --- Surface global creation. ---

All surfaces will be added to the `global.surfaces` table. ---

This modules events should be registered after any other Init functions but before any scripts needing `global.surfaces`. +--

All surfaces will be added to the `storage.surfaces` table. +--

This modules events should be registered after any other Init functions but before any scripts needing `storage.surfaces`. --

This modules can register the following events: -- @module Event.Surface -- @usage @@ -40,11 +40,11 @@ end --- Remove data for a surface when it is deleted. -- @tparam table event event table containing the surface index function Surface.remove(event) - global.surfaces[event.surface_index] = nil + storage.surfaces[event.surface_index] = nil end function Surface.rename(event) - global.surfaces[event.surface_index].name = event.new_name + storage.surfaces[event.surface_index].name = event.new_name end function Surface.import(event) @@ -59,21 +59,21 @@ end -- @tparam[opt] number|table|string|LuaSurface event -- @tparam[opt=false] boolean overwrite the surface data function Surface.init(event, overwrite) - -- Create the global.surfaces table if it doesn't exisit - global.surfaces = global.surfaces or {} + -- Create the storage.surfaces table if it doesn't exisit + storage.surfaces = storage.surfaces or {} --get a valid surface object or nil local surface = game.surfaces[event.surface_index] if surface then - if not global.surfaces[surface.index] or (global.surfaces[surface.index] and overwrite) then - global.surfaces[surface.index] = new(surface.index) - return global.surfaces[surface.index] + if not storage.surfaces[surface.index] or (storage.surfaces[surface.index] and overwrite) then + storage.surfaces[surface.index] = new(surface.index) + return storage.surfaces[surface.index] end else --Check all surfaces for index in pairs(game.surfaces) do - if not global.surfaces[index] or (global.surfaces[index] and overwrite) then - global.surfaces[index] = new(index) + if not storage.surfaces[index] or (storage.surfaces[index] and overwrite) then + storage.surfaces[index] = new(index) end end end @@ -82,7 +82,7 @@ end function Surface.dump_data() game.write_file(Surface.get_file_path('Surface/surface_data.lua'), inspect(Surface._new_surface_data, { longkeys = true, arraykeys = true })) - game.write_file(Surface.get_file_path('Surface/global.lua'), inspect(global.surfaces or nil, { longkeys = true, arraykeys = true })) + game.write_file(Surface.get_file_path('Surface/global.lua'), inspect(storage.surfaces or nil, { longkeys = true, arraykeys = true })) end function Surface.register_init() diff --git a/stdlib/event/trains.lua b/stdlib/event/trains.lua index 3623eaf4..77b505a1 100644 --- a/stdlib/event/trains.lua +++ b/stdlib/event/trains.lua @@ -101,7 +101,7 @@ end function Trains._on_locomotive_changed() -- For all the known trains local renames = {} - for id, train in pairs(global._train_registry) do + for id, train in pairs(storage._train_registry) do -- Check if their known ID is the same as the LuaTrain's dervied id local derived_id = Trains.get_train_id(train) -- If it's not @@ -115,8 +115,8 @@ function Trains._on_locomotive_changed() for _, renaming in pairs(renames) do -- Rename it in the registry -- and dispatch a renamed event - global._train_registry[renaming.new_id] = renaming.train - global._train_registry[renaming.old_id] = nil + storage._train_registry[renaming.new_id] = renaming.train + storage._train_registry[renaming.old_id] = nil local event_data = { old_id = renaming.old_id, @@ -181,19 +181,19 @@ end -- Creates a registry of known trains. -- @return table a mapping of train id to LuaTrain object function Trains.create_train_registry() - global._train_registry = global._train_registry or {} + storage._train_registry = storage._train_registry or {} local all_trains = Trains.find_filtered() for _, trainInfo in pairs(all_trains) do - global._train_registry[tonumber(trainInfo.id)] = trainInfo.train + storage._train_registry[tonumber(trainInfo.id)] = trainInfo.train end - return global._train_registry + return storage._train_registry end function Trains.on_train_created(event) local train_id = Trains.get_train_id(event.train) - global._train_registry[train_id] = event.train + storage._train_registry[train_id] = event.train end --- This needs to be called to register events for this module diff --git a/stdlib/game.lua b/stdlib/game.lua index 49014bce..3f04f5d5 100644 --- a/stdlib/game.lua +++ b/stdlib/game.lua @@ -55,7 +55,7 @@ end --- Messages all players currently connected to the game. --> Offline players are not counted as having received the message. --- If no players exist msg is stored in the `global._print_queue` table. +-- If no players exist msg is stored in the `storage._print_queue` table. -- @tparam string msg the message to send to players -- @tparam[opt] ?|nil|boolean condition the condition to be true for a player to be messaged -- @treturn uint the number of players who received the message. @@ -70,8 +70,8 @@ function Game.print_all(msg, condition) end return num else - global._print_queue = global._print_queue or {} - global._print_queue[#global._print_queue + 1] = msg + storage._print_queue = storage._print_queue or {} + storage._print_queue[#storage._print_queue + 1] = msg end end @@ -84,13 +84,13 @@ end -- @treturn mixed the chunk value stored at the key or the previous value function Game.get_or_set_data(sub_table, index, key, set, value) assert(type(sub_table) == 'string', 'sub_table must be a string') - global[sub_table] = global[sub_table] or {} + storage[sub_table] = storage[sub_table] or {} local this if index then - global[sub_table][index] = global[sub_table][index] or {} - this = global[sub_table][index] + storage[sub_table][index] = storage[sub_table][index] or {} + this = storage[sub_table][index] else - this = global[sub_table] + this = storage[sub_table] end local previous diff --git a/stdlib/misc/config.lua b/stdlib/misc/config.lua index da0d384b..ba823b3e 100644 --- a/stdlib/misc/config.lua +++ b/stdlib/misc/config.lua @@ -35,30 +35,30 @@ end -- @tparam table config_table the config table to manage -- @treturn Config the Config object to manage the config table -- --- @usage --[Use a global table for config that persists across game save/loads] --- CONFIG = Config.new(global.testtable) +-- @usage --[Use a storage table for config that persists across game save/loads] +-- CONFIG = Config.new(storage.testtable) -- -- @usage --[You can also create a temporary scratch pad config] -- CONFIG = Config.new({}) -- Temporary scratch pad -- -- @usage --[Setting data in Config] --- CONFIG = Config.new(global.testtable) +-- CONFIG = Config.new(storage.testtable) -- CONFIG.set("your.path.here", "myvalue") -- -- @usage --[Getting data out of Config] --- CONFIG = Config.new(global.testtable) +-- CONFIG = Config.new(storage.testtable) -- my_data = CONFIG.get("your.path.here") -- -- @usage --[Getting data out of Config with a default to use if path is not found in Config] --- CONFIG = Config.new(global.testtable) +-- CONFIG = Config.new(storage.testtable) -- my_data = CONFIG.get("your.path.here", "Your Default here") -- -- @usage --[Deleting a path from Config] --- CONFIG = Config.new(global.testtable) +-- CONFIG = Config.new(storage.testtable) -- CONFIG.delete("your.path.here") -- -- @usage --[Checking if a path exists in Config] --- CONFIG = Config.new(global.testtable) +-- CONFIG = Config.new(storage.testtable) -- CONFIG.is_set("your.path.here") function M.new(config_table) if not config_table then diff --git a/stdlib/misc/queue.lua b/stdlib/misc/queue.lua index fe3f1da3..c6c256d9 100644 --- a/stdlib/misc/queue.lua +++ b/stdlib/misc/queue.lua @@ -37,11 +37,11 @@ function Queue.new(...) return Queue.__call(nil, ...) end ---- Load global.queue or queues during on_load, as metatables are not persisted. ---

This is only needed if you are using the queue as an object and storing it in global. +--- Load storage.queue or queues during on_load, as metatables are not persisted. +--

This is only needed if you are using the queue as an object and storing it in storage. -- @tparam table queue (@{Queue},...) --- @usage global.myqueue1 = Queue.new() --- script.on_load(function() Queue.load(global.myqueue)) +-- @usage storage.myqueue1 = Queue.new() +-- script.on_load(function() Queue.load(storage.myqueue)) function Queue.load(queue) if type(queue) == 'table' and queue.first then return setmetatable(queue, meta) From 0fcbe67bb9afab6f25130b0218e64d608c7decac Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Tue, 22 Oct 2024 21:53:52 -0700 Subject: [PATCH 2/9] [FACTORIO 2.0] Added 8 new directions into defines.direction. If mods are storing any direction values in their storage, they will need to migrate them by multiplying by 2. --- stdlib/area/direction.lua | 10 +++++----- stdlib/area/orientation.lua | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/stdlib/area/direction.lua b/stdlib/area/direction.lua index ab485e3e..3da2078e 100644 --- a/stdlib/area/direction.lua +++ b/stdlib/area/direction.lua @@ -31,7 +31,7 @@ Direction.southwest = defines.direction.southwest -- @tparam defines.direction direction the direction -- @treturn defines.direction the opposite direction function Direction.opposite(direction) - return (direction + 4) % 8 + return (direction + 8) % 16 end --- Returns the next direction. @@ -40,7 +40,7 @@ end -- @tparam[opt=false] boolean eight_way true to get the next direction in 8-way (note: not many prototypes support 8-way) -- @treturn defines.direction the next direction function Direction.next(direction, eight_way) - return (direction + (eight_way and 1 or 2)) % 8 + return (direction + (eight_way and 2 or 4)) % 16 end --- Returns the previous direction. @@ -49,14 +49,14 @@ end -- @tparam[opt=false] boolean eight_way true to get the previous direction in 8-way (note: not many prototypes support 8-way) -- @treturn defines.direction the next direction function Direction.previous(direction, eight_way) - return (direction + (eight_way and -1 or -2)) % 8 + return (direction + (eight_way and -2 or -4)) % 16 end --- Returns an orientation from a direction. -- @tparam defines.direction direction -- @treturn float function Direction.to_orientation(direction) - return direction / 8 + return direction / 16 end --- Returns a vector from a direction. @@ -101,7 +101,7 @@ do end function Direction.next_direction(direction, reverse, eight_way) - return (direction + (eight_way and ((reverse and -1) or 1) or ((reverse and -2) or 2))) % 8 + return (direction + (eight_way and ((reverse and -2) or 2) or ((reverse and -4) or 4))) % 16 end end diff --git a/stdlib/area/orientation.lua b/stdlib/area/orientation.lua index cdea9bcf..d97cc300 100644 --- a/stdlib/area/orientation.lua +++ b/stdlib/area/orientation.lua @@ -9,21 +9,21 @@ local Orientation = { setmetatable(Orientation, Orientation) --- north orientation -Orientation.north = defines.direction.north / 8 +Orientation.north = defines.direction.north / 16 --- east orientation -Orientation.east = defines.direction.east / 8 +Orientation.east = defines.direction.east / 16 --- west orientation -Orientation.west = defines.direction.west / 8 +Orientation.west = defines.direction.west / 16 --- south orientation -Orientation.south = defines.direction.south / 8 +Orientation.south = defines.direction.south / 16 --- northeast orientation -Orientation.northeast = defines.direction.northeast / 8 +Orientation.northeast = defines.direction.northeast / 16 --- northwest orientation -Orientation.northwest = defines.direction.northwest / 8 +Orientation.northwest = defines.direction.northwest / 16 --- southeast orientation -Orientation.southeast = defines.direction.southeast / 8 +Orientation.southeast = defines.direction.southeast / 16 --- southwest orientation -Orientation.southwest = defines.direction.southwest / 8 +Orientation.southwest = defines.direction.southwest / 16 local floor = math.floor @@ -32,8 +32,8 @@ local floor = math.floor -- @tparam[opt=false] boolean eight_way -- @treturn defines.direction function Orientation.to_direction(orientation, eight_way) - local ways = eight_way and 8 or 4 - local mod = eight_way and 1 or 2 + local ways = eight_way and 16 or 8 + local mod = eight_way and 2 or 4 return floor(orientation * ways + 0.5) % ways * mod end From 070cdd776348669d46938d3e5069205fc4ca67ce Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Tue, 22 Oct 2024 21:59:30 -0700 Subject: [PATCH 3/9] [FACTORIO 2.0] Fixes event handler registration 2.0 no longer allows assigning values to non-event handlers (1.1 tolerated it, 2.0 throws an error). --- stdlib/event/event.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/stdlib/event/event.lua b/stdlib/event/event.lua index e9d3c213..0a4bdcb1 100644 --- a/stdlib/event/event.lua +++ b/stdlib/event/event.lua @@ -51,7 +51,7 @@ Event.script = { on_load = script.on_load, on_configuration_changed = script.on_configuration_changed, generate_event_name = script.generate_event_name, - get_event_handler = script.get_event_handler + get_event_handler = script.get_event_handler, } local Type = require('__stdlib__/stdlib/utils/type') @@ -66,11 +66,6 @@ if not config.skip_script_protections then -- Protections for post and pre regis error('Detected attempt to add the STDLIB event module after using script.on_event') end end - for name in pairs(Event.script) do - _G.script[name] = function() - error('Detected attempt to register an event using script.' .. name .. ' while using the STDLIB event system ') - end - end end local bootstrap_events = { From 120ff23ec4ea297db025bcec72ae22fe621d4f16 Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Tue, 22 Oct 2024 22:08:50 -0700 Subject: [PATCH 4/9] [FACTORIO 2.0] Moved prototypes access from LuaGameScript::X_prototypes to LuaPrototypes::X. --- stdlib/scripts/quickstart.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/scripts/quickstart.lua b/stdlib/scripts/quickstart.lua index eb762bf8..691c4411 100644 --- a/stdlib/scripts/quickstart.lua +++ b/stdlib/scripts/quickstart.lua @@ -81,13 +81,13 @@ function quickstart.on_player_created(event) end local power_armor = QS.get('power_armor', 'fake') - if player.character and game.item_prototypes[power_armor] then + if player.character and prototypes.item[power_armor] then --Put on power armor, install equipment player.get_inventory(defines.inventory.character_armor).insert(power_armor) local grid = player.character.grid if grid then for _, eq in pairs(QS.get('equipment', { 'fusion-reactor-equipment' })) do - if game.equipment_prototypes[eq] then + if prototypes.equipment[eq] then grid.put { name = eq } end end @@ -219,11 +219,11 @@ function quickstart.on_player_created(event) end if QS.get('setup_power', false) then - if game.entity_prototypes['debug-energy-interface'] then + if prototypes.entity['debug-energy-interface'] then local es = surface.create_entity { name = 'debug-energy-interface', position = { 0, 0 }, force = force, raise_built = true } es.destructible = false end - if game.entity_prototypes['debug-substation'] then + if prototypes.entity['debug-substation'] then local sb = surface.create_entity { name = 'debug-substation', position = { 0, 0 }, force = force, raise_built = true } sb.destructible = false end From 41c44bacabc75000e5f5071f3d3a4aa3f6a97f5a Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Tue, 22 Oct 2024 22:09:20 -0700 Subject: [PATCH 5/9] update info.json for 2.0 --- changelog.txt | 3 ++- info.json | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/changelog.txt b/changelog.txt index 82e63f70..81a706df 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,7 +1,8 @@ --------------------------------------------------------------------------------------------------- -Version: 1.4.9 +Version: 2.0.0 Date: ???? Changes: + - Factorio 2.0 compatible --------------------------------------------------------------------------------------------------- Version: 1.4.8 Date: 2022-11-27 diff --git a/info.json b/info.json index dd6c11a8..16f3cf16 100644 --- a/info.json +++ b/info.json @@ -1,12 +1,12 @@ { "name": "stdlib", - "version": "1.4.9", - "factorio_version": "1.1", + "version": "2.0.0", + "factorio_version": "2.0", "title": "Factorio Standard Library", "author": "Afforess", "contact": "", "dependencies": [ - "base >= 1.1.0" + "base >= 2.0.0" ], "homepage": "https://github.com/Afforess/Factorio-Stdlib", "description": "The Factorio Standard Library is a project to bring Factorio modders high-quality, commonly-required utilities and tools.", From a30291039bd273fed37488792e63a57662278c66 Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Tue, 29 Oct 2024 10:26:48 -0700 Subject: [PATCH 6/9] comment changes --- stdlib/area/position.lua | 6 +- stdlib/utils/color.lua | 18 ++-- stdlib/utils/is.lua | 175 ++++++++++++++++++--------------------- 3 files changed, 92 insertions(+), 107 deletions(-) diff --git a/stdlib/area/position.lua b/stdlib/area/position.lua index f6a3468f..dcd2423f 100644 --- a/stdlib/area/position.lua +++ b/stdlib/area/position.lua @@ -47,9 +47,9 @@ local function new(x, y) end --- Returns a correctly formated position object. --- @usage Position.new({0, 0}) -- returns {x = 0, y = 0} --- @tparam Concepts.Position pos the position table or array to convert --- @treturn Concepts.Position +---@usage Position.new({0, 0}) -- returns {x = 0, y = 0} +---@param pos Concepts.Position pos the position table or array to convert +---@return Concepts.Position function Position.new(pos) return new(pos.x or pos[1] or 0, pos.y or pos[2] or 0) end diff --git a/stdlib/utils/color.lua b/stdlib/utils/color.lua index 5df051f2..68712ec7 100644 --- a/stdlib/utils/color.lua +++ b/stdlib/utils/color.lua @@ -13,11 +13,11 @@ local table = require('__stdlib__/stdlib/utils/table') local math = require('__stdlib__/stdlib/utils/math') local color_list = require('__stdlib__/stdlib/utils/defines/color_list') ---- @table color @{defines.color} +---@table color @{defines.color} Color.color = require('__stdlib__/stdlib/utils/defines/color') ---- @table anticolor @{defines.anticolor} +---@table anticolor @{defines.anticolor} Color.anticolor = require('__stdlib__/stdlib/utils/defines/anticolor') ---- @table lightcolor @{defines.lightcolor} +---@table lightcolor @{defines.lightcolor} Color.lightcolor = require('__stdlib__/stdlib/utils/defines/lightcolor') --- Color Constructors @@ -116,7 +116,7 @@ function Color.from_params(r, g, b, a) local new = Color.normalize { r = r, g = g or r, b = b or r, a = a or 0.5 } return setmetatable(new, metatable) end ---- @see Color.from_params +---@see Color.from_params Color.from_rgb = Color.from_params --- Converts a color in the array format to a color in the table format. @@ -159,7 +159,7 @@ function Color.from_hex(color, alpha) return setmetatable(new, metatable) end ---- @section end +---@section end --- Color Methods -- @section Color Methods @@ -284,7 +284,7 @@ function Color.unary(color) return Color.len(color) < 1.5 and Color.white() or Color.black() end ---- @section end +---@section end --- Color Functions -- @section Color Functions @@ -342,7 +342,7 @@ function Color.to_array(color) return { color.r, color.g, color.b, color.a } end ---- @see Color.to_array +---@see Color.to_array Color.pack = Color.to_array --- Return the color as 4 paramaters. @@ -355,7 +355,7 @@ function Color.to_params(color) return color.r, color.g, color.b, color.a end ---- @see Color.to_params +---@see Color.to_params Color.unpack = Color.to_params --- Return the Color as a string. @@ -418,7 +418,7 @@ function Color.best_color_match(color) return closest end ---- @section end +---@section end metatable = { __class = 'color', diff --git a/stdlib/utils/is.lua b/stdlib/utils/is.lua index 08c225fa..8b765ff9 100644 --- a/stdlib/utils/is.lua +++ b/stdlib/utils/is.lua @@ -1,6 +1,4 @@ --- Is expression library --- @module Utils.Is --- @usage -- local Is = require('__stdlib__/stdlib/utils/is') -- Is.True(true) -- Is.Not.True(false) @@ -8,43 +6,24 @@ -- Is.Assert.Not.True(false) --- Is Table --- @section Table --- Is the test true. --- @table Is --- @field Not Is the test not true. --- @field Assert Assert that the test is true. --- @field Assert.Not Assert that the test is not true. --- Is Table Callers --- @section Callers --- Is the test truthy --- @function Is --- @tparam mixed var --- @treturn boolean local Is = {} --- Is the test not truthy --- @function Not --- @tparam mixed var --- @treturn boolean Is.Not = {} --- Assert that the test is Truthy --- @function Assert --- @tparam mixed var --- @treturn boolean Is.Assert = {} --- Assert that the test is not Truthy --- @function Assert.Not --- @tparam mixed var --- @treturn boolean Is.Assert.Not = {} --- Functions --- @section Functions local M = {} @@ -53,90 +32,94 @@ local floor = math.floor local huge = math.huge --- Returns the var if the passed variable is a table. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return table? function M.Table(var) return type(var) == 'table' and var end M.table = M.Table --- Returns the var if the passed variable is a string. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return string? function M.String(var) return type(var) == 'string' and var end M.string = M.String --- Returns the var if the passed variable is a number. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return number? function M.Number(var) return type(var) == 'number' and var end M.number = M.Number +---@param var any? The variable to check +---@return thread? function M.Thread(var) return type(var) == 'thread' and var end M.thread = M.Thread +---@param var any? The variable to check +---@return userdata? function M.Userdata(var) return type(var) == 'userdata' and var end M.userdata = M.Userdata --- Returns true if the passed variable is nil. --- @tparam mixed var The variable to check --- @treturn boolean +---@param var any? The variable to check +---@return boolean function M.Nil(var) return type(var) == 'nil' end M.is_nil = M.Nil --- Returns true if the passed variable is a boolean. --- @tparam mixed var The variable to check --- @treturn boolean +---@param var any? The variable to check +---@return boolean function M.Boolean(var) return type(var) == 'boolean' end M.boolean = M.boolean --- Returns true if the passed variable is true --- @tparam mixed var The variable to check --- @treturn boolean +---@param var any? The variable to check +---@return boolean function M.True(var) return var == true end M.is_true = M.True --- Returns the var if the passed variable is not nil or false. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return any function M.Truthy(var) return var or false end M.truthy = M.Truthy --- Returns true if the passed variable is false. --- @tparam mixed var The variable to check --- @treturn boolean +---@param var any? The variable to check +---@return boolean function M.False(var) return var == false end M.is_false = M.False --- Returns true if the passed variable is false or nil. --- @tparam mixed var The variable to check --- @treturn boolean +---@param var any? The variable to check +---@return boolean function M.Falsy(var) return not var end M.falsy = M.Falsy --- Returns true if the passed variable is nil, an empty table, or an empty string. --- @tparam mixed var The variable to check --- @treturn boolean +---@param var any? The variable to check +---@return boolean function M.Empty(var) if M.Table(var) then return table_size and table_size(var) == 0 or next(var) == nil @@ -147,164 +130,166 @@ function M.Empty(var) end M.empty = M.Empty +---@param var any? The variable to check +---@return boolean function M.None(var) return M.Empty(var) or M.False(var) or var == 0 or var ~= var end M.none = M.None --- Returns the passed var if it is positive. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return number? function M.Positive(var) return M.Number(var) and var >= 0 and var end M.positive = M.Positive --- Returns the passed var if it is odd. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return number? function M.odd(var) return M.number(var) and (var % 2 ~= 0) and var end --- Returns the passed var if it is even. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return number? function M.even(var) return M.number(var) and (var % 2 == 0) and var end --- Returns the passed var if it is negative. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return number? function M.Negative(var) return M.Number(var) and var < 0 and var end M.negative = M.Negative --- Returns the passed var if it is not a number. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return boolean function M.NaN(var) return var ~= var end M.nan = M.NaN --- Returns the passed var if it is finite. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return number? function M.Finite(var) return M.Number(var) and (var < huge and var > -huge) and var end M.finite = M.Finite --- Returns the passed var if it is an int. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return integer? function M.Int(var) return M.Finite(var) and rawequal(floor(var), var) and var end M.int = M.Int --- Returns the passed var if it is an int8. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return int8? function M.Int8(var) return M.Int(var) and var >= -128 and var <= 127 and var end M.int8 = M.Int8 --- Returns the passed var if it is an int16. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return int16? function M.Int16(var) return M.Int(var) and var >= -32768 and var <= 32767 and var end M.int16 = M.Int16 --- Returns the passed var if it is an int32. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return int32? function M.Int32(var) return M.Int(var) and var >= -2147483648 and var <= 2147483647 and var end M.int32 = M.Int32 --- Returns the passed var if it is an unsigned int. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return uint? function M.Unsigned(var) return Is.Number(var) and (var < huge and var >= 0) and var end M.unsigned = M.Unsigned --- Returns the passed var if it is an unsigned int. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return uint? function M.UInt(var) return M.Unsigned(var) and rawequal(floor(var), var) and var end M.uint = M.UInt --- Returns the passed var if it is an unsigned int8. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return uint8? function M.UInt8(var) return M.UInt(var) and var <= 255 and var end M.uint8 = M.UInt8 --- Returns the passed var if it is an unsigned int16. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return uint16? function M.UInt16(var) return M.UInt(var) and var <= 65535 and var end M.uint16 = M.UInt16 --- Returns the passed var if it is an unsigned int32. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return uint32? function M.UInt32(var) return M.UInt(var) and var <= 4294967295 and var end M.uint32 = M.UInt32 --- Returns the passed var if it is a float. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return float? function M.Float(var) return M.number(var) and var >= 0 and var < 1 and var end M.float = M.Float --- Returns the passed var if it is a full position. --- @tparam mixed var The variable to check --- @treturn mixed +---@param var any? The variable to check +---@return Area.Position? function M.Position(var) return M.Table(var) and (var.x and var.y) and var end M.position = M.Position --- Returns the passed var if it is a full area. --- @tparam mixed var The variable to check --- @treturn mixed +---@tparam mixed var The variable to check +---@treturn mixed function M.Area(var) return M.Table(var) and (M.Position(var.left_top) and M.Position(var.right_bottom)) and var end M.area = M.Area --- Returns the passed var if it is a simple position/vector. --- @tparam mixed var The variable to check --- @treturn mixed +---@tparam mixed var The variable to check +---@treturn mixed function M.Vector(var) return M.Table(var) and ((M.Number(var[1]) and M.Number(var[2])) or M.Position(var)) and var end M.vector = M.Vector --- Returns the passed var if it is a simple area/boundingbox. --- @tparam mixed var The variable to check --- @treturn mixed +---@tparam mixed var The variable to check +---@treturn mixed function M.BoundingBox(var) return M.Table(var) and (M.Vector(var[1]) and M.Vector(var[2])) end @@ -313,8 +298,8 @@ M.bounding_box = M.BoundingBox M.Bounding_Box = M.BoundingBox --- Returns the hex value of the passed var if it is hexadecimal. --- @tparam mixed var The variable to check --- @treturn mixed +---@tparam mixed var The variable to check +---@treturn mixed function M.Hex(var) return M.String(var) and var:match('%x%x%x%x%x%x$') end @@ -322,8 +307,8 @@ M.hex = M.Hex --- Returns true if the passed variable is a single alphbetical word. -- Does not allow any special chars --- @tparam mixed var The variable to check --- @treturn boolean true if the passed variable is a single alphbetical word +---@tparam mixed var The variable to check +---@treturn boolean true if the passed variable is a single alphbetical word function M.StrictWord(var) return M.String(var) and var:find('^[%a]+$') == 1 end @@ -331,8 +316,8 @@ M.strict_word = M.StrictWord --- Returns true if the passed variable is a single alphbetical word. -- Allows _ and - as part of the word --- @tparam mixed var The variable to check --- @treturn boolean true if the passed variable is a single alphbetical word +---@tparam mixed var The variable to check +---@treturn boolean true if the passed variable is a single alphbetical word function M.AlphabetWord(var) return M.String(var) and var:find('^[%a%_%-]+$') == 1 end @@ -340,8 +325,8 @@ M.Word = M.AlphabetWord --- Returns true if the passed variable is a single alphbetical word. -- Must start with a letter, allows _ and - as part of the word --- @tparam mixed var The variable to check --- @treturn boolean true if the passed variable is a single alphbetical word +---@tparam mixed var The variable to check +---@treturn boolean true if the passed variable is a single alphbetical word function M.AlphanumWord(var) return M.String(var) and var:find('^%a+[%w%_%-]*$') == 1 end @@ -350,24 +335,24 @@ M.alpha = M.AlphanumWord M.alphanumword = M.AlphanumWord --- Is this a factorio object --- @tparam LuaObject var The variable to check --- @treturn mixed the var if this is an LuaObject +---@tparam LuaObject var The variable to check +---@treturn mixed the var if this is an LuaObject function M.Object(var) return M.Table(var) and var.__self and var end M.object = M.Object --- Is this factorio object valid --- @tparam LuaObject var The variable to check --- @treturn mixed the var if this is a valid LuaObject +---@tparam LuaObject var The variable to check +---@treturn mixed the var if this is a valid LuaObject function M.Valid(var) return M.Object(var) and var.valid and var end M.valid = M.Valid --- Returns true if the passed variable is a callable function. --- @tparam mixed var The variable to check --- @treturn boolean true if the passed variable is a callable function +---@tparam mixed var The variable to check +---@treturn boolean true if the passed variable is a callable function function M.Callable(var) return type(var) == 'function' or type((getmetatable(var) or {}).__call) == 'function' end From abf36b87734f31d90cdfb2300d91283eed31afee Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Tue, 29 Oct 2024 10:27:02 -0700 Subject: [PATCH 7/9] logger fix --- stdlib/misc/logger.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/misc/logger.lua b/stdlib/misc/logger.lua index cb07c047..d28374d5 100644 --- a/stdlib/misc/logger.lua +++ b/stdlib/misc/logger.lua @@ -138,7 +138,7 @@ function Logger.new(log_name, debug_mode, options) function Log.write() if _G.game and table.size(Log.buffer) > 0 then Log.last_written = game.tick - game.write_file(Log.file_name, table.concat(Log.buffer), Log.ever_written) + helpers.write_file(Log.file_name, table.concat(Log.buffer), Log.ever_written) Log.buffer = {} Log.ever_written = true end From 03e76db86516f3dff541dd93c1c348c524cb0b9d Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Wed, 30 Oct 2024 10:07:50 -0700 Subject: [PATCH 8/9] Factorio object definition has changed from the 2.0.7 changelog: * Type of LuaObjects is now "userdata" instead of "table". * Removed __self from the LuaObjects. Intended way of checking if an object is a lua object is to check type is userdata. Without this change, e.g. Is.Valid does not work. --- stdlib/utils/is.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/utils/is.lua b/stdlib/utils/is.lua index 8b765ff9..25302d53 100644 --- a/stdlib/utils/is.lua +++ b/stdlib/utils/is.lua @@ -338,7 +338,7 @@ M.alphanumword = M.AlphanumWord ---@tparam LuaObject var The variable to check ---@treturn mixed the var if this is an LuaObject function M.Object(var) - return M.Table(var) and var.__self and var + return M.Userdata(var) and var end M.object = M.Object From 6c58af5cb09187f73328b5e82b1b3ec546852840 Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Wed, 30 Oct 2024 10:16:27 -0700 Subject: [PATCH 9/9] rename to stdlib2 --- doc/examples/event.lua | 2 +- info.json | 8 ++--- spec/area/area_spec.lua | 4 +-- spec/area/chunk_spec.lua | 2 +- spec/area/direction_spec.lua | 2 +- spec/area/position_spec.lua | 2 +- spec/area/surface_spec.lua | 2 +- spec/area/tile_spec.lua | 2 +- spec/core_spec.lua | 2 +- spec/data/data_spec.lua | 2 +- spec/data/recipe_spec.lua | 4 +-- spec/data/technology_spec.lua | 2 +- spec/entity/entity_spec.lua | 2 +- spec/entity/inventory_spec.lua | 4 +-- spec/entity/resource_spec.lua | 6 ++-- spec/event/event_spec.lua | 42 ++++++++++++------------ spec/event/force_bak.lua | 28 ++++++++-------- spec/event/gui_spec.lua | 4 +-- spec/event/player_bak.lua | 34 +++++++++---------- spec/game_spec.lua | 4 +-- spec/misc/config_spec.lua | 4 +-- spec/misc/logger_spec.lua | 2 +- spec/misc/queue_spec.lua | 4 +-- spec/utils/classes/linked_list_spec.lua | 2 +- spec/utils/classes/unique_array_spec.lua | 2 +- spec/utils/is_spec.lua | 2 +- spec/utils/math_spec.lua | 2 +- spec/utils/string_spec.lua | 2 +- spec/utils/table_spec.lua | 2 +- stdlib/area/area.lua | 10 +++--- stdlib/area/chunk.lua | 10 +++--- stdlib/area/direction.lua | 6 ++-- stdlib/area/orientation.lua | 4 +-- stdlib/area/position.lua | 14 ++++---- stdlib/area/surface.lua | 8 ++--- stdlib/area/tile.lua | 10 +++--- stdlib/core.lua | 8 ++--- stdlib/data/category.lua | 4 +-- stdlib/data/data.lua | 14 ++++---- stdlib/data/developer/developer.lua | 4 +-- stdlib/data/entity.lua | 4 +-- stdlib/data/fluid.lua | 2 +- stdlib/data/item.lua | 6 ++-- stdlib/data/modules/groups.lua | 2 +- stdlib/data/modules/pipes.lua | 2 +- stdlib/data/modules/util.lua | 8 ++--- stdlib/data/recipe.lua | 14 ++++---- stdlib/data/technology.lua | 6 ++-- stdlib/entity/entity.lua | 4 +-- stdlib/entity/inventory.lua | 4 +-- stdlib/entity/resource.lua | 16 ++++----- stdlib/event/changes.lua | 8 ++--- stdlib/event/event.lua | 20 +++++------ stdlib/event/force.lua | 14 ++++---- stdlib/event/gui.lua | 6 ++-- stdlib/event/modules/merge_data.lua | 2 +- stdlib/event/player.lua | 14 ++++---- stdlib/event/surface.lua | 8 ++--- stdlib/event/trains.lua | 10 +++--- stdlib/game.lua | 4 +-- stdlib/misc/config.lua | 8 ++--- stdlib/misc/logger.lua | 8 ++--- stdlib/misc/migrate.lua | 4 +-- stdlib/misc/queue.lua | 8 ++--- stdlib/scripts/interface.lua | 14 ++++---- stdlib/scripts/quickstart.lua | 10 +++--- stdlib/utils/classes/linked_list.lua | 6 ++-- stdlib/utils/classes/unique_array.lua | 2 +- stdlib/utils/color.lua | 16 ++++----- stdlib/utils/defines/anticolor.lua | 4 +-- stdlib/utils/defines/color.lua | 4 +-- stdlib/utils/defines/lightcolor.lua | 4 +-- stdlib/utils/globals.lua | 20 +++++------ stdlib/utils/is.lua | 2 +- stdlib/utils/math.lua | 2 +- stdlib/utils/string.lua | 2 +- stdlib/utils/table.lua | 2 +- stdlib/vendor/enumerable.lua | 2 +- 78 files changed, 272 insertions(+), 272 deletions(-) diff --git a/doc/examples/event.lua b/doc/examples/event.lua index 19564dc2..a13df169 100644 --- a/doc/examples/event.lua +++ b/doc/examples/event.lua @@ -1,5 +1,5 @@ -- Require the event module -local Event = require('__stdlib__/stdlib/event/event') +local Event = require('__stdlib2__/stdlib/event/event') -- Register our hotkeys diff --git a/info.json b/info.json index 16f3cf16..99516b55 100644 --- a/info.json +++ b/info.json @@ -1,15 +1,15 @@ { - "name": "stdlib", - "version": "2.0.0", + "name": "stdlib2", + "version": "2.0.2", "factorio_version": "2.0", - "title": "Factorio Standard Library", + "title": "Factorio Standard Library 2.0", "author": "Afforess", "contact": "", "dependencies": [ "base >= 2.0.0" ], "homepage": "https://github.com/Afforess/Factorio-Stdlib", - "description": "The Factorio Standard Library is a project to bring Factorio modders high-quality, commonly-required utilities and tools.", + "description": "The Factorio Standard Library is a project to bring Factorio modders high-quality, commonly-required utilities and tools. Reupload with 2.0 fixes.", "package": { "ignore": [ "wiki/**", diff --git a/spec/area/area_spec.lua b/spec/area/area_spec.lua index 82d4708d..a0b24ef4 100644 --- a/spec/area/area_spec.lua +++ b/spec/area/area_spec.lua @@ -1,8 +1,8 @@ require('spec/setup/busted')() -local Area = require('__stdlib__/stdlib/area/area') +local Area = require('__stdlib2__/stdlib/area/area') local A = Area -local P = require('__stdlib__/stdlib/area/position') +local P = require('__stdlib2__/stdlib/area/position') local rs = rawtostring describe('Area', function () diff --git a/spec/area/chunk_spec.lua b/spec/area/chunk_spec.lua index 8047198a..afc4b869 100644 --- a/spec/area/chunk_spec.lua +++ b/spec/area/chunk_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local Chunk = require('__stdlib__/stdlib/area/chunk') +local Chunk = require('__stdlib2__/stdlib/area/chunk') local C = Chunk describe('Chunk Spec', function() diff --git a/spec/area/direction_spec.lua b/spec/area/direction_spec.lua index 80708918..442d8c76 100644 --- a/spec/area/direction_spec.lua +++ b/spec/area/direction_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local Direction = require('__stdlib__/stdlib/area/direction') +local Direction = require('__stdlib2__/stdlib/area/direction') describe('Direction Functions', function() local d = defines.direction diff --git a/spec/area/position_spec.lua b/spec/area/position_spec.lua index aab2cef4..4d2e2e1a 100644 --- a/spec/area/position_spec.lua +++ b/spec/area/position_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local Position = require('__stdlib__/stdlib/area/position') +local Position = require('__stdlib2__/stdlib/area/position') local P = Position describe('Position', function () diff --git a/spec/area/surface_spec.lua b/spec/area/surface_spec.lua index 84e31495..e91da499 100644 --- a/spec/area/surface_spec.lua +++ b/spec/area/surface_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local Surface = require('__stdlib__/stdlib/area/surface') +local Surface = require('__stdlib2__/stdlib/area/surface') describe('Surface Spec', function() describe('Surface lookups', function() diff --git a/spec/area/tile_spec.lua b/spec/area/tile_spec.lua index dfadeeff..4fb42132 100644 --- a/spec/area/tile_spec.lua +++ b/spec/area/tile_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local Tile = require('__stdlib__/stdlib/area/tile') +local Tile = require('__stdlib2__/stdlib/area/tile') describe('Tile Spec', function() it('should give the correct tile coordinates for a position', function() diff --git a/spec/core_spec.lua b/spec/core_spec.lua index acd72d12..c3cdb35a 100644 --- a/spec/core_spec.lua +++ b/spec/core_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local Core = require('__stdlib__/stdlib/core') --luacheck: ignore +local Core = require('__stdlib2__/stdlib/core') --luacheck: ignore describe('Core', function() diff --git a/spec/data/data_spec.lua b/spec/data/data_spec.lua index ca3ac222..40188b36 100644 --- a/spec/data/data_spec.lua +++ b/spec/data/data_spec.lua @@ -6,7 +6,7 @@ describe('Data', function() before_each(function() require('faketorio/dataloader') - Data = require('__stdlib__/stdlib/data/data') + Data = require('__stdlib2__/stdlib/data/data') Raw = _G["data"].raw["recipe"] R = Data("stone-furnace", "recipe") F = Data("fake", "fake") diff --git a/spec/data/recipe_spec.lua b/spec/data/recipe_spec.lua index be8b4b31..e9f1428b 100644 --- a/spec/data/recipe_spec.lua +++ b/spec/data/recipe_spec.lua @@ -1,13 +1,13 @@ require('spec/setup/busted')() local Recipe, Raw, Rawtech -local table = require('__stdlib__/stdlib/utils/table') +local table = require('__stdlib2__/stdlib/utils/table') describe('Recipe', function() before_each(function() require('faketorio/dataloader') - Recipe = require('__stdlib__/stdlib/data/recipe') + Recipe = require('__stdlib2__/stdlib/data/recipe') Raw = _G["data"].raw["recipe"] Rawtech = _G["data"].raw["technology"]["steel-processing"] end) diff --git a/spec/data/technology_spec.lua b/spec/data/technology_spec.lua index 37ebbdc8..ff6c614e 100644 --- a/spec/data/technology_spec.lua +++ b/spec/data/technology_spec.lua @@ -8,7 +8,7 @@ describe( before_each( function() require('faketorio/dataloader') - Technology = require('__stdlib__/stdlib/data/technology') + Technology = require('__stdlib2__/stdlib/data/technology') end ) diff --git a/spec/entity/entity_spec.lua b/spec/entity/entity_spec.lua index 0ebf432d..56050407 100644 --- a/spec/entity/entity_spec.lua +++ b/spec/entity/entity_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local Entity = require('__stdlib__/stdlib/entity/entity') +local Entity = require('__stdlib2__/stdlib/entity/entity') describe('Entity', function() it('an entity should be frozen', function() diff --git a/spec/entity/inventory_spec.lua b/spec/entity/inventory_spec.lua index 6fc96ac0..0826773d 100644 --- a/spec/entity/inventory_spec.lua +++ b/spec/entity/inventory_spec.lua @@ -1,7 +1,7 @@ require('spec/setup/busted')() -local Inventory = require('__stdlib__/stdlib/entity/inventory') -local table = require('__stdlib__/stdlib/utils/table') +local Inventory = require('__stdlib2__/stdlib/entity/inventory') +local table = require('__stdlib2__/stdlib/utils/table') describe('Inventory Spec', function() local function make_get_contents(inv) diff --git a/spec/entity/resource_spec.lua b/spec/entity/resource_spec.lua index 78e845db..4f2e4190 100644 --- a/spec/entity/resource_spec.lua +++ b/spec/entity/resource_spec.lua @@ -1,8 +1,8 @@ require('spec/setup/busted')() -local Resource = require('__stdlib__/stdlib/entity/resource') -local Area = require('__stdlib__/stdlib/area/area') -local table = require('__stdlib__/stdlib/utils/table') +local Resource = require('__stdlib2__/stdlib/entity/resource') +local Area = require('__stdlib2__/stdlib/area/area') +local table = require('__stdlib2__/stdlib/utils/table') describe('Resource filtering', function() local resources = {} diff --git a/spec/event/event_spec.lua b/spec/event/event_spec.lua index 41c8c8e0..b6a55c10 100644 --- a/spec/event/event_spec.lua +++ b/spec/event/event_spec.lua @@ -10,7 +10,7 @@ describe('Event', function () insulate('.register', function() it('should multiplex events to multiple registered handlers', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local f, g = genstub(2) Event.register(0, f) Event.register(0, g) @@ -26,7 +26,7 @@ describe('Event', function () insulate('.register', function() it('should error() if a nil/false event id is supplied', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') assert.has.errors(function() Event.register(false, function() end) end) assert.has.errors(function() Event.register({0, false}, function() end) end) assert.has.errors(function() Event.register({0, {}}) end) @@ -36,7 +36,7 @@ describe('Event', function () insulate('.register', function() it('should error() if no handler is provided', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local f, g = genstub(2) Event.register(0, f) Event.register(0, g) @@ -47,7 +47,7 @@ describe('Event', function () insulate('.register', function() it('should add and invoke handlers for multiple events', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local f, g = genstub(2) Event.register({0, 2}, f).register(2, g) @@ -67,7 +67,7 @@ describe('Event', function () it('should attach to factorio events when initial, but not subsequent \z registrations are requested on a per-event basis', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local s = spy.on(Event.script, 'on_event') Event.register(0, genstub()) @@ -97,7 +97,7 @@ describe('Event', function () insulate('.register', function() it('should return the event module to callers', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') assert.equals(Event, Event.register(0, genstub(1))) assert.equals(Event, Event.register(0, genstub(1)).register(0, genstub(1))) end) @@ -107,7 +107,7 @@ describe('Event', function () it('should not add duplicate handers to a single event, and \z should fire in order of least recent registration', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local g = genstub() local f = spy(function () assert.stub(g).was.called(1) @@ -133,7 +133,7 @@ describe('Event', function () insulate('.register', function() it('should register and appropriately invoke filtered handlers', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local pete_repeat_repeated_pattern = 'pete_repeat' -- RepeatyPete copies pattern here when invoked local that_one_thing = {} -- arbitrary singleton @@ -209,7 +209,7 @@ describe('Event', function () is for the event being dispatched, does not cause the handler \z to fire.', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local g, h = genstub(2) local f = spy(function() Event.register(0, h) @@ -249,7 +249,7 @@ describe('Event', function () events, and should deregister itself when the corresponding final \z listener is removed.', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local spy_on_init = spy.on(Event.script, 'on_init') local spy_on_load = spy.on(Event.script, 'on_load') local spy_on_configuration_changed = spy.on(Event.script, 'on_configuration_changed') @@ -356,7 +356,7 @@ describe('Event', function () it('unregisters the requested handler regardless of the order \z in which it was registered', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local f, g, h = genstub(3) Event.register(0, f).register(0, g).register(0, h) @@ -391,7 +391,7 @@ describe('Event', function () insulate('.remove', function() it('returns the Event module when called', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local f, g, h = genstub(3) Event.register(0, f).register(0, g).register(0, h) @@ -421,7 +421,7 @@ describe('Event', function () insulate('.remove', function() pending('should remove the running handler if requested', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local f, h = genstub(2) local g = spy(function() Event.remove(0, g) --luacheck: ignore g @@ -444,7 +444,7 @@ describe('Event', function () pending('should prevent invocation of subsequent handlers \z during processing of preceeding handlers', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local f = spy(function() Event.remove(0, g).remove(0, h) --luacheck: ignore g h end) @@ -464,7 +464,7 @@ describe('Event', function () it('should log, but not error(), upon de-registration \z of non-registered listeners', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') _G.log = genstub() assert.has_no.errors(function () Event.remove(0, genstub()) end) --assert.stub(_G.log).was.called() @@ -474,7 +474,7 @@ describe('Event', function () insulate('.remove', function() it('should deregister a given handler from an event', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local f, g, h, i = genstub(4) Event.register(0, f).register({0, 1}, g) Event.register({0, 1, 2}, h).register({2, 0}, i) @@ -563,7 +563,7 @@ describe('Event', function () it('should print an error to connected players if a protected handler \z throws an error', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') World.init(true) World.create_players(2) _G.game.tick = 2 @@ -594,7 +594,7 @@ describe('Event', function () it('should cease processing an event with a userdata property \z which has become non-valid', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local fud = World.fake_userdata() local e = {foo = 'bar', fud = fud} local f, h = genstub(2) @@ -614,7 +614,7 @@ describe('Event', function () it('should abort event processing when a handler returns \z stop_processing', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local return_value = Event.stop_processing local g = spy(function () return return_value @@ -653,7 +653,7 @@ describe('Event', function () it('should abort event processing when a matched handler \z returns stop_processing', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local i,k = genstub(2) local j = spy(function() return Event.stop_processing @@ -693,7 +693,7 @@ describe('Event', function () Event.stop_processing, which should just count as a \z successful match in that context', function() World.bootstrap() - local Event = require('__stdlib__/stdlib/event/event') + local Event = require('__stdlib2__/stdlib/event/event') local l,m,n,o = genstub(4) local pattern_identity_matcher = function(_, pattern) return pattern diff --git a/spec/event/force_bak.lua b/spec/event/force_bak.lua index 7ed87bf6..dac8fa67 100644 --- a/spec/event/force_bak.lua +++ b/spec/event/force_bak.lua @@ -1,7 +1,7 @@ require('spec/setup/busted')() -local Event = require('__stdlib__/stdlib/event/event') -local table = require('__stdlib__/stdlib/utils/table').overwrite_global() +local Event = require('__stdlib2__/stdlib/event/event') +local table = require('__stdlib2__/stdlib/utils/table').overwrite_global() describe("Force", function() @@ -42,14 +42,14 @@ describe("Force", it("should allow itself to be loaded at startup time", function() - require('__stdlib__/stdlib/event/force').register_events() + require('__stdlib2__/stdlib/event/force').register_events() end ) it("should register handlers for creation events", function() --local register_spy = spy.on(_G.Event, "register") - require('__stdlib__/stdlib/event/force').register_events() + require('__stdlib2__/stdlib/event/force').register_events() --local match = require('luassert.match')) --local events = {defines.events.on_force_created, Event.core_events.init, Event.core_events.configuration_changed} --assert.spy(register_spy).was_called_with(events, match.is_function()) @@ -65,7 +65,7 @@ describe("Force", for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } end - require('__stdlib__/stdlib/event/force').register_events() + require('__stdlib2__/stdlib/event/force').register_events() Event.dispatch({name = Event.core_events.init}) for _, force_name in ipairs(storage.forces) do assert.same(game.forces[force_name].name, storage.forces[force_name].name) @@ -80,7 +80,7 @@ describe("Force", for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } end - require('__stdlib__/stdlib/event/force').register_events() + require('__stdlib2__/stdlib/event/force').register_events() Event.dispatch({name = Event.core_events.configuration_changed, test = "TEST"}) for _, force_name in ipairs(storage.forces) do assert.same(game.forces[force_name].name, storage.forces[force_name].name) @@ -102,7 +102,7 @@ describe("Force", it(".get should retrieve forces from game.forces and storage.forces", function() - local Force = require('__stdlib__/stdlib/event/force').register_events() + local Force = require('__stdlib2__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } @@ -120,7 +120,7 @@ describe("Force", it(".get should add a force into storage.forces if the force is in game.forces but does not exist in storage.forces", function() - local Force = require('__stdlib__/stdlib/event/force').register_events() + local Force = require('__stdlib2__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } @@ -141,7 +141,7 @@ describe("Force", for _, force_name in ipairs(force_names) do storage.forces[force_name] = { index = force_name, name = force_name, data = "Data" .. force_name } end - local Force = require('__stdlib__/stdlib/event/force').register_events() + local Force = require('__stdlib2__/stdlib/event/force').register_events() local data = {a = "abc", b = "def"} Force.add_data_all(data) for _, force_name in ipairs(force_names) do @@ -153,7 +153,7 @@ describe("Force", it(".init should initialize storage.forces", function() - local Force = require('__stdlib__/stdlib/event/force').register_events() + local Force = require('__stdlib2__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } @@ -169,7 +169,7 @@ describe("Force", it(".init should re-init forces", function() - local Force = require('__stdlib__/stdlib/event/force').register_events() + local Force = require('__stdlib2__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree", "ForceFour"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } @@ -197,7 +197,7 @@ describe("Force", it(".init should iterate all game.forces[index] and initialize storage.forces[index] when nil is passed", function() - local Force = require('__stdlib__/stdlib/event/force').register_events() + local Force = require('__stdlib2__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } @@ -213,7 +213,7 @@ describe("Force", it(".init should iterate all game.forces[index] and re-init storage.forces[index] when event is nil and overwrite is true", function() - local Force = require('__stdlib__/stdlib/event/force').register_events() + local Force = require('__stdlib2__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name } @@ -236,7 +236,7 @@ describe("Force", --If a force isn"t valid then it won"t add it to global table --Additionally game.forces won"t return invalid forces (TBD) function() - local Force = require('__stdlib__/stdlib/event/force').register_events() + local Force = require('__stdlib2__/stdlib/event/force').register_events() local force_names = {"ForceOne", "ForceTwo", "ForceThree"} for _, force_name in ipairs(force_names) do game.forces[force_name] = { index = force_name, name = force_name} diff --git a/spec/event/gui_spec.lua b/spec/event/gui_spec.lua index b1310866..e9e470bf 100644 --- a/spec/event/gui_spec.lua +++ b/spec/event/gui_spec.lua @@ -3,8 +3,8 @@ require('spec/setup/busted')() local World = require('faketorio/world') World.init() -local Event = require('__stdlib__/stdlib/event/event') -local Gui = require('__stdlib__/stdlib/event/gui') +local Event = require('__stdlib2__/stdlib/event/event') +local Gui = require('__stdlib2__/stdlib/event/gui') local test_function = { f=function(x) _G.someVariable = x end, diff --git a/spec/event/player_bak.lua b/spec/event/player_bak.lua index 5c57032c..c2636b28 100644 --- a/spec/event/player_bak.lua +++ b/spec/event/player_bak.lua @@ -1,8 +1,8 @@ require('spec/setup/busted')() --luacheck: ignore -local Event = require('__stdlib__/stdlib/event/event') -local table = require('__stdlib__/stdlib/utils/table') +local Event = require('__stdlib2__/stdlib/event/event') +local table = require('__stdlib2__/stdlib/utils/table') describe( 'Player', @@ -52,7 +52,7 @@ describe( it( 'should allow itself to be loaded at startup time', function() - require('__stdlib__/stdlib/event/player') + require('__stdlib2__/stdlib/event/player') end ) @@ -60,7 +60,7 @@ describe( 'should register handlers for creation events', function() --local register_spy = spy.on(_G.Event, "register") - require('__stdlib__/stdlib/event/player').register_events() + require('__stdlib2__/stdlib/event/player').register_events() --local match = require('luassert.match')) --local events = {defines.events.on_player_created, Event.core_events.init, Event.core_events.configuration_changed} --assert.spy(register_spy).was_called_with(events, match.is_function()) @@ -77,7 +77,7 @@ describe( 'should register handlers for destruction events', function() local register_spy = spy.on(Event, 'register') - require('__stdlib__/stdlib/event/player').register_events() + require('__stdlib2__/stdlib/event/player').register_events() local match = require('luassert.match') assert.spy(register_spy).was_called_with(defines.events.on_player_removed, match.is_function()) end @@ -91,7 +91,7 @@ describe( for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} end - require('__stdlib__/stdlib/event/player').register_events() + require('__stdlib2__/stdlib/event/player').register_events() Event.dispatch({name = Event.core_events.init}) for player_index in ipairs(storage.players) do assert.same(game.players[player_index].name, storage.players[player_index].name) @@ -107,7 +107,7 @@ describe( for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} end - require('__stdlib__/stdlib/event/player').register_events() + require('__stdlib2__/stdlib/event/player').register_events() Event.dispatch({name = Event.core_events.configuration_changed, test = 'TEST'}) for player_index in ipairs(storage.players) do assert.same(game.players[player_index].name, storage.players[player_index].name) @@ -119,7 +119,7 @@ describe( 'should load players into the global object when players are created in the game object', function() _G.storage = {} - require('__stdlib__/stdlib/event/player').register_events() + require('__stdlib2__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} @@ -149,7 +149,7 @@ describe( it( '.get should retrieve player objects from game.players and storage.players objects', function() - local Player = require('__stdlib__/stdlib/event/player').register_events() + local Player = require('__stdlib2__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} @@ -168,7 +168,7 @@ describe( it( '.get should add a player into storage.players if the player is in game.players but does not exist in storage.players', function() - local Player = require('__stdlib__/stdlib/event/player').register_events() + local Player = require('__stdlib2__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} @@ -190,7 +190,7 @@ describe( for player_index, player_name in ipairs(player_names) do storage.players[player_index] = {index = player_index, name = player_name, data = 'Data' .. player_index} end - local Player = require('__stdlib__/stdlib/event/player').register_events() + local Player = require('__stdlib2__/stdlib/event/player').register_events() local data = {a = 'abc', b = 'def'} Player.add_data_all(data) for player_index, _ in ipairs(player_names) do @@ -203,7 +203,7 @@ describe( it( '.remove should remove data for players when an event is passed', function() - local Player = require('__stdlib__/stdlib/event/player').register_events() + local Player = require('__stdlib2__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} @@ -219,7 +219,7 @@ describe( it( '.init should initialize global.players', function() - local Player = require('__stdlib__/stdlib/event/player').register_events() + local Player = require('__stdlib2__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} @@ -237,7 +237,7 @@ describe( it( '.init should re-init players', function() - local Player = require('__stdlib__/stdlib/event/player').register_events() + local Player = require('__stdlib2__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} @@ -255,7 +255,7 @@ describe( it( '.init should iterate all game.players[index] and initialize storage.players[index] when nil is passed', function() - local Player = require('__stdlib__/stdlib/event/player').register_events() + local Player = require('__stdlib2__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} @@ -272,7 +272,7 @@ describe( it( '.init should iterate all game.players[index] and re-init storage.players[index] when event is nil and overwrite is true', function() - local Player = require('__stdlib__/stdlib/event/player').register_events() + local Player = require('__stdlib2__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} @@ -296,7 +296,7 @@ describe( --If a player isn"t valid then it won"t add it to global table --Additionally game.players won"t return invalid players (TBD) function() - local Player = require('__stdlib__/stdlib/event/player').register_events() + local Player = require('__stdlib2__/stdlib/event/player').register_events() local player_names = {'PlayerOne', 'PlayerTwo', 'PlayerThree'} for player_index, player_name in ipairs(player_names) do game.players[player_index] = {index = player_index, name = player_name} diff --git a/spec/game_spec.lua b/spec/game_spec.lua index 03289041..51645550 100644 --- a/spec/game_spec.lua +++ b/spec/game_spec.lua @@ -1,7 +1,7 @@ require('spec/setup/busted')() -local Game = require('__stdlib__/stdlib/game') -local table = require('__stdlib__/stdlib/utils/table') +local Game = require('__stdlib2__/stdlib/game') +local table = require('__stdlib2__/stdlib/utils/table') describe("Game Spec", function() diff --git a/spec/misc/config_spec.lua b/spec/misc/config_spec.lua index cb689d5d..43dfd67c 100644 --- a/spec/misc/config_spec.lua +++ b/spec/misc/config_spec.lua @@ -1,7 +1,7 @@ require('spec/setup/busted')() -local Config = require('__stdlib__/stdlib/misc/config') -local table = require('__stdlib__/stdlib/utils/table') +local Config = require('__stdlib2__/stdlib/misc/config') +local table = require('__stdlib2__/stdlib/utils/table') --[[ the table to be duplicated for all tests. ]]-- _G.config_template = { diff --git a/spec/misc/logger_spec.lua b/spec/misc/logger_spec.lua index 977ce56e..607aaa44 100644 --- a/spec/misc/logger_spec.lua +++ b/spec/misc/logger_spec.lua @@ -3,7 +3,7 @@ require('spec/setup/busted')() _G.script = { mod_name = 'stdlib' } -local Logger = require('__stdlib__/stdlib/misc/logger') +local Logger = require('__stdlib2__/stdlib/misc/logger') describe('Logger', function() diff --git a/spec/misc/queue_spec.lua b/spec/misc/queue_spec.lua index a6d487cf..35f8cbc0 100644 --- a/spec/misc/queue_spec.lua +++ b/spec/misc/queue_spec.lua @@ -1,7 +1,7 @@ require('spec/setup/busted')() -local Queue = require('__stdlib__/stdlib/misc/queue') -local table = require('__stdlib__/stdlib/utils/table') +local Queue = require('__stdlib2__/stdlib/misc/queue') +local table = require('__stdlib2__/stdlib/utils/table') describe('Queue', function() local queue1 diff --git a/spec/utils/classes/linked_list_spec.lua b/spec/utils/classes/linked_list_spec.lua index 73f81509..a050d074 100644 --- a/spec/utils/classes/linked_list_spec.lua +++ b/spec/utils/classes/linked_list_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local LinkedList = require('__stdlib__/stdlib/utils/classes/linked_list') +local LinkedList = require('__stdlib2__/stdlib/utils/classes/linked_list') local World = require('faketorio/world') -- bootstrap world for _G.log diff --git a/spec/utils/classes/unique_array_spec.lua b/spec/utils/classes/unique_array_spec.lua index f56575ec..f4a4aa81 100644 --- a/spec/utils/classes/unique_array_spec.lua +++ b/spec/utils/classes/unique_array_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local Unique_Array = require('__stdlib__/stdlib/utils/classes/unique_array') +local Unique_Array = require('__stdlib2__/stdlib/utils/classes/unique_array') local U = Unique_Array describe('String_array', function() diff --git a/spec/utils/is_spec.lua b/spec/utils/is_spec.lua index ffc4917b..0d0a9c3e 100644 --- a/spec/utils/is_spec.lua +++ b/spec/utils/is_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local Is = require('__stdlib__/stdlib/utils/is') +local Is = require('__stdlib2__/stdlib/utils/is') describe( 'variable type checks', diff --git a/spec/utils/math_spec.lua b/spec/utils/math_spec.lua index 05f156ce..b0a553e7 100644 --- a/spec/utils/math_spec.lua +++ b/spec/utils/math_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local math = require('__stdlib__/stdlib/utils/math') +local math = require('__stdlib2__/stdlib/utils/math') describe('Math', function() it('should clamp', function() diff --git a/spec/utils/string_spec.lua b/spec/utils/string_spec.lua index 6f297c6a..3882a69d 100644 --- a/spec/utils/string_spec.lua +++ b/spec/utils/string_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local string = require('__stdlib__/stdlib/utils/string') +local string = require('__stdlib2__/stdlib/utils/string') describe('String Spec', function() describe('string.trim', function() diff --git a/spec/utils/table_spec.lua b/spec/utils/table_spec.lua index c3f74745..04982e1a 100644 --- a/spec/utils/table_spec.lua +++ b/spec/utils/table_spec.lua @@ -1,6 +1,6 @@ require('spec/setup/busted')() -local table = require('__stdlib__/stdlib/utils/table') +local table = require('__stdlib2__/stdlib/utils/table') describe('Table Spec', function() describe('table.map', function() diff --git a/stdlib/area/area.lua b/stdlib/area/area.lua index 0167f5bf..e01eb5ab 100644 --- a/stdlib/area/area.lua +++ b/stdlib/area/area.lua @@ -1,16 +1,16 @@ --- Tools for working with bounding boxes. -- @module Area.Area --- @usage local Area = require('__stdlib__/stdlib/area/area') +-- @usage local Area = require('__stdlib2__/stdlib/area/area') -- @see Area.Position -- @see Concepts.BoundingBox -- @see Concepts.Position -local Area = { __class = 'Area', __index = require('__stdlib__/stdlib/core') } +local Area = { __class = 'Area', __index = require('__stdlib2__/stdlib/core') } setmetatable(Area, Area) -local Position = require('__stdlib__/stdlib/area/position') +local Position = require('__stdlib2__/stdlib/area/position') -local math = require('__stdlib__/stdlib/utils/math') -local string = require('__stdlib__/stdlib/utils/string') +local math = require('__stdlib2__/stdlib/utils/math') +local string = require('__stdlib2__/stdlib/utils/string') local abs, floor, max = math.abs, math.floor, math.max local metatable diff --git a/stdlib/area/chunk.lua b/stdlib/area/chunk.lua index ccf095f7..e8d61862 100644 --- a/stdlib/area/chunk.lua +++ b/stdlib/area/chunk.lua @@ -1,19 +1,19 @@ --- For working with chunks. -- A chunk represents a 32 tile2 on a surface in Factorio. -- @module Area.Chunk --- @usage local Chunk = require('__stdlib__/stdlib/area/chunk') +-- @usage local Chunk = require('__stdlib2__/stdlib/area/chunk') -- @see Concepts.ChunkPosition local Chunk = { __class = 'Chunk', - __index = require('__stdlib__/stdlib/core') + __index = require('__stdlib2__/stdlib/core') } setmetatable(Chunk, Chunk) -local Game = require('__stdlib__/stdlib/game') -local Position = require('__stdlib__/stdlib/area/position') +local Game = require('__stdlib2__/stdlib/game') +local Position = require('__stdlib2__/stdlib/area/position') -local AREA_PATH = '__stdlib__/stdlib/area/area' +local AREA_PATH = '__stdlib2__/stdlib/area/area' Chunk.__call = Position.__call diff --git a/stdlib/area/direction.lua b/stdlib/area/direction.lua index 3da2078e..e0347d98 100644 --- a/stdlib/area/direction.lua +++ b/stdlib/area/direction.lua @@ -1,11 +1,11 @@ --- Functions for working with directions and orientations. -- @module Area.Direction --- @usage local Direction = require('__stdlib__/stdlib/area/direction') +-- @usage local Direction = require('__stdlib2__/stdlib/area/direction') -- @see defines.direction local Direction = { __class = 'Direction', - __index = require('__stdlib__/stdlib/core') + __index = require('__stdlib2__/stdlib/core') } setmetatable(Direction, Direction) @@ -88,7 +88,7 @@ end -- Deprecated do - local Orientation = require('__stdlib__/stdlib/area/orientation') + local Orientation = require('__stdlib2__/stdlib/area/orientation') Direction.opposite_direction = Direction.opposite Direction.direction_to_orientation = Direction.to_orientation diff --git a/stdlib/area/orientation.lua b/stdlib/area/orientation.lua index d97cc300..d9002ab5 100644 --- a/stdlib/area/orientation.lua +++ b/stdlib/area/orientation.lua @@ -1,10 +1,10 @@ --- Functions for working with orientations. -- @module Area.Orientation --- @usage local Orientation = require('__stdlib__/stdlib/area/orientation') +-- @usage local Orientation = require('__stdlib2__/stdlib/area/orientation') local Orientation = { __class = 'Orientation', - __index = require('__stdlib__/stdlib/core'), + __index = require('__stdlib2__/stdlib/core'), } setmetatable(Orientation, Orientation) diff --git a/stdlib/area/position.lua b/stdlib/area/position.lua index dcd2423f..97dd295c 100644 --- a/stdlib/area/position.lua +++ b/stdlib/area/position.lua @@ -1,17 +1,17 @@ --- Tools for working with `` coordinates. -- @module Area.Position --- @usage local Position = require('__stdlib__/stdlib/area/position') +-- @usage local Position = require('__stdlib2__/stdlib/area/position') -- @see Area.Area -- @see Concepts.Position -- @see defines.direction -local Position = { __class = 'Position', __index = require('__stdlib__/stdlib/core') } +local Position = { __class = 'Position', __index = require('__stdlib2__/stdlib/core') } setmetatable(Position, Position) -local Direction = require('__stdlib__/stdlib/area/direction') -local Orientation = require('__stdlib__/stdlib/area/orientation') +local Direction = require('__stdlib2__/stdlib/area/direction') +local Orientation = require('__stdlib2__/stdlib/area/orientation') -local string = require('__stdlib__/stdlib/utils/string') -local math = require('__stdlib__/stdlib/utils/math') +local string = require('__stdlib2__/stdlib/utils/string') +local math = require('__stdlib2__/stdlib/utils/math') local floor, abs, atan2, round_to, round = math.floor, math.abs, math.atan2, math.round_to, math.round local cos, sin, ceil, sqrt, pi, random = math.cos, math.sin, math.ceil, math.sqrt, math.pi, math.random @@ -19,7 +19,7 @@ local deg, acos, max, min, is_number = math.deg, math.acos, math.max, math.min, local split = string.split local directions = defines.direction -local AREA_PATH = '__stdlib__/stdlib/area/area' +local AREA_PATH = '__stdlib2__/stdlib/area/area' local EPSILON = 1.19e-07 local metatable diff --git a/stdlib/area/surface.lua b/stdlib/area/surface.lua index c5dbe051..acf699be 100644 --- a/stdlib/area/surface.lua +++ b/stdlib/area/surface.lua @@ -1,17 +1,17 @@ --- For working with surfaces. -- Surfaces are the "domain" of the world. -- @module Area.Surface --- @usage local Surface = require('__stdlib__/stdlib/area/surface') +-- @usage local Surface = require('__stdlib2__/stdlib/area/surface') -- @see LuaSurface local Surface = { __class = 'Surface', - __index = require('__stdlib__/stdlib/core') + __index = require('__stdlib2__/stdlib/core') } setmetatable(Surface, Surface) -local Is = require('__stdlib__/stdlib/utils/is') -local Area = require('__stdlib__/stdlib/area/area') +local Is = require('__stdlib2__/stdlib/utils/is') +local Area = require('__stdlib2__/stdlib/area/area') --- Flexible and safe lookup function for surfaces. --