Skip to main content

No project description provided

Project description

[!CAUTION] This is a heavily WIP project

RimWorld XML library

This library is designed to assist with writing mods and mod patches for RimWorld. It provides functionality to load game data into an xml file and apply patches to it.

Basic usage

from pathlib import Path

from rimworld import load_world

# First let's prepare some paths (i'm using wsl2):
RIMWORLD_CORE_PACKAGES = Path("/mnt/e/steam/steamapps/common/RimWorld/Data")
RIMWORLD_LOCAL_MODS = Path("/mnt/e/steam/steamapps/common/Rimworld/Mods")
RIMWORLD_STEAM_MODS = Path("/mnt/e/steam/steamapps/workshop/content/294100")
RIMWORLD_MODSCONFIG_FOLDER = Path(
    "/mnt/c/Users/lai/AppData/LocalLow/Ludeon Studios/"
    "RimWorld by Ludeon Studios/Config/ModsConfig.xml"
)

world = load_world(
    mod_folders=[RIMWORLD_CORE_PACKAGES, RIMWORLD_LOCAL_MODS, RIMWORLD_STEAM_MODS],
    modsconfig_folder=RIMWORLD_MODSCONFIG_FOLDER,
)

print(world.xpath("/Defs/ThingDef/label/text()"))

Slightly more advanced usage

from pathlib import Path

from lxml import etree

from rimworld.mod import ModsConfig, load_mods, select_mods
from rimworld.patch import PatchContext, get_operation
from rimworld.xml import load_xml, merge

# First let's prepare some paths (i'm using wsl2):
RIMWORLD_CORE_PACKAGES = Path("/mnt/e/steam/steamapps/common/RimWorld/Data")
RIMWORLD_LOCAL_MODS = Path("/mnt/e/steam/steamapps/common/Rimworld/Mods")
RIMWORLD_STEAM_MODS = Path("/mnt/e/steam/steamapps/workshop/content/294100")
RIMWORLD_MODSCONFIG_FOLDER = Path(
    "/mnt/c/Users/lai/AppData/LocalLow/Ludeon Studios/"
    "RimWorld by Ludeon Studios/Config/ModsConfig.xml"
)

# We know where our mods are, but we need to load information about them
# This will take a few seconds as the script loads About.xml files
mods_collection = list(
    load_mods(RIMWORLD_CORE_PACKAGES, RIMWORLD_LOCAL_MODS, RIMWORLD_STEAM_MODS)
)

# Now let's load game version, known expansions, and a list of active mods
mods_config = ModsConfig.load(RIMWORLD_MODSCONFIG_FOLDER)

# Select mods from our mods collection which are active
active_mods = list(select_mods(mods_collection, package_id_in=mods_config.active_mods))

# Prepare patching context - this is needed for proper patching
patch_context = PatchContext(
    active_package_ids={m.package_id for m in active_mods},
    active_package_names={m.about.name for m in active_mods if m.about.name},
)

# Create an empty xml tree
tree = etree.ElementTree(etree.Element("Defs"))

# And the final step
for mod in active_mods:
    for def_file in mod.def_files(mods_config):
        merge(tree, load_xml(def_file))
    for patch_file in mod.patch_files(mods_config):
        patch_operation_nodes = load_xml(patch_file).getroot().findall("Operation")
        for patch_operation_node in patch_operation_nodes:
            patch_operation = get_operation(patch_operation_node)
            patch_operation(tree, patch_context)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rimworld-0.3.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

rimworld-0.3.0-py3-none-any.whl (33.7 kB view details)

Uploaded Python 3

File details

Details for the file rimworld-0.3.0.tar.gz.

File metadata

  • Download URL: rimworld-0.3.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for rimworld-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b2f9a838c2cf8526f61a1ed7d68c2f5071fbc2b2ae2fa40d3d864e457d15a7bc
MD5 fbb2b2198ec571bec2ae3c9a9227b88d
BLAKE2b-256 f58f19e81758c9d0e008963d1ae68a6a2878a3f8011caa75352444e6cf0190cb

See more details on using hashes here.

File details

Details for the file rimworld-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: rimworld-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 33.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for rimworld-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d46517624b660db6e4833cd04d4ab10e5e3b78b919087c3e537e892c30c28c85
MD5 dcb5b96e1ddec70b19f020d074cce3aa
BLAKE2b-256 301ba515bb32af6a47385a94b9ccce91bc1c22315e0cf72ef5ba30690fc58e3e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page