Created
May 17, 2017 00:46
-
-
Save sparr/c90a9a0af52176f3ec4835497cb440f6 to your computer and use it in GitHub Desktop.
Factorio python lua data raw entities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import lupa | |
DATA_PATH = "/Users/crisher/Library/Application Support/Steam/steamapps/common/Factorio/factorio.app/Contents/data" | |
lua = lupa.LuaRuntime(unpack_returned_tuples=True) | |
def lua_run_file(file): | |
if os.path.isfile(file): | |
lua.execute(open(file).read()) | |
def load_mod(path): | |
if os.path.isdir(path): | |
os.chdir(path) | |
lua_run_file(os.path.join(path,"data.lua")) | |
lua_run_file(os.path.join(path,"data-updates.lua")) | |
lua_run_file(os.path.join(path,"data-final-fixes.lua")) | |
# add the lualib folder to the package path for lua require() | |
lua.execute('package.path = "' + os.path.join(DATA_PATH,"core","lualib") + '/?.lua;" .. package.path') | |
# dataloader initializes the data global and defines data:extend etc | |
lua_run_file(os.path.join(DATA_PATH,"core","lualib","dataloader.lua")) | |
# extracted copy of defines global | |
lua_run_file("defines.lua") | |
# the two "mods" packaged with the game | |
load_mod(os.path.join(DATA_PATH,"core")) | |
load_mod(os.path.join(DATA_PATH,"base")) | |
# data.raw contains many types of things. these types are entity prototypes | |
entity_prototype_types = [ | |
"accumulator", | |
"arithmetic-combinator", | |
"assembling-machine", | |
"beacon", | |
"boiler", | |
"constant-combinator", | |
"container", | |
"decider-combinator", | |
"electric-pole", | |
"furnace", | |
"generator", | |
"heat-pipe", | |
"lab", | |
"logistic-container", | |
"mining-drill", | |
"pipe", | |
"pipe-to-ground", | |
"programmable-speaker", | |
"pump", | |
"radar", | |
"reactor", | |
"solar-panel", | |
"storage-tank", | |
"tree", | |
"turret", | |
] | |
# flatten the entity prototypes | |
entities = {} | |
for type in entity_prototype_types: | |
for name, prototype in lua.globals().data.raw[type].items(): | |
entities[name] = prototype |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment