Skip to content

Commit

Permalink
Added Support for logistic-requests, logistic-storage-filters and slo…
Browse files Browse the repository at this point in the history
…t-locking in blueprints (#2)
  • Loading branch information
Nicolas Lang committed Aug 17, 2021
1 parent f45b0bd commit afd8158
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---------------------------------------------------------------------------------------------------
Version: 0.2.3
Major Features:
- Added Support for logistic-requests, logistic-storage-filters and slot-locking (https://github.com/nicolas-lang/Factorio.LongWarehouses/issues/2)
---------------------------------------------------------------------------------------------------
Version: 0.2.2
Bugfixes:
- Fix for missing check in compatibility scripts (https://github.com/nicolas-lang/Factorio.LongWarehouses/issues/1)
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nco-LongWarehouses",
"version": "0.2.2",
"version": "0.2.3",
"title": "Long Warehouses",
"author": "Karoschl",
"contact": "",
Expand Down
1 change: 1 addition & 0 deletions locale/en/Long-Train-warehouses.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ warning-undo=Long Warehouses: warning, using undo on a warehouse will break wire
warning-orphaned-connector=Long Warehouses: warning, removed orphaned warehouse connector
info-called-wh_check=Long Warehouses: called /wh_check
info-validate-warehouses=Long Warehouses: validating all warehouses...
warning-type-changed=Long Warehouses: Warning, a blueprint was created with logistic filters which the target does not support

cust-warehouse-name-normal=Long Warehouse
cust-warehouse-name-requester=Long Requester Warehouse
Expand Down
39 changes: 37 additions & 2 deletions script/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function myControl.on_built(event)
end
-- do all the things
if baseType == "entity" and entityName == "proxy" then
myControl.on_built_proxy(built_entity)
myControl.on_built_proxy(built_entity,event.tags)
end
-- finalize all the other things
if data_util.has_value({"horizontal","vertical", "proxy", "pole"}, entityName) then
Expand All @@ -183,7 +183,8 @@ end
-------------------------------------------------------------------------------------
-- On WhProxy Build
-------------------------------------------------------------------------------------
function myControl.on_built_proxy(proxy)
function myControl.on_built_proxy(proxy,tags)
--log("on_built_proxy")
local proxyData = {
surface = proxy.surface,
position = proxy.position,
Expand All @@ -205,6 +206,40 @@ function myControl.on_built_proxy(proxy)
force = proxyData.force,
player = proxyData.last_user
}
--set inventory configuration from blueprint tags
searchResult = proxyData.surface.find_entities_filtered({force = proxyData.force, name = proxyData.structure_name, position = proxyData.position, radius = 0.001})
--log(#searchResult)
for _, wh in pairs(searchResult) do
--log("configuring "..wh.name)
local whPrototype = game.entity_prototypes[wh.name]
--locked slots
if tags and tags.bar then
--log("configuring locked slots")
wh.get_inventory(defines.inventory.chest).set_bar(tags.bar)
end
-- requests/buffer-requests
if (tags and tags.request_slots)then
if (whPrototype.type == "logistic-container" and data_util.has_value({"requester","buffer"},whPrototype.logistic_mode))then
--log("configuring request slots")
for _, request_slot in pairs(data_util.csv_split(tags.request_slots,";")) do
local slotInfo = data_util.csv_split(request_slot,":")
wh.set_request_slot({name=slotInfo[2], count=tonumber(slotInfo[3])}, slotInfo[1])
end
else
game.print({"custom-strings.warning-type-changed"}, {r = 0.75, g = 0.5, b = 0.25, a = 0} )
end
end
-- logistic filter
if (tags and tags.storage_filter) then
if (whPrototype.type == "logistic-container" and whPrototype.logistic_mode == "storage")then
--log("configuring storage filter")
local slotInfo = data_util.csv_split(tags.storage_filter,":")
wh.storage_filter = game.item_prototypes[slotInfo[2]]
else
game.print({"custom-strings.warning-type-changed"}, {r = 0.75, g = 0.5, b = 0.25, a = 0} )
end
end
end
-- remainder of composite entity is built in validation called by on_built
end

Expand Down
27 changes: 26 additions & 1 deletion script/on_blueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local data_util = require("__nco-LongWarehouses__/lib/data_util")
-- On Blueprint Item Replace to Reset Item to Item-Proxy
-------------------------------------------------------------------------------------
local function on_blueprint(event)
--log("on_blueprint")
local player = game.players[event.player_index]
local bp = player.blueprint_to_setup
if not bp or not bp.valid_for_read then
Expand All @@ -18,7 +19,31 @@ local function on_blueprint(event)
end
for _, e in ipairs(entities) do
local whType = lib_warehouse.checkEntityName(e.name)
if data_util.has_value({"horizontal","vertical", "proxy"}, whType) then
if data_util.has_value({"horizontal","vertical"}, whType) then
--log("save inventory filters, requests for h/v. A proxy copied from a ghost should have inherited the tags")
local searchResult = player.surface.find_entities_filtered({force = e.force, name = e.name, position = e.position, radius = 0.001})
--log(#searchResult)
for _, ent in pairs(searchResult) do
local inventory = ent.get_inventory(defines.inventory.chest)
local request_slots = ""
local filter_slot = ""
for slotIndex = 1,ent.request_slot_count,1 do
local slot = ent.get_request_slot(slotIndex)
if slot then
request_slots = ((request_slots == "" and request_slots) or (request_slots..";"))..tostring(slotIndex)..":"..slot.name..":"..tostring(slot.count)
end
end
if ent.filter_slot_count and ent.filter_slot_count > 0 and ent.storage_filter then
filter_slot = ent.storage_filter.type..":"..ent.storage_filter.name
end
e.tags = {
request_slots = (request_slots ~= "" and request_slots or nil),
storage_filter = (filter_slot ~= "" and filter_slot or nil),
bar = (inventory.get_bar() <= #inventory and inventory.get_bar() or nil),
}
--log("set blueprint entity tags for "..ent.name.." to:"..serpent.block(e.tags, {comment = false, numformat = '%1.8g', compact = true } ))
end
--log("change to proxy")
if whType == "horizontal" then
e.name = e.name:gsub("-h", "-proxy")
elseif whType == "vertical" then
Expand Down
Binary file modified thumbnail.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit afd8158

Please sign in to comment.