Code, graphics and conventions to help modders creating planets, moons and other systems. This library is a community project and will grow over time. Contributors are welcome to open a pull request on Github. For feature requests, please open an issue.
Contributors:
- We're currently publishing releases of this mod manually. In your pull requests, please list your changes in changelog.txt to be included in the next release. Please also update README.md to add sections for your new functionality (even with only 'Documentation pending') and add yourself to the contributors list.
- You must test your changes, ideally with multiple planets installed.
- We aim to avoid any breaking changes.
- Feel free to use the file
todo.md
.
Planet prototypes and space location prototypes can be defined using the following API. The 'distance' and 'orientation' of the prototypes will be calculated automatically from the orbit hierarchy, as will the layering of the sprites on the starmap.
PlanetsLib:extend(config)
— A wrapper/replacement fordata:extend
. Throws an error if passeddistance
ororientation
. It instead takes the fields listed below.type
—"planet"
or"space-location"
orbit
— Object containing orbital parameters:parent
— Object containingname
andtype
fields, corresponding to a parent atdata.raw[type][name]
. Planets in the original solar system should have an orbit withtype = "space-location"
andname = "star"
.distance
— Number: orbital distance from parentorientation
— Number: orbital angle from parent (0-1). Note that orientation is absolute, not relative to the parent's orientation.sprite
— Object (optional): Sprite for the planet’s orbit, centered on its parent.
sprite_only
— Boolean (optional): If true, this prototype will be removed indata-final-fixes
and replaced by its sprites on the starmap (unless neitherstarmap_icon
,starmap_icons
nor an orbit sprite are defined, in which case nothing will show).- This is useful for constructing stars and other locations that should not have a space platform 'docking ring'.
- Other valid
planet
orspace-location
prototype fields - Further notes on
PlanetsLib:extend
:
PlanetsLib:update(config)
— The same asPlanetsLib:extend
, except it updates a pre-existing planet or space location (identified by the passedtype
andname
fields) using the parameters passed. If theorbit
field is passed, thedistance
andorientation
fields on the prototype will be updated appropriately. Should not be called indata-final-fixes
.
The library provides automatic functionality to restrict cargo drops on your planet until a technology is researched. To implement:
- Use the helper function
PlanetsLib.cargo_drops_technology_base(planet, planet_technology_icon, planet_technology_icon_size)
to create a base technology prototype.- This will create a technology with name pattern:
planetslib-[planet-name]-cargo-drops
- PlanetsLib detects this technology by name. Players will be unable to drop cargo (excluding players and construction robots) to planets with that name before researching the technology.
- Only the fields
type
,name
,localised_name
,localised_description
,effects
,icons
will be defined, so you will need to addunit
(orresearch_trigger
) and prerequisites. - A locale entry for this technology is automatically generated, but you are free to override it.
- This will create a technology with name pattern:
PlanetsLib.technology_icons_moon
— Icon to be used in moon discovery technologies.subgroup=satellites
— A new Factoriopedia row for satellites (below the planets row).
Documentation pending.
Typically, when planet mods want to add a surface condition, what they are trying to do is restrict or relax the range of values for which that recipe or entity is allowed.
For example, Space Age recyclers have a maximum magnetic field of 99. If mod A wants to allow recyclers to be built up to 120, whilst mod B wants to allow them up to 150, compatibility issues can arise if mod A acts last and overrides mod B's change (which it ought to have been perfectly happy with). Instead mod A should modify existing surface conditions only if necessary.
Hence relax_surface_conditions
and restrict_surface_conditions
are provided, used like so:
relax_surface_conditions(data.raw.recipe["recycler"], {property = "magnetic-field", max = 120})
restrict_surface_conditions(data.raw.recipe["boiler"], {property = "pressure", min = 10})
NOTE: Calling relax_surface_conditions
without a min
field will not remove any existing min
conditions for that property (and similarly for max
).
PlanetsLib includes a variety of surface conditions, all of which are either hidden or disabled by default. To enable a surface condition, modders must add the following line to settings-updates.lua (using 'oxygen' as an example):
data.raw["bool-setting"]["PlanetsLib-enable-oxygen"].forced_value = true
PlanetsLib.restrict_to_planet(entity_or_recipe, planet)
: Restricts the entity or recipe prototype to a given planet by adding a special surface condition unique to that planet. This surface condition is almost invisible in the UI, with the exception of messages like "X can't be crafted on this surface. The is too low". The planet can be passed as a name or object.
PlanetsLib.set_default_import_location(item_name, planet)
- Sets the default import location for an item on a planet.PlanetsLib.borrow_music(source_planet, target_planet)
- Clones music tracks fromsource_planet
totarget_planet
. Does not overwrite existing music fortarget_planet
.
lib/orbit_graphic_generator.py
: contains a Python script that generates orbit sprites.generate_orbit(distance, output_file, mod_name)
,distance
being the same as your orbital distance. After generating your sprite, the script will print a block of lua code that imports your sprite with proper scaling. Orbit sprites should be scaled at 0.25 to ensure that no pixels are visible, even on 4K displays.