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

Merge pull request #265 from ComfyFactory/blueprint_requesting

module to set requests in logi chests to blueprint total costs
This commit is contained in:
hanakocz 2022-05-19 23:36:41 +02:00 committed by GitHub
commit 7ee89ad7cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 0 deletions

View File

@ -27,6 +27,7 @@ require 'modules.floaty_chat'
require 'modules.show_inventory'
require 'modules.inserter_drops_pickup'
require 'modules.autostash'
require 'modules.blueprint_requesting'
require 'utils.gui'
require 'utils.gui.player_list'

View File

@ -21,6 +21,10 @@ turret_filler_label_amount=Amount:
turret_filler_ammo_type=Select Ammo:
turret_filler_ammo_lower=Enable lower tiers?
blueprint_requesting=Blueprint Requesting
blueprint_requesting_desc=Placing blueprints into [entity=logistic-chest-requester] or [entity=logistic-chest-buffer] will set the chest requests to match the blueprint costs. Happens when chest is closed.
blueprint_requesting_notify=This server has Blueprint Requesting feature enabled. Placing blueprints into [entity=logistic-chest-requester] or [entity=logistic-chest-buffer] will match the requests to the blueprint costs. You can disable this feature for yourself in Comfy menu -> Config.
[modules_towny]
map_info=__1__\n\n__2__\n\n__3__\n\n__4__\n\n__5__
map_info1=To ally or settle with another town, drop a fish on their market or character. (Default Hotkey Z)\nThey will have to do the same to you to complete the request.\nCoal yields the opposite result, as it will make foes or banish settlers.

View File

@ -0,0 +1,63 @@
--module by Hanakocz
local Event = require 'utils.event'
local Global = require 'utils.global'
local Public = {}
local this = {}
Global.register(
this,
function(tbl)
this = tbl
end
)
local function on_gui_closed(event)
local player_index = event.player_index
if this[player_index] and this[player_index].disabled then return end -- player disabled usage of this module in config tab for his actions
local entity = event.entity
if not entity or not entity.valid then return end
if entity.name == 'logistic-chest-requester' or entity.name == 'logistic-chest-buffer' then
if not this[player_index] or not this[player_index].notified then
local player = game.get_player(player_index)
player.print({'modules.blueprint_requesting_notify'}, {r= 0.88, g = 0.66, b = 0.02})
this[player_index] = this[player_index] or {}
this[player_index].notified = true
end
local inventory = entity.get_inventory(defines.inventory.chest)
if not inventory or not inventory.valid then return end
if inventory.get_item_count('blueprint') > 0 then
local items = {}
for i = 1, #inventory, 1 do
if inventory[i].valid_for_read and inventory[i].is_blueprint then
local cost = inventory[i].cost_to_build
for name, amount in pairs(cost) do
items[name] = (items[name] or 0) + amount
end
end
end
if entity.request_slot_count > 0 then
for slot = 1, entity.request_slot_count, 1 do
entity.clear_request_slot(slot)
end
end
local slot_index = 1
for item, amount in pairs(items) do
entity.set_request_slot({name = item, count = amount}, slot_index)
slot_index = slot_index + 1
end
end
end
end
function Public.get(key)
if key then
return this[key]
else
return this
end
end
Event.add(defines.events.on_gui_closed, on_gui_closed)
return Public

View File

@ -126,6 +126,18 @@ local functions = {
game.get_player(event.player_index).spectator = false
end
end,
['blueprint_requesting'] = function(event)
local BPRequests = is_loaded('modules.blueprint_requesting')
local Module = BPRequests.get()
if not Module[event.player_index] then
Module[event.player_index] = {}
end
if event.element.switch_state == 'left' then
Module[event.player_index].disabled = false
else
Module[event.player_index].disabled = true
end
end,
['bottom_location'] = function(event)
local player = game.get_player(event.player_index)
if event.element.switch_state == 'left' then
@ -448,6 +460,17 @@ local function build_config_gui(data)
scroll_pane.add({type = 'line'})
end
local BPRequests = is_loaded('modules.blueprint_requesting')
if BPRequests then
local Module = BPRequests.get()
switch_state = 'left'
if Module[player.index] and Module[player.index].disabled then
switch_state = 'right'
end
add_switch(scroll_pane, switch_state, 'blueprint_requesting', {'modules.blueprint_requesting'}, {'modules.blueprint_requesting_desc'})
scroll_pane.add({type = 'line'})
end
if BottomFrame.is_custom_buttons_enabled() then
label = scroll_pane.add({type = 'label', caption = 'Bottom Buttons Settings'})
label.style.font = 'default-bold'