Skip to content

Commit

Permalink
Merge pull request #4 from Pouka-dev/develop
Browse files Browse the repository at this point in the history
feature(Issue-1) Copy/Paste
close #1
Adding functionnality for Copy/Paste settings
This fix blueprint mode
  • Loading branch information
Pouka-dev authored Sep 5, 2021
2 parents 6d4e231 + e436b97 commit 138f7f6
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 281 deletions.
12 changes: 12 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
---------------------------------------------------------------------------------------------------
Version: 1.1.2
Date: 05. 09. 2021
Bugfixes:
- Copy/Paste settings and blueprint
Changes:
- Nothing
---------------------------------------------------------------------------------------------------
Version: 1.1.1
Date: 03. 09. 2021
Changes:
- Circuit network research changing for Easy mode.
---------------------------------------------------------------------------------------------------
Version: 1.1.0
Date: 03. 09. 2021
Changes:
Expand Down
1 change: 0 additions & 1 deletion control.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-------------- include libs ---------------
require ("mod-gui")
require ("cores.lib.class")
Expand Down
9 changes: 4 additions & 5 deletions cores/game-events/control-handler.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
--- Description: Defines the event manager for custom-input/control events

--- Constructs and returns the ControlHandler object
return function()
local ControlHandler = {}

-- OnShowStorageNetworkGUI( Event ) :: void
-- Called when the key bound to show network overview is pressed
function ControlHandler.OnShowStorageNetworkGUI(event)
local playerIndex = event.player_index

-- Toggle show/close
if (SE.GuiManager.IsGuiOpen(playerIndex, SE.GuiManager.Guis.NetworkOverview)) then
SE.GuiManager.CloseGui(playerIndex)
else
SE.GuiManager.ShowGui(event, SE.GuiManager.Guis.NetworkOverview)
end
end

-- RegisterWithGame() :: void
-- Registers a listener for custom inputs
function ControlHandler.RegisterWithGame()
script.on_event(SE.Constants.Names.Controls.StorageNetworkGui, ControlHandler.OnShowStorageNetworkGUI)
end

return ControlHandler
end
114 changes: 92 additions & 22 deletions cores/game-events/entity-handler.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- Description: Defines the event handlers for when event effects entities

-- Constructs and returns the EntityHandlers object
return function()
local CreationHandlers = {}
Expand All @@ -8,17 +7,18 @@ return function()
Creation = CreationHandlers,
Destruction = DestructionHandlers
}

-- OnEntityBuilt( LuaEntity ) :: void
-- OnEntityBuilt( LuaEntity, Event ) :: void
-- Called by when either a player or bot builds an entity
function CreationHandlers.OnEntityBuilt(entity)
function CreationHandlers.OnEntityBuilt(entity, event)
local handler = SE.NodeHandlersRegistry.GetEntityHandler(entity)
if (handler ~= nil) then
SE.Logger.Trace("Entity Handler: Adding network node " .. handler.HandlerName)
SE.NetworksManager.AddNode(handler.NewNode(entity))
local newNode = SE.NetworksManager.AddNode(handler.NewNode(entity))
EntityHandlers.OnPasteSettingsWithNode(entity, newNode, event)
end
end

-- OnBuiltByPlayer( Event ) :: void
-- Called when player builds something.
-- Event fields:
Expand All @@ -27,9 +27,9 @@ return function()
-- - item :: string (optional)
-- - tags :: dictionary string -> Any (optional)
function CreationHandlers.OnBuiltByPlayer(event)
CreationHandlers.OnEntityBuilt(event.created_entity)
CreationHandlers.OnEntityBuilt(event.created_entity, event)
end

-- OnBuiltByBot( Event ) :: void
-- Called when a construction robot builds an entity.
-- Event fields:
Expand All @@ -38,18 +38,18 @@ return function()
-- - item :: string (optional)
-- - tags :: dictionary string -> Any (optional)
function CreationHandlers.OnBuiltByBot(event)
CreationHandlers.OnEntityBuilt(event.created_entity)
CreationHandlers.OnEntityBuilt(event.created_entity, event)
end

-- OnUnMarked( Event ) :: void
-- Called when the deconstruction of an entity is canceled.
-- Event fields:
-- - entity :: LuaEntity
-- - player_index :: uint (optional)
function CreationHandlers.OnUnMarked(event)
CreationHandlers.OnEntityBuilt(event.entity)
CreationHandlers.OnEntityBuilt(event.entity, event)
end

-- OnEntityRemoved( LuaEntity ) :: void
-- Called when an entity is, or will be, removed from the game
function DestructionHandlers.OnEntityRemoved(entity)
Expand All @@ -58,7 +58,7 @@ return function()
SE.NetworksManager.RemoveNodeByEntity(entity)
end
end

-- OnMinedByPlayer( Event ) :: void
-- Called after the results of an entity being mined are collected just before the entity is destroyed. After this event any items in the buffer will be transferred into the player as if they came from mining the entity.
-- Event fields:
Expand All @@ -69,7 +69,7 @@ return function()
function DestructionHandlers.OnMinedByPlayer(event)
DestructionHandlers.OnEntityRemoved(event.entity)
end

-- OnMinedByBot( Event ) :: void
-- Called after the results of an entity being mined are collected just before the entity is destroyed. After this event any items in the buffer will be transferred into the robot as if they came from mining the entity.
-- Event fields:
Expand All @@ -80,7 +80,7 @@ return function()
function DestructionHandlers.OnMinedByBot(event)
DestructionHandlers.OnEntityRemoved(event.entity)
end

-- OnKilled( Event )
-- Called when an entity dies.
-- Event fields:
Expand All @@ -90,10 +90,10 @@ return function()
function DestructionHandlers.OnKilled(event)
DestructionHandlers.OnEntityRemoved(event.entity)
end

local thingy = function()
end

end
-- OnMarked( Event ) :: void
-- Called when an entity is marked for deconstruction with the Deconstruction planner or via script.
-- Event fields:
Expand All @@ -102,7 +102,7 @@ return function()
function DestructionHandlers.OnMarked(event)
DestructionHandlers.OnEntityRemoved(event.entity)
end

-- OnPasteSettings( Event )
-- Called after entity copy-paste is done.
-- Event fields:
Expand All @@ -116,15 +116,85 @@ return function()
if (handler ~= nil) then
local destNode = SE.NetworksManager.GetNodeForEntity(destEntity)
if (destNode ~= nil) then
handler.OnPasteSettings(destNode, event.source, player)
handler.OnPasteSettings(destNode, event.source)
end
end
end



-- OnPasteSettingsWithNode( LuaEntity, Node, Event )
-- Called after entity copy-paste is done.
-- Event fields:
-- - entity :: LuaEntity: The source entity settings have been copied from.
-- - newNode :: Node: New node where the parameters will have to be pasted.
-- - event :: Event: Event, containing the potential information of a tag in the blueprint.
function EntityHandlers.OnPasteSettingsWithNode(entity, newNode, event)
local handler = SE.NodeHandlersRegistry.GetEntityHandler(entity)
if (handler ~= nil) then
if (event.tags ~= nil) then
handler.OnPasteSettingsWithNode(newNode, event.tags)
end
end
end


function EntityHandlers.OnPreEntitySettingsPasted(event)
local player = Player.load(event).get()
end
function EntityHandlers.OnPlayerSetupBlueprint(event)
local player = game.players[event.player_index]
local mapping = event.mapping.get()
local bp = player.blueprint_to_setup
if bp.valid_for_read == false then
local cursor = player.cursor_stack
if cursor and cursor.valid_for_read and cursor.name == "blueprint" then
bp = cursor
--return
end
end
if bp == nil or bp.valid_for_read == false then return end

for index, ent in pairs(mapping) do
local tags = EntityHandlers.EntityToBlueprintTags(ent)
if tags ~= nil then
for tag, value in pairs(tags) do
bp.set_blueprint_entity_tag(index, tag, value)
end
end
end

end
function EntityHandlers.OnPlayerConfiguredBlueprint(event)
local player = Player.load(event).get()
end



function EntityHandlers.EntityToBlueprintTags(copyEntity, fromTable)

local tags = nil
local handler = SE.NodeHandlersRegistry.GetEntityHandler(copyEntity)
if (handler ~= nil) then
tags = SE.NetworksManager.GetNodeForEntity(copyEntity)
end
return tags
end





-- RegisterWithGame() :: void
-- Registers event listeners with the game.
function EntityHandlers.RegisterWithGame()
script.on_event(defines.events.on_entity_settings_pasted, EntityHandlers.OnPasteSettings)
script.on_event(defines.events.on_pre_entity_settings_pasted, EntityHandlers.OnPreEntitySettingsPasted)
script.on_event(defines.events.on_player_setup_blueprint, EntityHandlers.OnPlayerSetupBlueprint)
script.on_event(defines.events.on_player_configured_blueprint, EntityHandlers.OnPlayerConfiguredBlueprint)




-- Creation
script.on_event(defines.events.on_built_entity, EntityHandlers.Creation.OnBuiltByPlayer)
script.on_event(defines.events.on_robot_built_entity, EntityHandlers.Creation.OnBuiltByBot)
Expand All @@ -134,6 +204,6 @@ return function()
script.on_event(defines.events.on_player_mined_entity, EntityHandlers.Destruction.OnMinedByPlayer)
script.on_event(defines.events.on_entity_died, EntityHandlers.Destruction.OnKilled)
end

return EntityHandlers
end
Loading

0 comments on commit 138f7f6

Please sign in to comment.