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/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 dd6c11a8..a41ac138 100644 --- a/info.json +++ b/info.json @@ -1,15 +1,15 @@ { - "name": "stdlib", - "version": "1.4.9", - "factorio_version": "1.1", - "title": "Factorio Standard Library", + "name": "stdlib2", + "version": "2.0.1", + "factorio_version": "2.0", + "title": "Factorio Standard Library 2.0", "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.", + "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 15b45481..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() @@ -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/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 c0c14831..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() @@ -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/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 f4f9d987..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() @@ -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/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 7f324f66..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() @@ -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 ) @@ -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()) @@ -60,67 +60,67 @@ 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() + require('__stdlib2__/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() + require('__stdlib2__/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 = 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 } - 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 = 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 } @@ -129,55 +129,55 @@ 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 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 - 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 = 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 } 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 ) 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 } - 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,62 +189,62 @@ 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 = 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 } 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 = 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 } - 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() - 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} 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/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 32002481..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', @@ -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) @@ -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 @@ -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() + require('__stdlib2__/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() + require('__stdlib2__/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 = {} - require('__stdlib__/stdlib/event/player').register_events() + _G.storage = {} + 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} 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,40 +135,40 @@ 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 = 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} - 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 = 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} @@ -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 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 - 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 ) @@ -203,15 +203,15 @@ 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} - 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 ) @@ -219,92 +219,92 @@ 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} 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 ) 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} - 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 = 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} 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 = 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} - 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() - 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} 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..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() @@ -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/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 af13dd81..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 @@ -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/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 ab485e3e..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) @@ -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. @@ -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 @@ -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..d9002ab5 100644 --- a/stdlib/area/orientation.lua +++ b/stdlib/area/orientation.lua @@ -1,29 +1,29 @@ --- 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) --- 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 diff --git a/stdlib/area/position.lua b/stdlib/area/position.lua index f6a3468f..a2b42cc5 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. --