Добавлены все обновления от сообщества, вплоть до #148

This commit is contained in:
2024-09-12 14:28:43 +03:00
parent 98159766c4
commit 487a0e6e16
8841 changed files with 23077 additions and 20175 deletions

View File

@@ -0,0 +1,75 @@
---------------------------------------------------------------------------------------------------
Version: 1.2.1
Date: 2023-01-15
Changes:
- Consolidated both shortcuts into one (Alt + G by default), which will spawn the ghost counter selection tool when clicked, and use blueprint contents if the player is holding a blueprint in their cursor. The toolbar button will function similarly.
- Ghost counter GUI will now remember its last location on the screen.
---------------------------------------------------------------------------------------------------
Version: 1.2.0
Date: 2022-09-14
Features:
- Added ability to manually craft requests. You can attempt to manually craft a request by shift-clicking its blue request button. You can also attempt to manually craft all requests by clicking on the new toolbar button with the hammer icon.
---------------------------------------------------------------------------------------------------
Version: 1.1.9
Date: 2022-06-20
Bugfixes:
- Fixed a crash that would occur if you tried to count ghosts from a blueprint book in your inventory.
---------------------------------------------------------------------------------------------------
Version: 1.1.8
Date: 2022-06-12
Bugfixes:
- Fixed a crash that would occur if a monitored ghost was built or destroyed while the player was dead.
---------------------------------------------------------------------------------------------------
Version: 1.1.7
Date: 2022-04-14
Bugfixes:
- Fixed GUI appearing inappropriately when a player uses unrelated area selection tools.
---------------------------------------------------------------------------------------------------
Version: 1.1.6
Date: 2022-03-23
Features:
- Added support for entities marked for upgrade.
---------------------------------------------------------------------------------------------------
Version: 1.1.5
Date: 2021-11-01
Optimizations:
- Improved tile counting logic.
Gui:
- Improved temporary request button tooltips.
---------------------------------------------------------------------------------------------------
Version: 1.1.4
Date: 2021-10-31
Features:
- Added support for module requests in already-built entities when using the selection tool. Once all the module requests of an entity are fulfilled, the ghost count will be updated to reflect that.
---------------------------------------------------------------------------------------------------
Version: 1.1.3
Date: 2021-10-31
Features:
- Added support for exporting ghost counts as signals. Click on the button in the top left of the mod window to generate a blueprint with constant combinators, set to output the ghost counts.
Bugfixes:
- Fixed crash which could occur if you closed the ghost counter window while you still had pending temporary logistic requests, and then modified your logistic requests yourself or using a different mod.
- Fixed temporary logistic requests not immediately updating after selection of a new area or blueprint with pre-existing temporary requests.
---------------------------------------------------------------------------------------------------
Version: 1.1.2
Date: 2021-10-31
Bugfixes:
- Fixed crash in Space Exploration which could occur if you had the contents of your inventory or cursor change a few ticks before you turned on Navigation Satellite view.
---------------------------------------------------------------------------------------------------
Version: 1.1.1
Date: 2021-10-29
Features:
- Added a "Request all" button, which allows you to set temporary logistic requests for all the items that you're missing to complete your build. The red button next to it will cancel all of your temporary logistic requests and restore any previous ones you had for those items.
Bugfixes:
- Fixed issue that could cause temporary logistic requests to linger if an inventory change or ghost count change affected a large number of them.
- Fixed issue with new ghost area selections inconsistently modifying temporary logistic requests that you had set.
- Fixed mod GUI moving to its default position if you made a new ghost area selection while it was open.
---------------------------------------------------------------------------------------------------
Version: 1.1.0
Date: 2021-10-28
Features:
- Added support for blueprints. Press Ctrl + G while holding a blueprint to get ghost counts from there.
---------------------------------------------------------------------------------------------------
Version: 1.0.0
Date: 2021-10-26
Features:
- Initial release.

107
ghost-counter/control.lua Normal file
View File

@@ -0,0 +1,107 @@
mod_prefix = "ghost-counter-"
NAME = require("shared/constants")
require("scripts/core")
require("scripts/events")
require("scripts/gui")
---Creates all necessary global tables.
function on_init()
---@type table<uint, Playerdata> Table of all `playerdata` tables, indexed by `player_index`
global.playerdata = {}
---@type uint Last game tick where an event updated mod data
global.last_event = 0
---@type {min_update_interval: uint} Map settings table
global.settings = {min_update_interval=settings.global[NAME.setting.min_update_interval].value --[[@as uint]]}
---@type table<string, boolean> Contains registration status of different event handler groups
global.events = {inventory=false, logistics=false, nth_tick=false}
end
script.on_init(on_init)
---Re-setups conditional event handlers.
function on_load()
-- Inventory/entity event handlers
if global.events.inventory then
script.on_event(defines.events.on_player_main_inventory_changed,
on_player_main_inventory_changed)
script.on_event(defines.events.on_player_cursor_stack_changed,
on_player_main_inventory_changed)
script.on_event(defines.events.on_entity_destroyed, on_ghost_destroyed)
end
-- Logistics event handler
if global.events.logistics then
script.on_event(defines.events.on_entity_logistic_slot_changed,
on_entity_logistic_slot_changed)
end
-- nth_tick event handler
if global.events.nth_tick then
script.on_nth_tick(global.settings.min_update_interval, on_nth_tick)
end
end
script.on_load(on_load)
---Validates mod data.
function on_configuration_changed()
-- Validate `playerdata.job` table and contents
for _, playerdata in pairs(global.playerdata) do
playerdata.job = playerdata.job or {}
playerdata.job.area = playerdata.job.area or {}
playerdata.job.ghosts = playerdata.job.ghosts or {}
playerdata.job.requests = playerdata.job.requests or {}
playerdata.job.requests_sorted = playerdata.job.requests_sorted or {}
end
end
script.on_configuration_changed(on_configuration_changed)
---Re-registers event handlers if appropriate for joining player.
---@param event EventData.on_player_joined_game Event table
function on_player_joined_game(event)
local playerdata = get_make_playerdata(event.player_index)
if playerdata.is_active then register_inventory_monitoring(true) end
if playerdata.is_active or table_size(playerdata.logistic_requests) > 0 then
register_logistics_monitoring(true)
end
end
script.on_event(defines.events.on_player_joined_game, on_player_joined_game)
---Re-evaluates whether event handlers should continue to be bound.
---@param event EventData.on_player_left_game Event able
function on_player_left_game(event)
if not is_inventory_monitoring_needed() then register_inventory_monitoring(false) end
if not is_logistics_monitoring_needed() then register_logistics_monitoring(false) end
end
script.on_event(defines.events.on_player_left_game, on_player_left_game)
---Deletes playerdata table associated with removed player.
---@param event EventData.on_player_removed Event table
function on_player_removed(event)
global.playerdata[event.player_index] = nil
if not is_inventory_monitoring_needed() then register_inventory_monitoring(false) end
if not is_logistics_monitoring_needed() then register_logistics_monitoring(false) end
end
script.on_event(defines.events.on_player_removed, on_player_removed)
---Listens to runtime settings changes.
---@param event EventData.on_runtime_mod_setting_changed Event table
function on_runtime_mod_setting_changed(event)
if event.setting == NAME.setting.min_update_interval then
local new_value = settings.global[NAME.setting.min_update_interval].value --[[@as uint]]
-- Reregister on_nth_tick event handler using the new minimum interval
if global.events.nth_tick then
---@diagnostic disable-next-line
script.on_nth_tick(nil)
script.on_nth_tick(new_value, on_nth_tick)
end
global.settings.min_update_interval = new_value
end
end
script.on_event(defines.events.on_runtime_mod_setting_changed, on_runtime_mod_setting_changed)

107
ghost-counter/data.lua Normal file
View File

@@ -0,0 +1,107 @@
local NAME = require("shared/constants")
require("prototypes/style")
data:extend{
{
type = "selection-tool",
name = NAME.tool.ghost_counter,
subgroup = "tool",
selection_color = {57, 156, 251},
alt_selection_color = {0, 89, 132},
selection_mode = {"any-entity", "same-force"},
alt_selection_mode = {"any-entity", "same-force"},
selection_count_button_color = {43, 113, 180},
alt_selection_count_button_color = {43, 113, 180},
selection_cursor_box_type = "copy",
alt_selection_cursor_box_type = "copy",
stack_size = 1,
stackable = false,
flags = {"hidden", "only-in-cursor", "not-stackable", "spawnable"},
icon = "__ghost-counter__/graphics/ghost-small.png",
icon_size = 64
}, {
type = "shortcut",
name = NAME.shortcut.button,
localised_name = {"shortcut.make-ghost-counter"},
action = "lua",
icon = {
filename = "__ghost-counter__/graphics/ghost.png",
priority = "extra-high",
size = 64,
flags = {"gui-icon"}
},
associated_control_input = NAME.input.ghost_counter_selection,
style = "blue"
}, {
type = "custom-input",
name = NAME.input.ghost_counter_selection,
key_sequence = "ALT + G",
order = "a",
action = "lua"
}, {
type = "sprite",
name = NAME.sprite.get_signals_white,
filename = "__ghost-counter__/graphics/get-signals-white.png",
priority = "extra-high",
size = 64,
flags = {"gui-icon"},
scale = 0.5
}, {
type = "sprite",
name = NAME.sprite.get_signals_black,
filename = "__ghost-counter__/graphics/get-signals-black.png",
priority = "extra-high",
size = 64,
flags = {"gui-icon"},
scale = 0.5
}, {
type = "sprite",
name = NAME.sprite.hide_empty_white,
filename = "__ghost-counter__/graphics/hide-white.png",
priority = "extra-high",
size = 64,
flags = {"gui-icon"},
scale = 0.5
}, {
type = "sprite",
name = NAME.sprite.hide_empty_black,
filename = "__ghost-counter__/graphics/hide-black.png",
priority = "extra-high",
size = 64,
flags = {"gui-icon"},
scale = 0.5
}, {
type = "sprite",
name = NAME.sprite.craft_all_white,
filename = "__ghost-counter__/graphics/craft-white.png",
priority = "extra-high",
size = 64,
flags = {"gui-icon"},
scale = 0.5
}, {
type = "sprite",
name = NAME.sprite.craft_all_black,
filename = "__ghost-counter__/graphics/craft-black.png",
priority = "extra-high",
size = 64,
flags = {"gui-icon"},
scale = 0.5
}, {
type = "sprite",
name = NAME.sprite.cancel_white,
filename = "__ghost-counter__/graphics/cancel-white.png",
priority = "extra-high",
size = 64,
flags = {"gui-icon"},
scale = 0.5
}, {
type = "sprite",
name = NAME.sprite.cancel_black,
filename = "__ghost-counter__/graphics/cancel-black.png",
priority = "extra-high",
size = 64,
flags = {"gui-icon"},
scale = 0.5
}
}

View File

@@ -0,0 +1,32 @@
---Contains all information pertaining to a player.
---@class Playerdata
---@field index uint Player index
---@field luaplayer LuaPlayer
---@field is_active boolean Is player gui open
---@field job Job Contains item requests for current job
---@field logistic_requests table<string, LogisticRequest> Active temporary logistic requests indexed by item name
---@field gui table Contains references to gui elements
---@field options table Player options
---Contains details of ghosts and requests currently being tracked by player.
---@class Job
---@field area BoundingBox|nil Area selected by player, if any
---@field ghosts table<uint, table> Table linking each ghost `unit_number to associated requests
---@field requests table<string, Request> Table of requests, indexed by item name
---@field requests_sorted Request[] Array of requests, sorted by required item count
---Contains details of an item request, including inventory and logistic request counts.
---@class Request
---@field name string Item name
---@field count uint Number of item needed
---@field inventory uint Number of item currently in inventory
---@field logistic_request table Existing logistic request for item, empty if none
---Contains record of temporary logistic request set by player, with details of any prior logistic
---request for that item, to be restored when appropriate.
---@class LogisticRequest
---@field slot_index uint Slot index of the logistic request
---@field old_min uint Old minimum value
---@field old_max uint|nil Old maximum value, if any
---@field new_min uint New minimum value
---@field is_new boolean Transiently set to true after GC has made a deliberate change to a logistic slot, in order for the relevant event handler to ignore it

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

13
ghost-counter/info.json Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "ghost-counter",
"version": "1.2.1",
"title": "Ghost Counter",
"author": "Inappropriate Penguin",
"homepage": "https://github.com/InappropriatePenguin/ghost-counter",
"dependencies": [
"base >= 1.1.42"
],
"description": "Generate a list of all ghosts in your selection area or blueprint. Find out what you have in your inventory, and conveniently make one-time logistic requests for everything you need.",
"factorio_version": "1.1"
}

402
ghost-counter/license.txt Normal file
View File

@@ -0,0 +1,402 @@
Attribution-NonCommercial-NoDerivatives 4.0 International
=======================================================================
Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.
Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.
Considerations for licensors: Our public licenses are
intended for use by those authorized to give the public
permission to use material in ways otherwise restricted by
copyright and certain other rights. Our licenses are
irrevocable. Licensors should read and understand the terms
and conditions of the license they choose before applying it.
Licensors should also secure all rights necessary before
applying our licenses so that the public can reuse the
material as expected. Licensors should clearly mark any
material not subject to the license. This includes other CC-
licensed material, or material used under an exception or
limitation to copyright. More considerations for licensors:
wiki.creativecommons.org/Considerations_for_licensors
Considerations for the public: By using one of our public
licenses, a licensor grants the public permission to use the
licensed material under specified terms and conditions. If
the licensor's permission is not necessary for any reason--for
example, because of any applicable exception or limitation to
copyright--then that use is not regulated by the license. Our
licenses grant only permissions under copyright and certain
other rights that a licensor has authority to grant. Use of
the licensed material may still be restricted for other
reasons, including because others have copyright or other
rights in the material. A licensor may make special requests,
such as asking that all changes be marked or described.
Although not required by our licenses, you are encouraged to
respect those requests where reasonable. More considerations
for the public:
wiki.creativecommons.org/Considerations_for_licensees
=======================================================================
Creative Commons Attribution-NonCommercial-NoDerivatives 4.0
International Public License
By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution-NonCommercial-NoDerivatives 4.0 International Public
License ("Public License"). To the extent this Public License may be
interpreted as a contract, You are granted the Licensed Rights in
consideration of Your acceptance of these terms and conditions, and the
Licensor grants You such rights in consideration of benefits the
Licensor receives from making the Licensed Material available under
these terms and conditions.
Section 1 -- Definitions.
a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is always produced where the Licensed Material is
synched in timed relation with a moving image.
b. Copyright and Similar Rights means copyright and/or similar rights
closely related to copyright including, without limitation,
performance, broadcast, sound recording, and Sui Generis Database
Rights, without regard to how the rights are labeled or
categorized. For purposes of this Public License, the rights
specified in Section 2(b)(1)-(2) are not Copyright and Similar
Rights.
c. Effective Technological Measures means those measures that, in the
absence of proper authority, may not be circumvented under laws
fulfilling obligations under Article 11 of the WIPO Copyright
Treaty adopted on December 20, 1996, and/or similar international
agreements.
d. Exceptions and Limitations means fair use, fair dealing, and/or
any other exception or limitation to Copyright and Similar Rights
that applies to Your use of the Licensed Material.
e. Licensed Material means the artistic or literary work, database,
or other material to which the Licensor applied this Public
License.
f. Licensed Rights means the rights granted to You subject to the
terms and conditions of this Public License, which are limited to
all Copyright and Similar Rights that apply to Your use of the
Licensed Material and that the Licensor has authority to license.
g. Licensor means the individual(s) or entity(ies) granting rights
under this Public License.
h. NonCommercial means not primarily intended for or directed towards
commercial advantage or monetary compensation. For purposes of
this Public License, the exchange of the Licensed Material for
other material subject to Copyright and Similar Rights by digital
file-sharing or similar means is NonCommercial provided there is
no payment of monetary compensation in connection with the
exchange.
i. Share means to provide material to the public by any means or
process that requires permission under the Licensed Rights, such
as reproduction, public display, public performance, distribution,
dissemination, communication, or importation, and to make material
available to the public including in ways that members of the
public may access the material from a place and at a time
individually chosen by them.
j. Sui Generis Database Rights means rights other than copyright
resulting from Directive 96/9/EC of the European Parliament and of
the Council of 11 March 1996 on the legal protection of databases,
as amended and/or succeeded, as well as other essentially
equivalent rights anywhere in the world.
k. You means the individual or entity exercising the Licensed Rights
under this Public License. Your has a corresponding meaning.
Section 2 -- Scope.
a. License grant.
1. Subject to the terms and conditions of this Public License,
the Licensor hereby grants You a worldwide, royalty-free,
non-sublicensable, non-exclusive, irrevocable license to
exercise the Licensed Rights in the Licensed Material to:
a. reproduce and Share the Licensed Material, in whole or
in part, for NonCommercial purposes only; and
b. produce and reproduce, but not Share, Adapted Material
for NonCommercial purposes only.
2. Exceptions and Limitations. For the avoidance of doubt, where
Exceptions and Limitations apply to Your use, this Public
License does not apply, and You do not need to comply with
its terms and conditions.
3. Term. The term of this Public License is specified in Section
6(a).
4. Media and formats; technical modifications allowed. The
Licensor authorizes You to exercise the Licensed Rights in
all media and formats whether now known or hereafter created,
and to make technical modifications necessary to do so. The
Licensor waives and/or agrees not to assert any right or
authority to forbid You from making technical modifications
necessary to exercise the Licensed Rights, including
technical modifications necessary to circumvent Effective
Technological Measures. For purposes of this Public License,
simply making modifications authorized by this Section 2(a)
(4) never produces Adapted Material.
5. Downstream recipients.
a. Offer from the Licensor -- Licensed Material. Every
recipient of the Licensed Material automatically
receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this
Public License.
b. No downstream restrictions. You may not offer or impose
any additional or different terms or conditions on, or
apply any Effective Technological Measures to, the
Licensed Material if doing so restricts exercise of the
Licensed Rights by any recipient of the Licensed
Material.
6. No endorsement. Nothing in this Public License constitutes or
may be construed as permission to assert or imply that You
are, or that Your use of the Licensed Material is, connected
with, or sponsored, endorsed, or granted official status by,
the Licensor or others designated to receive attribution as
provided in Section 3(a)(1)(A)(i).
b. Other rights.
1. Moral rights, such as the right of integrity, are not
licensed under this Public License, nor are publicity,
privacy, and/or other similar personality rights; however, to
the extent possible, the Licensor waives and/or agrees not to
assert any such rights held by the Licensor to the limited
extent necessary to allow You to exercise the Licensed
Rights, but not otherwise.
2. Patent and trademark rights are not licensed under this
Public License.
3. To the extent possible, the Licensor waives any right to
collect royalties from You for the exercise of the Licensed
Rights, whether directly or through a collecting society
under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly
reserves any right to collect such royalties, including when
the Licensed Material is used other than for NonCommercial
purposes.
Section 3 -- License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the
following conditions.
a. Attribution.
1. If You Share the Licensed Material, You must:
a. retain the following if it is supplied by the Licensor
with the Licensed Material:
i. identification of the creator(s) of the Licensed
Material and any others designated to receive
attribution, in any reasonable manner requested by
the Licensor (including by pseudonym if
designated);
ii. a copyright notice;
iii. a notice that refers to this Public License;
iv. a notice that refers to the disclaimer of
warranties;
v. a URI or hyperlink to the Licensed Material to the
extent reasonably practicable;
b. indicate if You modified the Licensed Material and
retain an indication of any previous modifications; and
c. indicate the Licensed Material is licensed under this
Public License, and include the text of, or the URI or
hyperlink to, this Public License.
For the avoidance of doubt, You do not have permission under
this Public License to Share Adapted Material.
2. You may satisfy the conditions in Section 3(a)(1) in any
reasonable manner based on the medium, means, and context in
which You Share the Licensed Material. For example, it may be
reasonable to satisfy the conditions by providing a URI or
hyperlink to a resource that includes the required
information.
3. If requested by the Licensor, You must remove any of the
information required by Section 3(a)(1)(A) to the extent
reasonably practicable.
Section 4 -- Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
to extract, reuse, reproduce, and Share all or a substantial
portion of the contents of the database for NonCommercial purposes
only and provided You do not Share Adapted Material;
b. if You include all or a substantial portion of the database
contents in a database in which You have Sui Generis Database
Rights, then the database in which You have Sui Generis Database
Rights (but not its individual contents) is Adapted Material; and
c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
c. The disclaimer of warranties and limitation of liability provided
above shall be interpreted in a manner that, to the extent
possible, most closely approximates an absolute disclaimer and
waiver of all liability.
Section 6 -- Term and Termination.
a. This Public License applies for the term of the Copyright and
Similar Rights licensed here. However, if You fail to comply with
this Public License, then Your rights under this Public License
terminate automatically.
b. Where Your right to use the Licensed Material has terminated under
Section 6(a), it reinstates:
1. automatically as of the date the violation is cured, provided
it is cured within 30 days of Your discovery of the
violation; or
2. upon express reinstatement by the Licensor.
For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
of this Public License.
c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.
Section 7 -- Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different
terms or conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the
Licensed Material not stated herein are separate from and
independent of the terms and conditions of this Public License.
Section 8 -- Interpretation.
a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the provision
cannot be reformed, it shall be severed from this Public License
without affecting the enforceability of the remaining terms and
conditions.
c. No term or condition of this Public License will be waived and no
failure to comply consented to unless expressly agreed to by the
Licensor.
d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.
=======================================================================
Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.
Creative Commons may be contacted at creativecommons.org.

View File

@@ -0,0 +1,32 @@
[mod-setting-name]
ghost-counter-min-update-interval=Minimum update interval
[mod-setting-description]
ghost-counter-min-update-interval=Minimum number of ticks between mod data updates. Lower numbers allow the mod UI to update more frequently. Increase this number if you want to minimize any performance impact. Default: 10 [5120].
[shortcut]
make-ghost-counter=Ghost Counter
[controls]
ghost-counter-selection-hotkey=Activate ghost counter
[item-name]
ghost-counter-tool=Ghost Counter selection tool
[ghost-counter-message]
failed-to-clear-cursor=Failed to clear cursor.
crafts-attempted-none=Unable to craft item
crafts-not-needed=No additional crafts needed
missing-constant-combinator-prototype=Couldn't find constant-combinator in game entity prototypes.
[ghost-counter-gui]
cancel-all-tooltip=Cancel all temporary logistic requests
close-button-tooltip=Close window
existing-logistic-request-tooltip=Existing logistic request meets requirement
get-signals-tooltip=Export ghost counts as signals
hide-empty-requests-tooltip=Toggle hiding rows with no remaining ghosts
craft-all-tooltip=Attempt to craft all missing items
request-all-caption=Request all
request-all-tooltip=Create temporary logistic requests for all missing items
set-temporary-request-tooltip=__CONTROL_LEFT_CLICK__ to create a temporary logistic request for __1__ __2__\n__CONTROL_KEY_SHIFT____CONTROL_STYLE_BEGIN__ + __CONTROL_STYLE_END____CONTROL_LEFT_CLICK__ to craft
unset-temporary-request-tooltip=__CONTROL_LEFT_CLICK__ to cancel temporary logistic request\n__CONTROL_KEY_SHIFT____CONTROL_STYLE_BEGIN__ + __CONTROL_STYLE_END____CONTROL_LEFT_CLICK__ to craft

View File

@@ -0,0 +1,146 @@
local NAME = require("shared/constants")
local guistyle = data.raw["gui-style"]["default"]
guistyle[NAME.style.root_frame] = {type="frame_style", width=422}
guistyle[NAME.style.titlebar_flow] = {type="horizontal_flow_style", horizontal_spacing=6}
guistyle[NAME.style.titlebar_space_header] = {
type = "empty_widget_style",
parent = "draggable_space_header",
height = 24,
horizontally_stretchable = "on",
left_margin = 4,
right_margin = 4
}
guistyle[NAME.style.titlebar_button] = {type="button_style", parent="frame_action_button"}
guistyle[NAME.style.titlebar_button_active] = {
type = "button_style",
parent = "frame_action_button",
default_graphical_set = guistyle["frame_button"].clicked_graphical_set,
clicked_graphical_set = guistyle["frame_button"].default_graphical_set
}
guistyle[NAME.style.inside_deep_frame] = {
type = "frame_style",
parent = "inside_deep_frame",
horizontally_stretchable = "stretch_and_expand",
vertically_stretchable = "stretch_and_expand",
vertical_flow_style = {type = "vertical_flow_style", vertical_spacing = 0}
}
guistyle[NAME.style.topbar_frame] = {
type = "frame_style",
parent = "subheader_frame",
top_padding = 6,
bottom_padding = 0,
left_padding = 6,
right_padding = 6,
height = 40,
horizontally_stretchable = "stretch_and_expand",
horizontal_flow_style = {
type = "horizontal_flow_style",
height = 28,
vertical_align = "center",
horizontal_align = "left"
}
}
guistyle[NAME.style.get_signals_button] = {
type = "button_style",
parent = NAME.style.ghost_request_button,
padding = 2,
width = 28,
height = 28
}
guistyle[NAME.style.topbar_space] = {
type = "empty_widget_style",
height = 24,
horizontally_stretchable = "on",
left_margin = 4,
right_margin = 4
}
guistyle[NAME.style.ghost_request_all_button] = {
type = "button_style",
parent = NAME.style.ghost_request_button,
minimal_width = 100,
height = 28
}
guistyle[NAME.style.ghost_cancel_all_button] = {
type = "button_style",
parent = "slot_sized_button_red",
padding = 2,
height = 28,
width = 28
}
guistyle[NAME.style.scroll_pane] = {
type = "scroll_pane_style",
parent = "scroll_pane",
padding = 2,
extra_padding_when_activated = 0,
extra_margin_when_activated = 0,
maximal_height = 500,
horizontally_stretchable = "stretch_and_expand",
vertically_stretchable = "stretch_and_expand",
vertical_flow_style = {type="vertical_flow_style", vertical_spacing=0}
}
guistyle[NAME.style.row_frame] = {
type = "frame_style",
horizontally_stretchable = "stretch_and_expand",
height = 32,
top_padding = 0,
bottom_padding = 0,
right_padding = 0,
vertical_align = "center",
horizontal_flow_style = {
type = "horizontal_flow_style",
horizontal_spacing = 8,
vertical_align = "center",
vertically_stretchable = "stretch_and_expand"
}
}
guistyle[NAME.style.ghost_number_label] = {type="label_style", width=40, horizontal_align="right"}
guistyle[NAME.style.ghost_sprite] = {type="image_style", width=20, height=20}
guistyle[NAME.style.ghost_name_label] = {type="label_style", width=180}
guistyle[NAME.style.inventory_number_label] = {
type = "label_style",
parent = NAME.style.ghost_number_label,
font_color = {0.6, 0.6, 0.6}
}
guistyle[NAME.style.ghost_request_button] = {
type = "button_style",
parent = "slot_sized_button_blue",
size = {50, 24},
default_font_color = {1, 1, 1},
vertically_stretchable = "stretch_and_expand"
}
guistyle[NAME.style.ghost_request_active_button] = {
type = "button_style",
parent = NAME.style.ghost_request_button,
default_font_color = {0, 0, 0},
clicked_font_color = {1, 1, 1},
default_graphical_set = guistyle["tool_button_blue"].clicked_graphical_set,
clicked_graphical_set = guistyle["tool_button_blue"].default_graphical_set
}
guistyle[NAME.style.ghost_request_fulfilled_flow] = {
type = "horizontal_flow_style",
size = {50, 24},
horizontal_align = "center",
vertical_align = "center"
}
guistyle[NAME.style.ghost_request_fulfilled_sprite] = {type="image_style", size={20, 20}}

27
ghost-counter/readme.md Normal file
View File

@@ -0,0 +1,27 @@
![Mod thumbnail](/thumbnail.png)
# Ghost Counter
A [Factorio](https://factorio.com) mod that allows you to select an area and conveniently get a list
of all the ghost entities and tiles within that area, sorted by count. The mod will also show you
how many of each item/tile you currently have in your inventory and how many you're missing. For
each item/tile that you're missing, you can set a temporary logistic request for the amount you
need. Your previous logistic request (if any) will be restored once that request has been
fulfilled.
Activate the Ghost Counter tool by clicking on the ghost shortcut button in your shortcut bar or by using
the keyboard shortcut (default: Alt+G). Next, select the area containing the ghosts that you want
to count. Holding shift during selection will include ghost tiles in the count.
You can use the tool directly on blueprints by activating it while holding a blueprint in your cursor.
You can download it from the Factorio
[Mod Portal](https://mods.factorio.com/mod/ghost-counter).
## Credits
Ghost by Andres Flores from the Noun Project
hide by Adrien Coquet from the Noun Project
wave by Stephen Plaster from the Noun Project
cancel by Bluetip Design from the Noun Project
Hammer by Deemak Daksina from the Noun Project

View File

@@ -0,0 +1,645 @@
---Gets or makes playerdata table.
---@param player_index uint LuaPlayer index
---@return Playerdata playerdata
function get_make_playerdata(player_index)
local playerdata = global.playerdata[player_index]
if not playerdata then
playerdata = {
luaplayer=game.players[player_index],
index=player_index,
is_active=false,
job={},
logistic_requests={},
gui={},
options={}
}
global.playerdata[player_index] = playerdata
end
return playerdata
end
---Returns an empty request table for the given item.
---@param name string Item name
---@return Request request
function make_empty_request(name)
return {name=name, count=0, inventory=0, logistic_request={}}
end
---Sorts a table of `Request` objects by count, in descending order.
---@param requests table<string, Request> Table of requests to be sorted
---@return Request[] requests_sorted
function sort_requests(requests)
local requests_sorted = {}
for _, request in pairs(requests) do table.insert(requests_sorted, request) end
table.sort(requests_sorted, function(a, b)
if a.count > b.count then
return true
elseif a.count < b.count then
return false
elseif a.name < b.name then
return true
else
return false
end
end)
return requests_sorted
end
---Iterates over passed entities and counts items needed to build all ghost entities and tiles.
---@param entities LuaEntity[] table of entities
---@param ignore_tiles boolean Determines whether ghost tiles are counted
---@return table<uint, LuaEntity> ghosts table of actual ghost entities/tiles
---@return table requests table of requests, indexed by request name
function get_selection_counts(entities, ignore_tiles)
local ghosts, requests = {}, {}
local cache = {}
-- Iterate over entities and filter out anything that's not a ghost
local insert = table.insert
for _, entity in pairs(entities) do
local entity_type = entity.type
if entity_type == "entity-ghost" or (entity_type == "tile-ghost" and not ignore_tiles) then
local ghost_name = entity.ghost_name
local unit_number = entity.unit_number --[[@as uint]]
-- Get item to place entity, from prototype if necessary
if not cache[ghost_name] then
local prototype = entity_type == "entity-ghost" and
game.entity_prototypes[ghost_name] or
game.tile_prototypes[ghost_name]
cache[ghost_name] = {
item=prototype.items_to_place_this and prototype.items_to_place_this[1] or nil
}
end
ghosts[unit_number] = {}
-- If entity is associated with item, increment request for that item by `item.count`
local item = cache[ghost_name].item
if item then
requests[item.name] = requests[item.name] or make_empty_request(item.name)
requests[item.name].count = requests[item.name].count + item.count
insert(ghosts[unit_number], item)
end
-- If entity has module requests, increment request for each module type
local item_requests = entity_type == "entity-ghost" and entity.item_requests or nil
if item_requests and table_size(item_requests) > 0 then
for name, val in pairs(item_requests) do
requests[name] = requests[name] or make_empty_request(name)
requests[name].count = requests[name].count + val
insert(ghosts[unit_number], {name=name, count=val})
end
end
script.register_on_entity_destroyed(entity)
elseif entity_type == "item-request-proxy" then
local unit_number = entity.unit_number --[[@as uint]]
ghosts[unit_number] = {}
for name, val in pairs(entity.item_requests) do
requests[name] = requests[name] or make_empty_request(name)
requests[name].count = requests[name].count + val
insert(ghosts[unit_number], {name=name, count=val})
end
script.register_on_entity_destroyed(entity)
elseif entity.to_be_upgraded() then
local unit_number = entity.unit_number --[[@as uint]]
local prototype = entity.get_upgrade_target() --[[@as LuaEntityPrototype]]
local ghost_name = prototype.name
-- Get item to place entity, from prototype if necessary
if not cache[ghost_name] then
cache[ghost_name] = {
item=prototype.items_to_place_this and prototype.items_to_place_this[1] or nil
}
end
ghosts[unit_number] = {}
-- If entity is associated with item, increment request for that item by `item.count`
local item = cache[ghost_name].item
if item then
requests[item.name] = requests[item.name] or make_empty_request(item.name)
requests[item.name].count = requests[item.name].count + item.count
insert(ghosts[unit_number], item)
end
script.register_on_entity_destroyed(entity)
end
end
return ghosts, requests
end
---Returns the blueprint tiles contained within a given item stack.
---@param item_stack LuaItemStack Must be a blueprint or a blueprint-book
---@return Tile[] tiles
function get_blueprint_tiles(item_stack)
if item_stack.is_blueprint_book then
local inventory = item_stack.get_inventory(defines.inventory.item_main) --[[@as LuaInventory]]
return get_blueprint_tiles(inventory[item_stack.active_index])
else
return (item_stack.get_blueprint_tiles() or {})
end
end
---Processes blueprint entities and tiles to generate item request counts.
---@param entities table array of blueprint entities
---@param tiles table array of blueprint tiles
---@return table requests
function get_blueprint_counts(entities, tiles)
local requests = {}
local cache = {}
-- Iterate over blueprint entities
for _, entity in pairs(entities) do
if not cache[entity.name] then
local prototype = game.entity_prototypes[entity.name]
cache[entity.name] = {
item=prototype.items_to_place_this and prototype.items_to_place_this[1] or nil
}
end
-- If entity is associated with item, increment request for that item by `item.count`
local item = cache[entity.name].item
if item then
requests[item.name] = requests[item.name] or make_empty_request(item.name)
requests[item.name].count = requests[item.name].count + item.count
end
-- If entity has module requests, increment request for each module type
local item_requests = entity.items
if item_requests and table_size(item_requests) > 0 then
for name, val in pairs(item_requests) do
requests[name] = requests[name] or make_empty_request(name)
requests[name].count = requests[name].count + val
end
end
end
-- Iterate over blueprint tiles
for _, tile in pairs(tiles) do
if not cache[tile.name] then
local prototype = game.tile_prototypes[tile.name]
cache[tile.name] = {
item=prototype.items_to_place_this and prototype.items_to_place_this[1] or nil
}
end
-- If tile is associated with item, increment request for that item by `item.count`
local item = cache[tile.name].item
if item then
requests[item.name] = requests[item.name] or make_empty_request(item.name)
requests[item.name].count = requests[item.name].count + item.count
end
end
return requests
end
---Converts a given player's `Request` table to signals out of a series of constant combinators.
---@param player_index uint Player index
function make_combinators_blueprint(player_index)
local playerdata = get_make_playerdata(player_index)
-- Make sure constant combinator prototype exists
local prototype = game.entity_prototypes["constant-combinator"]
if not prototype then
playerdata.luaplayer.print({"ghost-counter-message.missing-constant-combinator-prototype"})
return
end
local n_slots = prototype.item_slot_count
local requests = playerdata.job.requests_sorted
local request_index = 1
local combinators = {}
-- Iterate over the number of constant combinators we will need
for i = 1, math.ceil(#requests / n_slots) do
combinators[i] = {
entity_number=i,
name="constant-combinator",
position={i - 0.5, 0},
direction=4,
control_behavior={filters={}},
connections={{}}
}
local filters = combinators[i].control_behavior.filters
-- Set the combinator slots to the ghost request counts
for j = 1, n_slots do
local request = requests[request_index]
filters[j] = {signal={type="item", name=request.name}, count=request.count, index=j}
-- Increment request index; break if no more requests are left
request_index = request_index + 1
if request_index > #requests then break end
end
end
-- Wire up the combinators to one another
if #combinators > 1 then
for i = 1, (#combinators - 1) do
local connections = combinators[i].connections[1]
connections["green"] = {{entity_id=i + 1}}
connections["red"] = {{entity_id=i + 1}}
end
end
-- Try to clear the cursor
local is_successful = playerdata.luaplayer.clear_cursor()
if is_successful then
playerdata.luaplayer.cursor_stack.set_stack("blueprint")
playerdata.luaplayer.cursor_stack.set_blueprint_entities(combinators)
else
playerdata.luaplayer.print({"ghost-counter-message.failed-to-clear-cursor"})
end
end
---Deletes requests with zero ghosts from the `job.requests` table.
---@param player_index uint Player index
function remove_empty_requests(player_index)
local playerdata = get_make_playerdata(player_index)
for name, request in pairs(playerdata.job.requests) do
if request.count <= 0 then playerdata.job.requests[name] = nil end
end
end
---Updates table of `Request`s with inventory and cursor stack contents.
---@param player_index uint Player index
function update_inventory_info(player_index)
local playerdata = get_make_playerdata(player_index)
local cursor_stack = playerdata.luaplayer.cursor_stack
local inventory = playerdata.luaplayer.get_main_inventory()
local contents = inventory and inventory.get_contents() or {}
local requests = playerdata.job.requests
-- Iterate over each request and get the count in inventory
for name, request in pairs(requests) do request.inventory = contents[name] or 0 end
-- Add cursor contents to request count
if cursor_stack and cursor_stack.valid_for_read and requests[cursor_stack.name] then
local request = requests[cursor_stack.name]
request.inventory = request.inventory + cursor_stack.count
end
end
---Updates table of `Request`s with the player's current logistic requests.
---@param player_index uint Player index
function update_logistics_info(player_index)
local playerdata = get_make_playerdata(player_index)
local requests = playerdata.job.requests
-- Get player character
local character = playerdata.luaplayer.character
if not character then return end
-- Iterate over each logistic slot and update request table with logistic request details
local logistic_requests = {}
for i = 1, character.request_slot_count do
local slot = playerdata.luaplayer.get_personal_logistic_slot(i --[[@as uint]])
if requests[slot.name] then
requests[slot.name].logistic_request = {slot_index=i, min=slot.min, max=slot.max}
logistic_requests[slot.name] = true
end
end
-- Clear the `logistic_request` table of the request if one was not found
for _, request in pairs(playerdata.job.requests) do
if not logistic_requests[request.name] then request.logistic_request = {} end
end
end
---Iterates over one-time requests table and restores old requests if they have been fulfilled.
---@param player_index uint Player index
function update_one_time_logistic_requests(player_index)
local playerdata = get_make_playerdata(player_index)
if not playerdata.luaplayer.character then return end
local inventory = playerdata.luaplayer.get_main_inventory() --[[@as LuaInventory]]
-- Iterate over one-time requests table and restore old requests if they have been fulfilled
for name, logi_req in pairs(playerdata.logistic_requests) do
local request = playerdata.job.requests[name]
local slot = playerdata.luaplayer.get_personal_logistic_slot(logi_req.slot_index)
if request then
-- Update logistic request to reflect new ghost count
if slot.min ~= request.count then
local new_slot = {name=name, min=request.count}
logi_req.new_min = request.count
logi_req.is_new = true
playerdata.luaplayer.set_personal_logistic_slot(logi_req.slot_index, new_slot)
end
-- Restore prior request (if any) if one-time request has been fulfilled
if (inventory.get_item_count(name) >= logi_req.new_min) or
(logi_req.new_min <= (logi_req.old_min or 0)) then
restore_prior_logistic_request(player_index, name)
end
end
end
end
---Iterates over player's logistic slots and returns the first empty slot. Player _must_ have a
---character entity.
---@param player_index uint Player index
---@return uint? slot_index First empty slot
function get_first_empty_slot(player_index)
local playerdata = get_make_playerdata(player_index)
local character = playerdata.luaplayer.character --[[@as LuaEntity]]
for slot_index = 1, character.request_slot_count + 1 do
---@cast slot_index uint
local slot = playerdata.luaplayer.get_personal_logistic_slot(slot_index)
if slot.name == nil then return slot_index end
end
end
---Gets a table with details of any existing logistic request for a given item.
---@param player_index uint Player index
---@param name string Item name
---@return table|nil logistic_request
function get_existing_logistic_request(player_index, name)
local playerdata = get_make_playerdata(player_index)
local character = playerdata.luaplayer.character
if not character then return nil end
for i = 1, character.request_slot_count do
---@cast i uint
local slot = playerdata.luaplayer.get_personal_logistic_slot(i)
if slot and slot.name == name then
return {slot_index=i, name=slot.name, min=slot.min, max=slot.max}
end
end
end
---Generates a logistic request or modifies an existing request to satisfy need. Registers the
---change in a `playerdata.logistic_requests` table so that it can be reverted later on.
---@param player_index uint Player index
---@param name string `request` name
function make_one_time_logistic_request(player_index, name)
-- Abort if no player character
local playerdata = get_make_playerdata(player_index)
if not playerdata.luaplayer.character then return end
-- Abort if player already has more of item in inventory than needed
local request = playerdata.job.requests[name]
if not request or request.inventory >= request.count then return end
-- Get any existing request and abort if it would already meet need
local existing_request = get_existing_logistic_request(player_index, request.name) or {}
if (existing_request.min or 0) >= request.count then return end
-- Prepare new logistic slot and get existing or first empty `slot_index`
local new_slot = {name=request.name, min=request.count}
local slot_index = existing_request.slot_index or get_first_empty_slot(player_index)
if not slot_index then return end
-- Save details of change in playerdata so that it can be reverted later
-- This is set here in order for the event handler to be able to identify this change
-- as originating from the mod and to ignore it.
playerdata.logistic_requests[request.name] = {
slot_index=slot_index,
old_min=existing_request.min,
old_max=existing_request.max,
new_min=request.count,
is_new=true
}
-- Actually modify personal logistic slot
local is_successful = playerdata.luaplayer.set_personal_logistic_slot(slot_index, new_slot)
if is_successful then
-- Update request's `logistic_request` table
request.logistic_request.slot_index = slot_index
request.logistic_request.min = request.count
request.logistic_request.max = nil
playerdata.has_updates = true
register_update(player_index, game.tick)
else
-- Delete record of temporary request as it didn't go through
playerdata.logistic_requests[request.name] = nil
end
end
---Restores the prior logistic request (if any) that was in place before the one-time request was
---made.
---@param player_index uint Player index
---@param name string Item name
function restore_prior_logistic_request(player_index, name)
local playerdata = get_make_playerdata(player_index)
if not playerdata.luaplayer.character then return end
local request = playerdata.logistic_requests[name]
local slot
-- Either clear or reset slot using old request values
if request.old_min or request.old_max then
slot = {name=name, min=request.old_min, max=request.old_max}
playerdata.luaplayer.set_personal_logistic_slot(request.slot_index, slot)
else
playerdata.luaplayer.clear_personal_logistic_slot(request.slot_index)
end
if playerdata.job.requests[name] then
if slot then
playerdata.job.requests[name].logistic_request = {
slot_index=request.slot_index,
min=slot.min,
max=slot.max
}
else
playerdata.job.requests[name].logistic_request = {}
end
end
end
---Iterates over `playerdata.logistic_requests` to get rid of them.
---@param player_index uint Player index
function cancel_all_one_time_requests(player_index)
local playerdata = get_make_playerdata(player_index)
for name, _ in pairs(playerdata.logistic_requests) do
restore_prior_logistic_request(player_index, name)
end
end
---Returns the yield of a given item from a single craft of a given recipe.
---@param item_name string Item name
---@param recipe LuaRecipePrototype Recipe prototype
---@return number
function get_yield_per_craft(item_name, recipe)
local yield = 0
for _, product in pairs(recipe.products) do
if product.name == item_name then
local probability = product.probability or 1
yield = (product.amount) and (product.amount * probability) or
((product.amount_min + product.amount_max) * 0.5 * probability)
break
end
end
return yield
end
---Returns the number of times an item is set to be produced by a given character, taking into
---account their crafting queue contents.
---@param character LuaEntity Character entity
---@param item_name string Name of item to craft
---@return uint item_count
function get_item_count_from_character_crafting_queue(character, item_name)
if character.crafting_queue_size == 0 then return 0 end
local relevant_recipes = game.get_filtered_recipe_prototypes{
{filter="has-product-item", elem_filters={{filter="name", name=item_name}}},
{filter="hidden-from-player-crafting", invert=true, mode="and"}
}
local unique_recipes = {} --[[@as table<string, uint>]]
local item_count = 0
-- Create a list of unique and relevant recipes in the crafting queue
for _, queue_item in pairs(character.crafting_queue) do
local recipe_name = queue_item.recipe
if not queue_item.prerequisite and (unique_recipes[recipe_name] or relevant_recipes[recipe_name]) then
unique_recipes[recipe_name] = (unique_recipes[recipe_name] or 0) + queue_item.count
end
end
-- Count number of `name` items that will ultimately be produced by recipes in crafting queue
for recipe_name, n_crafts in pairs(unique_recipes) do
local yield_per_craft = get_yield_per_craft(item_name, relevant_recipes[recipe_name])
item_count = item_count + math.floor(yield_per_craft * n_crafts)
end
return item_count --[[@as uint]]
end
---Crafts a given item; amount to craft based on the corresponding request for that item.
---@param player_index uint Player index
---@param request Request Request data
---@return "no-character"|"no-crafts-needed"|"attempted" result
---@return uint? items_crafted Number of items crafted
function craft_request(player_index, request)
-- Abort if no player character
local playerdata = get_make_playerdata(player_index)
local character = playerdata.luaplayer.character
if not character then return "no-character" end
-- Abort if player already has more of item in inventory than needed
if request.inventory >= request.count then return "no-crafts-needed" end
-- Calculate item need; abort if 0 (or less)
local crafting_yield = get_item_count_from_character_crafting_queue(character, request.name)
local item_need = request.count - request.inventory - crafting_yield
local original_need = item_need
if item_need <= 0 then return "no-crafts-needed" end
local crafting_recipes = game.get_filtered_recipe_prototypes{
{filter="has-product-item", elem_filters={{filter="name", name=request.name}}},
{filter="hidden-from-player-crafting", invert=true, mode="and"}
}
for recipe_name, recipe in pairs(crafting_recipes) do
local yield_per_craft = get_yield_per_craft(request.name, recipe)
local needed_crafts = math.ceil(item_need / yield_per_craft) --[[@as uint]]
local actual_crafts = character.begin_crafting{recipe=recipe_name, count=needed_crafts, silent=true}
item_need = item_need - math.floor(actual_crafts * yield_per_craft)
if item_need <= 0 then break end
end
return "attempted", original_need - item_need
end
---Registers that a change in data tables has occured and marks the responsible player as having
---data updates to process.
---@param player_index uint Player index
---@param tick number Tick during which the data update occurred
function register_update(player_index, tick)
local playerdata = get_make_playerdata(player_index)
-- Mark player as having a data update, in order for it to get reprocessed
playerdata.has_updates = true
-- Record the tick in which the update was registered
global.last_event = tick
-- Register nth_tick handler if needed
register_nth_tick_handler(true)
end
---Registers/unregisters on_nth_tick event handler.
---@param state any
function register_nth_tick_handler(state)
if state and not global.events.nth_tick then
global.events.nth_tick = true
script.on_nth_tick(global.settings.min_update_interval, on_nth_tick)
elseif state == false and global.events.nth_tick then
global.events.nth_tick = false
---@diagnostic disable-next-line
script.on_nth_tick(nil)
end
end
---Registers/unregisters event handlers for inventory or player cursor stack changes.
---@param state boolean Determines whether to register or unregister event handlers
function register_inventory_monitoring(state)
if state and not global.events.inventory then
global.events.inventory = true
script.on_event(defines.events.on_player_main_inventory_changed,
on_player_main_inventory_changed)
script.on_event(defines.events.on_player_cursor_stack_changed,
on_player_main_inventory_changed)
script.on_event(defines.events.on_entity_destroyed, on_ghost_destroyed)
elseif state == false and global.events.inventory then
global.events.inventory = false
script.on_event(defines.events.on_player_main_inventory_changed, nil)
script.on_event(defines.events.on_player_cursor_stack_changed, nil)
script.on_event(defines.events.on_entity_destroyed, nil)
end
end
---Registers/unregisters event handlers for player logistic slot changes.
---@param state boolean Determines whether to register or unregister event handlers
function register_logistics_monitoring(state)
if state and not global.events.logistics then
global.events.logistics = true
script.on_event(defines.events.on_entity_logistic_slot_changed,
on_entity_logistic_slot_changed)
elseif state == false and global.events.logistics then
global.events.logistics = false
script.on_event(defines.events.on_entity_logistic_slot_changed, nil)
end
end
---Iterates over global playerdata table and determines whether any connected players have their
---mod GUI open.
---@return boolean
function is_inventory_monitoring_needed()
for _, playerdata in pairs(global.playerdata) do
if playerdata.is_active and playerdata.luaplayer.connected then return true end
end
return false
end
---Iterates over the global playerdata table and checks to see if any one-time logistic requests
---are still unfulfilled.
---@return boolean
function is_logistics_monitoring_needed()
for _, playerdata in pairs(global.playerdata) do
if (playerdata.is_active or table_size(playerdata.logistic_requests) > 0) and
playerdata.luaplayer.connected then return true end
end
return false
end

View File

@@ -0,0 +1,201 @@
---Handles the lua shortcut button or hotkey being triggered.
---@param event EventData.on_lua_shortcut|EventData.CustomInputEvent Event table
function on_lua_shortcut(event)
-- Exclude irrelevant lua shortcuts
if event.prototype_name and event.prototype_name ~= NAME.shortcut.button then return end
local player = game.get_player(event.player_index) --[[@as LuaPlayer]]
local cursor_stack = player.cursor_stack
-- Abort if player has no cursor stack as they are presumably a spectator
if not cursor_stack then return end
if player.is_cursor_blueprint() then
on_player_selected_blueprint(event)
else
local clear_cursor = player.clear_cursor()
if clear_cursor then
cursor_stack.set_stack({name=NAME.tool.ghost_counter})
end
end
end
script.on_event(defines.events.on_lua_shortcut, on_lua_shortcut)
script.on_event(NAME.input.ghost_counter_selection, on_lua_shortcut)
---Event handler for selection using GC tool
---@param event EventData.on_player_selected_area Event table
---@param ignore_tiles boolean Determines whether tiles are included in count
function on_player_selected_area(event, ignore_tiles)
if event.item ~= NAME.tool.ghost_counter then return end
local ghosts, requests = get_selection_counts(event.entities, ignore_tiles)
-- Open window only if there are non-zero ghost entities
if table_size(requests) > 0 then
local player_index = event.player_index
local playerdata = get_make_playerdata(player_index)
playerdata.job = {
area=event.area,
ghosts=ghosts,
requests=requests,
requests_sorted=sort_requests(requests)
}
update_one_time_logistic_requests(player_index)
update_inventory_info(player_index)
update_logistics_info(player_index)
Gui.toggle(player_index, true)
playerdata.luaplayer.clear_cursor()
end
end
script.on_event(defines.events.on_player_selected_area,
---@param event EventData.on_player_selected_area
function(event) on_player_selected_area(event, true) end)
script.on_event(defines.events.on_player_alt_selected_area,
---@param event EventData.on_player_selected_area
function(event) on_player_selected_area(event, false) end)
---Handles Ghost counter being activated with a blueprint in cursor.
---@param event EventData.on_lua_shortcut|EventData.CustomInputEvent Event table
function on_player_selected_blueprint(event)
local player_index = event.player_index
local playerdata = get_make_playerdata(player_index)
local entities = playerdata.luaplayer.get_blueprint_entities() or {}
local tiles = {}
if (playerdata.luaplayer.is_cursor_blueprint() and
playerdata.luaplayer.cursor_stack.valid_for_read) then
tiles = get_blueprint_tiles(playerdata.luaplayer.cursor_stack)
end
-- Abort if player not holding blueprint or empty blueprint
if not (entities and #entities > 0) and not (tiles and #tiles > 0) then return end
local requests = get_blueprint_counts(entities, tiles)
playerdata.job = {
area={},
ghosts={},
requests=requests,
requests_sorted=sort_requests(requests)
}
update_one_time_logistic_requests(player_index)
update_inventory_info(player_index)
update_logistics_info(player_index)
Gui.toggle(player_index, true)
end
---Updates playerdata.job.requests table as well as one-time requests to see if any can be
---considered fulfilled
---@param event EventData.on_player_main_inventory_changed Event table
function on_player_main_inventory_changed(event)
local playerdata = get_make_playerdata(event.player_index)
if not playerdata.is_active then return end
if playerdata.luaplayer.controller_type ~= defines.controllers.character then return end
register_update(playerdata.index, event.tick)
end
---Updates one-time logistic requests table as well as job.requests
---@param event EventData.on_entity_logistic_slot_changed Event table
function on_entity_logistic_slot_changed(event)
-- Exit if event does not involve a player character
if event.entity.type ~= "character" then return end
local player = event.entity.player or event.entity.associated_player
if not player then return end
local player_index = player.index
local playerdata = get_make_playerdata(player_index)
-- Iterate over known one-time logistic requests to see if the event concerns any of them
for name, request in pairs(playerdata.logistic_requests) do
if request.slot_index == event.slot_index then
if request.is_new then
request.is_new = false
return
else
playerdata.logistic_requests[name] = nil
end
break
end
end
register_update(player_index, event.tick)
end
---Triggers an update if the player respawns.
---@param event EventData.on_player_respawned Event data
function on_player_respawned(event)
local playerdata = get_make_playerdata(event.player_index)
if not playerdata.is_active then return end
register_update(playerdata.index, event.tick)
end
script.on_event(defines.events.on_player_respawned, on_player_respawned)
---Triggers an update if the player dies.
---@param event EventData.on_player_died Event data
function on_player_died(event)
local playerdata = get_make_playerdata(event.player_index)
if not playerdata.is_active then return end
register_update(playerdata.index, event.tick)
end
script.on_event(defines.events.on_player_died, on_player_died)
---Handles `on_entity_destroyed` by looking up `event.unit_number` in ghost tables and updates
---requests tables where appropriate
---@param event EventData.on_entity_destroyed Event table
function on_ghost_destroyed(event)
-- Since even ghost tiles have `unit_number`, exit if none is provided
if not event.unit_number then return end
-- Iterate over each player, and update their requests if they were tracking the entity
for player_index, playerdata in pairs(global.playerdata) do
if playerdata.is_active and playerdata.job.ghosts[event.unit_number] then
local items = playerdata.job.ghosts[event.unit_number]
for _, item in pairs(items) do
local request = playerdata.job.requests[item.name]
request.count = request.count - item.count
end
register_update(player_index, event.tick)
end
end
end
---Handles `on_nth_tick`—processes data for players who have had data updates. Aborts and
---unregisters itself if there were no data updates for any player since the previous function call
---@param event table Event table
function on_nth_tick(event)
-- If no data updates happened over the last 5 ticks, unregister nth_tick handler and exit
if event.tick - global.last_event > global.settings.min_update_interval then
register_nth_tick_handler(false)
return
end
-- Iterate over each player and process their data if they had updates
for player_index, playerdata in pairs(global.playerdata) do
-- If a player had registered data updates, reprocess their data
if playerdata.has_updates then
update_one_time_logistic_requests(player_index)
if playerdata.is_active then
update_inventory_info(player_index)
update_logistics_info(player_index)
Gui.update_list(player_index)
end
-- Reset `has_updates` boolean for that player
playerdata.has_updates = false
end
end
-- Check if event handlers can be unbound
if not is_inventory_monitoring_needed() then register_inventory_monitoring(false) end
if not is_logistics_monitoring_needed() then register_logistics_monitoring(false) end
end

View File

@@ -0,0 +1,420 @@
Gui = {}
---Toggles mod GUI on or off
---@param player_index uint Player index
---@param state boolean true -> on, false -> off
function Gui.toggle(player_index, state)
local playerdata = get_make_playerdata(player_index)
state = state or not playerdata.is_active
if state then
playerdata.is_active = true
-- Create mod gui and register event handler
Gui.make_gui(player_index)
register_inventory_monitoring(true)
register_logistics_monitoring(true)
else
playerdata.is_active = false
playerdata.job = {
area={},
ghosts={},
requests={},
requests_sorted={}
}
-- Destroy mod GUI and remove references to it
if playerdata.gui.root and playerdata.gui.root.valid then
local last_location = playerdata.gui.root.location --[[@as GuiLocation.0]]
playerdata.gui.root.destroy()
playerdata.gui = {last_location=last_location}
end
-- Unbind event hooks if no no longer needed
if not is_inventory_monitoring_needed() then register_inventory_monitoring(false) end
if not is_logistics_monitoring_needed() then register_logistics_monitoring(false) end
end
end
---Make mod GUI
---@param player_index uint Player index
function Gui.make_gui(player_index)
local playerdata = get_make_playerdata(player_index)
local screen = playerdata.luaplayer.gui.screen
local window_loc_x, window_loc_y
-- Restore previous saved location, if any
if playerdata.gui.last_location then
local location = playerdata.gui.last_location
local resolution = playerdata.luaplayer.display_resolution
window_loc_x = location.x < resolution.width and location.x or nil
window_loc_y = location.y < resolution.height and location.y or nil
end
-- Destory existing mod GUI if one exists
if screen[NAME.gui.root_frame] then
local location = screen[NAME.gui.root_frame].location
window_loc_x, window_loc_y = location.x, location.y
screen[NAME.gui.root_frame].destroy()
end
playerdata.gui.root = screen.add{
type="frame",
name=NAME.gui.root_frame,
direction="vertical",
style=NAME.style.root_frame
}
do
local resolution = playerdata.luaplayer.display_resolution
local x = window_loc_x or 50
local y = window_loc_y or (resolution.height / 2) - 300
playerdata.gui.root.location = {x, y}
end
-- Create title bar
local titlebar_flow = playerdata.gui.root.add{
type="flow",
direction="horizontal",
style=NAME.style.titlebar_flow
}
titlebar_flow.drag_target = playerdata.gui.root
titlebar_flow.add{
type="label",
caption="Ghost Counter",
ignored_by_interaction=true,
style="frame_title"
}
titlebar_flow.add{
type="empty-widget",
ignored_by_interaction=true,
style=NAME.style.titlebar_space_header
}
local hide_empty = playerdata.options.hide_empty_requests
titlebar_flow.add{
type="sprite-button",
name=NAME.gui.hide_empty_button,
tooltip={"ghost-counter-gui.hide-empty-requests-tooltip"},
sprite=hide_empty and NAME.sprite.hide_empty_black or NAME.sprite.hide_empty_white,
hovered_sprite=NAME.sprite.hide_empty_black,
clicked_sprite=hide_empty and NAME.sprite.hide_empty_white or NAME.sprite.hide_empty_black,
style=hide_empty and NAME.style.titlebar_button_active or NAME.style.titlebar_button
}
titlebar_flow.add{
type="sprite-button",
name=NAME.gui.close_button,
sprite="utility/close_white",
hovered_sprite="utility/close_black",
clicked_sprite="utility/close_black",
tooltip={"ghost-counter-gui.close-button-tooltip"},
style="close_button"
}
local deep_frame = playerdata.gui.root.add{
type="frame",
direction="vertical",
style=NAME.style.inside_deep_frame
}
local toolbar = deep_frame.add{
type="frame",
direction="horizontal",
style=NAME.style.topbar_frame
}
toolbar.add{
type="sprite-button",
name=NAME.gui.get_signals_button,
sprite=NAME.sprite.get_signals_white,
hovered_sprite=NAME.sprite.get_signals_black,
clicked_sprite=NAME.sprite.get_signals_black,
tooltip={"ghost-counter-gui.get-signals-tooltip"},
style=NAME.style.get_signals_button
}
toolbar.add{
type="empty-widget",
style=NAME.style.topbar_space
}
toolbar.add{
type="sprite-button",
name=NAME.gui.craft_all_button,
sprite=NAME.sprite.craft_all_white,
hovered_sprite=NAME.sprite.craft_all_black,
clicked_sprite=NAME.sprite.craft_all_black,
tooltip={"ghost-counter-gui.craft-all-tooltip"},
style=NAME.style.get_signals_button
}
toolbar.add{
type="button",
name=NAME.gui.request_all_button,
caption={"ghost-counter-gui.request-all-caption"},
tooltip={"ghost-counter-gui.request-all-tooltip"},
style=NAME.style.ghost_request_all_button
}
toolbar.add{
type="sprite-button",
name=NAME.gui.cancel_all_button,
sprite=NAME.sprite.cancel_white,
hovered_sprite=NAME.sprite.cancel_black,
clicked_sprite=NAME.sprite.cancel_black,
tooltip={"ghost-counter-gui.cancel-all-tooltip"},
style=NAME.style.ghost_cancel_all_button
}
playerdata.gui.requests_container = deep_frame.add{
type="scroll-pane",
name=NAME.gui.scroll_pane,
style=NAME.style.scroll_pane
}
Gui.make_list(player_index)
end
---Creates the list of request frames in the GUI
---@param player_index uint Player index
function Gui.make_list(player_index)
local playerdata = get_make_playerdata(player_index)
-- Create a new row frame for each request
playerdata.gui.requests = {}
for _, request in pairs(playerdata.job.requests_sorted) do
Gui.make_row(player_index, request)
end
end
---Returns request button properties based on request fulfillment and other criteria
---@param request table `request` table
---@param one_time_request table `playerdata.logistic_requests[request.name]`
---@return boolean enabled Whehter button should be enabled
---@return string style Style that should be applied to the button
---@return LocalisedString tooltip Tooltip shown for button
function make_request_button_properties(request, one_time_request)
local logistic_request = request.logistic_request or {}
local enabled = ((logistic_request.min or 0) < request.count) or one_time_request and true or
false
local style =
((logistic_request.min or 0) < request.count) and NAME.style.ghost_request_button or
NAME.style.ghost_request_active_button
local str = "[item=" .. request.name .. "] "
local tooltip
if enabled then
tooltip = ((logistic_request.min or 0) < request.count) and
{"ghost-counter-gui.set-temporary-request-tooltip", request.count, str} or
{"ghost-counter-gui.unset-temporary-request-tooltip"}
else
tooltip = {"ghost-counter-gui.existing-logistic-request-tooltip"}
end
return enabled, style, tooltip
end
---Updates the list of request frames in the GUI
---@param player_index uint Player index
function Gui.update_list(player_index)
local playerdata = get_make_playerdata(player_index)
if not playerdata.is_active or not playerdata.gui.requests then return end
local indices = {count=1, sprite=2, label=3, inventory=4, request=5}
-- Update gui elements with new values
for name, frame in pairs(playerdata.gui.requests) do
local request = playerdata.job.requests[name]
if request.count > 0 or not playerdata.options.hide_empty_requests then
frame.visible = true
-- Update ghost count
frame.children[indices.count].caption = request.count
-- Update amont in inventory
frame.children[indices.inventory].caption = request.inventory
-- Calculate amount missing
local diff = request.count - request.inventory
-- If amount needed exceeds amount in inventory, show request button
local request_element = frame.children[indices.request]
if diff > 0 then
local enabled, style, tooltip = make_request_button_properties(request,
playerdata.logistic_requests[request.name])
if request_element.type == "button" then
request_element.enabled = enabled
request_element.style = style
request_element.caption = diff
request_element.tooltip = tooltip
else
frame.children[indices.request].destroy()
frame.add{
type="button",
caption=diff,
enabled=enabled,
style=style,
tooltip=tooltip,
tags={ghost_counter_request=request.name}
}
end
-- Otherwise create request-fulfilled checkmark previous element was a request button
elseif request_element.type == "button" then
request_element.destroy()
local sprite_container = frame.add{
type="flow",
direction="horizontal",
style=NAME.style.ghost_request_fulfilled_flow
}
sprite_container.add{
type="sprite",
sprite="utility/check_mark_white",
resize_to_sprite=false,
style=NAME.style.ghost_request_fulfilled_sprite
}
end
else
frame.visible = false
end
end
end
---Generates the row frame for a given request table
---@param player_index uint Player index
---@param request table `request` table, containing name, count, inventory, etc.
function Gui.make_row(player_index, request)
local playerdata = get_make_playerdata(player_index)
local parent = playerdata.gui.requests_container
local localized_name = game.item_prototypes[request.name].localised_name
-- Row frame
local frame = parent.add{type="frame", direction="horizontal", style=NAME.style.row_frame}
playerdata.gui.requests[request.name] = frame
-- Ghost (item) count
frame.add{type="label", caption=request.count, style=NAME.style.ghost_number_label}
-- Item sprite
frame.add{
type="sprite",
sprite="item/" .. request.name,
resize_to_sprite=false,
style=NAME.style.ghost_sprite
}
-- Item or tile localized name
frame.add{type="label", caption=localized_name, style=NAME.style.ghost_name_label}
-- Amount in inventory
frame.add{type="label", caption=request.inventory, style=NAME.style.inventory_number_label}
-- Calculate amount missing
local diff = request.count - request.inventory
-- Show one-time request logistic button
if diff > 0 then
local enabled, style, tooltip = make_request_button_properties(request,
playerdata.logistic_requests[request.name])
frame.add{
type="button",
caption=diff,
enabled=enabled,
style=style,
tooltip=tooltip,
tags={ghost_counter_request=request.name}
}
else -- Show request fulfilled sprite
local sprite_container = frame.add{
type="flow",
direction="horizontal",
style=NAME.style.ghost_request_fulfilled_flow
}
sprite_container.add{
type="sprite",
sprite="utility/check_mark_white",
resize_to_sprite=false,
style=NAME.style.ghost_request_fulfilled_sprite
}
end
-- Hide frame if ghost count is 0 and player toggled hide empty requests
frame.visible = request.count > 0 or not playerdata.options.hide_empty_requests and true or
false
end
---Event handler for GUI button clicks
---@param event EventData.on_gui_click Event table
function Gui.on_gui_click(event)
local player_index = event.player_index
local element = event.element
local element_name = element.name
if element.name == NAME.gui.close_button then
-- Close button
Gui.toggle(player_index, false)
elseif element.tags and element.tags.ghost_counter_request then
-- One-time logistic request/craft button
local playerdata = get_make_playerdata(player_index)
local request_name = element.tags.ghost_counter_request --[[@as string]]
if event.shift == true then
local request = playerdata.job.requests[request_name]
if request then
local result, crafted = craft_request(event.player_index, request)
local player = game.get_player(player_index) --[[@as LuaPlayer]]
if result == "no-crafts-needed" then
player.create_local_flying_text{
text={"ghost-counter-message.crafts-not-needed"},
create_at_cursor=true
}
elseif result == "attempted" and crafted == 0 then
player.create_local_flying_text{
text={"ghost-counter-message.crafts-attempted-none"},
create_at_cursor=true
}
end
end
else
if not playerdata.logistic_requests[request_name] then
make_one_time_logistic_request(player_index, request_name)
Gui.update_list(player_index)
else
restore_prior_logistic_request(player_index, request_name)
Gui.update_list(player_index)
end
end
elseif element_name == NAME.gui.hide_empty_button then
local playerdata = get_make_playerdata(player_index)
local new_state = not playerdata.options.hide_empty_requests
playerdata.options.hide_empty_requests = new_state
element.style = new_state and NAME.style.titlebar_button_active or
NAME.style.titlebar_button
element.sprite = new_state and NAME.sprite.hide_empty_black or NAME.sprite.hide_empty_white
element.clicked_sprite = new_state and NAME.sprite.hide_empty_white or
NAME.sprite.hide_empty_black
Gui.update_list(player_index)
elseif element_name == NAME.gui.get_signals_button then
make_combinators_blueprint(event.player_index)
elseif element_name == NAME.gui.craft_all_button then
local playerdata = get_make_playerdata(player_index)
for _, request in pairs(playerdata.job.requests) do
craft_request(player_index, request)
end
elseif element_name == NAME.gui.request_all_button then
local playerdata = get_make_playerdata(player_index)
for _, request in pairs(playerdata.job.requests) do
if request.count > 0 and not playerdata.logistic_requests[request.name] then
make_one_time_logistic_request(player_index, request.name)
end
end
Gui.update_list(player_index)
elseif element_name == NAME.gui.cancel_all_button then
cancel_all_one_time_requests(player_index)
Gui.update_list(player_index)
end
end
script.on_event(defines.events.on_gui_click, Gui.on_gui_click)

View File

@@ -0,0 +1,10 @@
data:extend{
{
name="ghost-counter-min-update-interval",
setting_type="runtime-global",
type="int-setting",
default_value=10,
minimum_value=5,
maximum_value=120
}
}

View File

@@ -0,0 +1,55 @@
local mod_prefix = "ghost-counter-"
local NAME = {
tool={ghost_counter=mod_prefix .. "tool"},
shortcut={button=mod_prefix .. "shortcut"},
setting={min_update_interval=mod_prefix .. "min-update-interval"},
sprite = {
get_signals_white = mod_prefix .. "get-signals-white",
get_signals_black = mod_prefix .. "get-signals-black",
hide_empty_white = mod_prefix .. "hide-empty-white",
hide_empty_black = mod_prefix .. "hide-empty-black",
craft_all_white = mod_prefix .. "craft-all-white",
craft_all_black = mod_prefix .. "craft-all-black",
cancel_white = mod_prefix .. "cancel-white",
cancel_black = mod_prefix .. "cancel-black"
},
gui = {
root_frame = mod_prefix .. "root-frame",
hide_empty_button = mod_prefix .. "hide-empty-requests-button",
close_button = mod_prefix .. "close-button",
get_signals_button = mod_prefix .. "convert-to-signals-button",
craft_all_button = mod_prefix .. "craft-all",
request_all_button = mod_prefix .. "request-all-button",
cancel_all_button = mod_prefix .. "cancel-all-button",
scroll_pane = mod_prefix .. "scroll-pane"
},
input = {
ghost_counter_selection = mod_prefix .. "selection-hotkey"
},
style = {
root_frame = mod_prefix .. "root-frame",
titlebar_flow = mod_prefix .. "titlebar-flow",
titlebar_space_header = mod_prefix .. "titlebar-space-header",
titlebar_button = mod_prefix .. "titlebar-button",
titlebar_button_active = mod_prefix .. "titlebar-button-active",
inside_deep_frame = mod_prefix .. "inside-deep-frame",
topbar_frame = mod_prefix .. "topbar-frame",
get_signals_button = mod_prefix .. "get-signals-button",
topbar_space = mod_prefix .. "topbar-space",
ghost_request_all_button = mod_prefix .. "ghost-request-all-button",
ghost_cancel_all_button = mod_prefix .. "ghost-cancell-all-button",
scroll_pane = mod_prefix .. "scroll-pane",
row_frame = mod_prefix .. "row-frame",
ghost_number_label = mod_prefix .. "ghost-number-label",
ghost_sprite = mod_prefix .. "ghost-sprite",
ghost_name_label = mod_prefix .. "ghost-name-label",
inventory_number_label = mod_prefix .. "inventory-number-label",
ghost_request_button = mod_prefix .. "ghost-request-button",
ghost_request_active_button = mod_prefix .. "ghost-request-active-button",
ghost_request_fulfilled_flow = mod_prefix .. "ghost-request-fulfilled-flow",
ghost_request_fulfilled_sprite = mod_prefix .. "ghost-request-fulfilled-sprite"
}
}
return NAME

BIN
ghost-counter/thumbnail.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB