mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Changed config/settings loop
- Fixed settings/entity loop should be faster now - Fixed floating text position overlapping - Added more comments
This commit is contained in:
@@ -6,38 +6,38 @@ return {
|
|||||||
icon = 'item/piercing-rounds-magazine', --- @setting icon that will be used for the toolbar
|
icon = 'item/piercing-rounds-magazine', --- @setting icon that will be used for the toolbar
|
||||||
entities = {
|
entities = {
|
||||||
['car'] = {
|
['car'] = {
|
||||||
{
|
[defines.inventory.fuel] = {
|
||||||
type = 'fuel',
|
type = 'fuel',
|
||||||
inventory = defines.inventory.fuel,
|
inventory = defines.inventory.fuel,
|
||||||
enabled = true
|
enabled = true
|
||||||
},
|
},
|
||||||
{
|
[defines.inventory.car_ammo] = {
|
||||||
type = 'ammo',
|
type = 'ammo',
|
||||||
inventory = defines.inventory.car_ammo,
|
inventory = defines.inventory.car_ammo,
|
||||||
enabled = true
|
enabled = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
['locomotive'] = {
|
['locomotive'] = {
|
||||||
{
|
[defines.inventory.fuel] = {
|
||||||
type = 'fuel',
|
type = 'fuel',
|
||||||
inventory = defines.inventory.fuel,
|
inventory = defines.inventory.fuel,
|
||||||
enabled = true
|
enabled = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
['tank'] = {
|
['tank'] = {
|
||||||
{
|
[defines.inventory.fuel] = {
|
||||||
type = 'fuel',
|
type = 'fuel',
|
||||||
inventory = defines.inventory.fuel,
|
inventory = defines.inventory.fuel,
|
||||||
enabled = true
|
enabled = true
|
||||||
},
|
},
|
||||||
{
|
[defines.inventory.car_ammo] = {
|
||||||
type = 'ammo',
|
type = 'ammo',
|
||||||
inventory = defines.inventory.car_ammo,
|
inventory = defines.inventory.car_ammo,
|
||||||
enabled = true
|
enabled = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
['gun-turret'] = {
|
['gun-turret'] = {
|
||||||
{
|
[defines.inventory.turret_ammo] = {
|
||||||
type = 'ammo',
|
type = 'ammo',
|
||||||
inventory = defines.inventory.turret_ammo,
|
inventory = defines.inventory.turret_ammo,
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|||||||
@@ -150,39 +150,50 @@ local function entity_build(event)
|
|||||||
if not entity_configs then
|
if not entity_configs then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
-- Get the inventory of the player
|
||||||
|
local player_inventory = player.get_main_inventory()
|
||||||
|
|
||||||
-- Loop over each entity config and try to furfill the request amount
|
local text_position = { x = entity.position.x, y = entity.position.y }
|
||||||
for _,entity_config in pairs(entity_configs) do
|
-- Loop over all possible item settings to insert into the entity
|
||||||
if not entity_config.enabled then
|
for _, setting in pairs(autofill_player_settings[player.name]) do
|
||||||
break
|
if not setting.enabled then
|
||||||
|
goto end_setting
|
||||||
end
|
end
|
||||||
local player_inventory = player.get_main_inventory()
|
-- Loop over possible inventories for this setting to put into the vehicle
|
||||||
local entity_inventory = entity.get_inventory(entity_config.inventory)
|
for _, inventory in pairs(setting.inventories) do
|
||||||
for _, setting in pairs(autofill_player_settings[player.name]) do
|
-- Check in the configs if the inventory type exists and is enabled for this vehicle
|
||||||
if not setting.enabled or not table.contains(setting.inventories, entity_config.inventory) then
|
if not entity_configs[inventory] or not entity_configs[inventory].enabled then
|
||||||
goto continue
|
goto end_inventory
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Get the inventory of the entity
|
||||||
|
local entity_inventory = entity.get_inventory(inventory)
|
||||||
|
if not entity_inventory then
|
||||||
|
goto end_inventory
|
||||||
|
end
|
||||||
|
|
||||||
local item = setting.item
|
local item = setting.item
|
||||||
local preferd_amount = setting.amount
|
local preferd_amount = setting.amount
|
||||||
local item_amount = player_inventory.get_item_count(item)
|
local item_amount = player_inventory.get_item_count(item)
|
||||||
if item_amount ~= 0 then
|
if item_amount ~= 0 then
|
||||||
local inserted
|
local inserted
|
||||||
|
text_position.y = text_position.y - 0.2
|
||||||
if item_amount >= preferd_amount then
|
if item_amount >= preferd_amount then
|
||||||
if not entity_inventory.can_insert({name=item, count=preferd_amount}) then
|
if not entity_inventory.can_insert({name=item, count=preferd_amount}) then
|
||||||
goto continue
|
goto end_inventory
|
||||||
end
|
end
|
||||||
inserted = entity_inventory.insert({name=item, count=preferd_amount})
|
inserted = entity_inventory.insert({name=item, count=preferd_amount})
|
||||||
player_inventory.remove({name=item, count=inserted})
|
player_inventory.remove({name=item, count=inserted})
|
||||||
print_text(entity.surface, entity.position, {'autofill.filled', rich_img('entity', entity.name), inserted, rich_img('item', item) }, { r = 0, g = 255, b = 0, a = 1})
|
print_text(entity.surface, text_position, {'autofill.filled', rich_img('entity', entity.name), inserted, rich_img('item', item) }, { r = 0, g = 255, b = 0, a = 1})
|
||||||
else
|
else
|
||||||
inserted = entity_inventory.insert({name=item, count=item_amount})
|
inserted = entity_inventory.insert({name=item, count=item_amount})
|
||||||
player_inventory.remove({name=item, count=inserted})
|
player_inventory.remove({name=item, count=inserted})
|
||||||
print_text(entity.surface, entity.position, {'autofill.filled', rich_img('entity', entity.name), inserted, rich_img('item', item) }, { r = 255, g = 165, b = 0, a = 1})
|
print_text(entity.surface, text_position, {'autofill.filled', rich_img('entity', entity.name), inserted, rich_img('item', item) }, { r = 255, g = 165, b = 0, a = 1})
|
||||||
end
|
end
|
||||||
goto continue
|
|
||||||
end
|
end
|
||||||
::continue::
|
::end_inventory::
|
||||||
end
|
end
|
||||||
|
::end_setting::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user