Data Raw Prototypes deprecated


A modding utility to access raw prototype data from data.raw within control.lua. Prototypes are only loaded as required, cached to the save game for as long as the mods state is unchanged, and the cache is shared across all mods. To use: remote.call("data-raw", "prototype", "car", "tank"). See readme for more details.

Utilities
7 years ago
0.14 - 0.15
65
Owner:
Earendel
Source:
N/A
Homepage:
N/A
License:
See below
Created:
8 years ago
Latest Version:
0.3.1 (7 years ago)
Factorio version:
0.14 - 0.15
Downloaded by:
65 users

Title: Data Raw Prototypes
Short Description: A modding utility to access raw prototype data from data.raw within control.lua. Prototypes are only loaded as required, cached to the save game for as long as the mods state is unchanged, and the cache is shared across all mods. To use: remote.call("data-raw", "prototype", "car", "tank").
Name: data-raw-prototypes
Mod State: Beta
Dependencies: Base
Forum Thread: https://forums.factorio.com/viewtopic.php?t=38459

Long Description

The mod uses loadstring() to load parts of data.raw that are available to data.lua files. The data is saved in a way that allows loading of specific prototypes instead of needing to load the entire data.raw in one go. This means that if you only need to load a single car type entity, or only need to load a few types of ammo it won’t cause the game to hang for a long time. This mod also uses a cache that lasts as long as prototypes are unchanged, so even if you load the same prototype multiple times (even across different save/load sessions) then the load call will only be performed once. Additionally, this mod provides interfaces for other mods to access the same cache, so even if multiple mods request the same prototype, that prototype will only be loaded once.

Instructions

Access a raw prototype

remote.call("data-raw", "prototype", "car", "tank")
-- returns the raw prototype from data.raw.car.tank
-- replace "car" with the desired prototype type and "tank" with the desired prototype name.

Access all prototype of a type

remote.call("data-raw", "prototypes_of_type", "car")
-- returns the raw prototype dictionary from data.raw.car -- e.g: {car = {car_prototype...}, tank = {tank_prototype...}, ...}
-- replace "car" with the desired prototype type.

Access a list of all prototype types and prototype names

remote.call("data-raw", "prototypes_list")
-- returns a dictionary of prototype types, each containing a list of prototype names of that type -- e.g: {car = {"car", "tank", ...}, gun = {"shotgun", ...}, ...}

Troubleshooting

The 'game' variable must have loaded in order to access the prototypes, see the http://lua-api.factorio.com/latest/Data-Lifecycle.html for more details.

Avoid using data-final-fixes.lua to alter prototypes, use data-updates.lua instead, otherwise if your mod is processed after this mod then any changes will not be loaded.

Licence

This software is provided without warranty and the software author/license owner cannot be held liable for damages.

Commercial Use

No. You are not allowed to make money off this mod or any of the contained assets (unless you are Wube Software).

Distribution

Yes. You are allowed to redistribute this mod as is. This includes being repackaged as part of a mod pack. You must disclose the source.

Modification

No. You are not allowed to distribute anything altered, or derived from this mod.
Exceptions:
You can make modifications if you have expressed permission from me (Earendel) first.
You may make alterations for private personal use.
You may post partial modified sections of this mod in the mod portal discussion section or official forum thread for this mod (and only those locations) for the purpose of providing bug fixes or enhancements.

Change Log

v0.1.2: Returns nil when nil is input
v0.2.1: Updated for Factorio 0.15.
v0.3.1: Any prototype data stored and provided by data-raw-prototypes now needs to be specifically set as 'required' by other mods calling data_raw_require("type_name", {"prototype_name", ...}, {"property_name", ...}) from data.lua phase. This is an optimisation due to additional restrictions in Factorio 0.15. Updating may break mods that require an earlier version.