Tooltip Library


Add dynamic tooltips and custom statuses to entities at runtime.

Internal
a day ago
2.0
4
Owner:
thremtopod
Source:
https://gitlab.com/jfletcher94/factorio-mods
Homepage:
N/A
License:
GNU LGPLv3
Created:
a day ago
Latest Version:
0.1.0 (a day ago)
Factorio version:
2.0
Downloaded by:
4 users

Tooltip Library

This mod adds a remote interface for adding custom tooltips and statuses to entities at runtime. Tooltip Library works by using LuaEntity.custom_status, and setting custom entity statuses using this mod will improve comaptibility; however, Tooltip Library automatically adapts to custom statuses set by other mods.

Set Status

To set the custom status of an entity, call the remote interface:

remote.call("tooltip-lib", "set_status", entity, custom_status)

Where:

  • entity is the LuaEntity for which to set the custom status.
  • custom_status is a CustomEntityStatus, or nil to unset the custom status.

Set Tooltip

To add a custom tooltip to an entity, call the remote interface:

remote.call("tooltip-lib", "set_tooltip", entity, name, value)

Where:

  • entity is the LuaEntity for which to set the custom status.
  • name is a string, usually a LocalisedString key (e.g. "mod-tooltip-name.my-tooltip"), that is the unique identifier for the tooltip. Unless name is registered as "value only," the localised value of this string will be displayed as the tooltip key.
  • value is a LocalisedString that is the value displayed for this tooltip, or nil to remove the tooltip.

By default, the localised text of name and value will be formatted and displayed in the standard way for tooltips (i.e. "name: value"), including with the standard font and text color. To display only the value, and without formatting, register the tooltip's name as "value only" (see next section). Note that you can add formatting, icons, and everything else supported by LocalisedString in tooltip text yourself.

Set Value Only Tooltip Name

To register a tooltip name as "value only," call the remote interface:

remote.call("tooltip-lib", "set_value_only_toolip_name", name, is_value_only)

Where:

  • name is the string tooltip name to set (or unset) as "value only."
  • is_value_only is a boolean that determines whether to set or unset this name as "value only."

Note that his interface only needs to be called once per name, and not once per entity.

More Information

Implementation

Tooltip Library uses LuaEntity.custom_status under the hood for displaying all custom statuses and custom tooltips. There is almost no performance overhead in this mod; it is mostly event-driven, and at worst, it checks up to two entities per player each tick for entity status changes. Most of the complexity in the implementation comes from the compatibility logic required to work gracefully with other mods that set custom status but that do not use Tooltip Library.

Issues

This is a brand new mod, and should still be considered experimental. Use at your own risk.