rimworld-blax-defaults/README.md

131 lines
15 KiB
Markdown
Raw Normal View History

![Blax Defaults](About/Preview.png)
# Blax Defaults
[![RimWorld 1.7](https://img.shields.io/badge/RimWorld-1.7-19C63C)](https://rimworldgame.com)
[![Needs Harmony](https://img.shields.io/badge/needs-Harmony-050805)](https://steamcommunity.com/sharedfiles/filedetails/?id=2009463077)
[![Status: 1.0](https://img.shields.io/badge/status-1.0-CDCDCD)](CHANGELOG.md)
[![Any DLC combination](https://img.shields.io/badge/DLCs-any_combination-5a6b5d)](#dlc-support)
RimWorld mod (1.7) from Blax Gaming: your own starting settings for new stockpiles, shelves and bills. Set up one shelf, click "Make default for new shelves", and every new shelf starts like it. Nothing changes until you save a default, the things you already have keep their settings, and nothing goes into your save, so the mod can be added to or removed from a running colony. Needs Harmony. Works with any DLC combination, core only included. Colonists, slaves and prisoners are Blax Castes' job; Blax Defaults never changes a pawn.
## Features
### Storage
- 📦 **New stockpiles start from your default.** Drag a stockpile or a dumping stockpile and it gets the filter and priority you saved for that type. A modded stockpile designator that subclasses the vanilla one shows up as a type of its own; its default applies only when the designator runs the vanilla zone maker, which no test covers with a real mod yet. An Expand drag that grows a zone leaves its filter alone. `Source/BlaxDefaults/StockpileHooks.cs`
- 🗄️ **New storage buildings start from your default.** Shelves, small shelves, bookcases and hoppers, and modded storage with a storage blueprint such as the racks from Weapon Racks, get your default from the moment the blueprint is placed. Changes you make on the blueprint still win. A shelf or hopper that auto-rebuild puts back keeps its old settings; a rebuilt bookcase starts from your default. Ruins, map generation, trader stock and things spawned without a blueprint keep the game's settings, and a default never makes a building take items it can't hold. `Source/BlaxDefaults/StorageBuildingHooks.cs`
- 🔘 **"Defaults" button in the storage tab** of stockpiles and covered storage buildings, or a small icon where the tab has no priority button: "Make default for new shelves", "Load your default", "Load the game's default" and "Forget the default for new shelves", which asks first. On a stockpile each entry opens a menu of stockpile types. On linked shelves it reads and writes the group's settings. The tooltip says whether new ones start from your default. `Source/BlaxDefaults/StorageTabButton.cs`, `StorageDefaultsMenu.cs`
- 🧹 **Quick setup.** The settings page button "New shelves start empty at Normal" lists every covered storage building with a checkbox. General-purpose shelves are ticked; hoppers, bookcases and storage limited to one kind of item start unticked, and kinds that already have a default are marked and start unticked. Confirming saves an empty default at Normal for each ticked kind, one that also refuses items mods add later. `Source/BlaxDefaults/QuickSetup.cs`
- A storage default stores every item it allows and every item it refuses, plus a rule for items it lists in neither: follow the game's default (what "Make default" saves), refuse them or allow them. `Source/BlaxDefaults/StorageTemplate.cs`
### Bills
- 📜 **Values for every new bill:** repeat mode, count, target, pause when satisfied and resume at, ingredient radius, allowed skill range, where products go (best stockpile or drop on floor), count equipped, count tainted, and the hit points and quality ranges used for counting. Each value starts at "Game's default", and only values you change are applied. "Do until you have X" falls back to "do X times" where the bill can't count its products. `Source/BlaxDefaults/BillDefaults.cs`
- 🩺 Surgery, mech gestation, mech resurrection and forming bills, pasted bills and loaded bills are never touched.
### Your defaults stay
- 📁 **One file for every save.** Defaults live in `Config/BlaxDefaults/Defaults.xml` in the game's save data folder, shared by every save, never in a save or in the mod settings. Every write goes to a temporary file first, is read back and checked, and only then replaces the file, with the previous version kept as `Defaults.xml.bak`. A file that fails to load is kept as a broken copy under its own name and never rotated into the backup; the backup loads instead, and the settings page says so. A file from a newer version is read but never overwritten. `Source/BlaxDefaults/DefaultsFile.cs`
- 🔌 **Removed a mod?** Names from a mod or DLC that is not active stay in the file, are skipped and counted on the settings page, and work again when the mod comes back.
- 📋 **Settings page** (Mod settings > Blax Defaults): the master switch "Apply saved defaults to new things", a status line, and the sections Stockpiles, Storage buildings and Every new bill, each with its own switch. Every saved default has a row saying what it sets, with Edit and Forget; Forget asks first. Edit opens the item filter with the priority and the rule for unlisted items. It all works from the main menu. `Source/BlaxDefaults/SettingsPage.cs`
- ⚠️ **Overlap warnings.** The settings page names active mods that set the same starting settings, and the first game loaded in a session opens a window listing them, with "Don't remind me" per mod. `Source/BlaxDefaults/OverlapWarnings.cs`
### Planned
Designed, not built yet (details and the release table in `docs/design.md`):
- 1.1: forbid rules. When your colonists, slaves, prisoners or enemies go down or die, what the game forbids is allowed again if it matches a filter with hit points and quality ranges, once the fight is over. For example enemy weapons and apparel only at 50 to 100% and Normal or better, their food, medicine, drugs and silver always. Stripping can forbid what doesn't match. Corpses outside the home area can stay allowed. Every rule ships off; neutral visitors and traders keep the game's rules.
- 1.2: graves, sarcophagi, mortars, growth vats (Biotech), biosculpter pods (Ideology) and other storage; defaults per recipe from the bill window; the bills a new workbench comes with.
- 1.3: animals per species (area, follow flags, training), born animals copy their mother, auto-slaughter limits; auto-repair for new mechs (Biotech).
- 1.4: crops for new growing zones and hydroponics basins; settings for new doors, tables, traps, heaters, coolers and lamps.
- 1.5: mech work modes and areas (Biotech).
### DLC support
Blax Defaults works with any combination of DLCs, core only included, and lists none as a dependency. 1.0 needs no DLC for any feature.
- The defaults file is shared by every DLC set. A DLC item inside a default, such as wastepack in a dumping stockpile default saved with Biotech, is skipped while that DLC is off, counted with the names from inactive mods, and works again when the DLC is back.
- A save made with a DLC loads without it: Blax Defaults keeps nothing in the save, and the vanilla fields it wrote are the game's to load.
- Not covered: Anomaly's corpse stockpile, Odyssey's fishing zones and gravship stockpiles. They keep the game's settings.
### Compatibility
Replaces, so you can unsubscribe them (the settings page names them while they are active):
- ♻️ [FSF] No Default Shelf Storage: the quick setup empties new shelves per kind and leaves hoppers and single-purpose storage alone.
- ♻️ Default Ingredient Radius and Default Bill Ingredient Radius: "Ingredient radius" under Every new bill.
Overlaps, named by the overlap warning:
- ⚠️ 1trickPwnyta's Defaults and Set my Defaults set starting settings for stockpiles and shelves too, and 1trickPwnyta's sets values for every new bill. Blax Defaults 1.0 covers those, so set each in one mod. Their bill lists per recipe or per workbench are not in 1.0 (planned for 1.1), so keep those mods for that and for their other defaults. The unofficial Defaults 1.7 repack is not detected yet.
- ⚠️ [FSF] FrozenSnowFox Tweaks: its "No Default Storage Settings" option empties the starting filter of storage buildings, like the quick setup. Use one of the two.
- ⚠️ Better Workbench Management sets where the products of new bills go. Set that in one mod only.
Works next to:
- ✔️ Weapon Racks: its racks get defaults like shelves; the quick setup leaves them unticked.
- ✔️ RimFridge (no 1.7 build yet, loads its 1.6 files): its fridges are covered storage kinds. The quick setup leaves them unticked, because RimFridge makes fridges act as hoppers.
- ✔️ Replace Stuff: replacing a shelf's material keeps its settings.
- ✔️ Preset Filtered Zones: its zones keep their preset filters and show no Defaults button.
- 🧩 Other Blax mods: Blax Castes handles colonists, slaves and prisoners. Blax Slaves and Blax Zones don't overlap with Blax Defaults; Zones' delivery zones keep their own tab and get no Defaults button. Load order between them doesn't matter.
- ❌ Multiplayer: not supported yet (the defaults file differs per player).
## Development
The repo is the mod folder. Link it into the game with a directory junction, run from the repo root (adjust the RimWorld path):
```powershell
New-Item -ItemType Junction -Path "E:\SteamLibrary\steamapps\common\RimWorld\Mods\BlaxDefaults" -Target (Get-Location).Path
```
Build (needs the .NET 10 SDK; output goes to `1.7/Assemblies/BlaxDefaults.dll`):
```powershell
dotnet build Source\BlaxDefaults\BlaxDefaults.csproj -c Release
```
`RimWorldDir` and `HarmonyDir` in the csproj point at the Steam install and the Harmony mod; override them with `-p:RimWorldDir=...` elsewhere.
### Tests
`Tests/BlaxDefaultsTests` is a separate test mod. `Tests/run-tests.ps1` builds both projects and starts RimWorld headless with its own save data folder in `%TEMP%\BlaxDefaultsTest`, so your mod list, saves, settings and defaults file stay untouched. Every run starts with an empty defaults library. The suite saves and reloads the game, checks that the save holds nothing of Blax Defaults, writes `BlaxDefaultsTestResults.txt` and quits. It needs Steam running.
```powershell
.\Tests\run-tests.ps1
.\Tests\run-tests.ps1 -NoDlc
.\Tests\run-tests.ps1 -Dlc Royalty,Biotech
.\Tests\run-tests.ps1 -Compat
```
A release runs all 8 combinations of Royalty, Ideology and Biotech. Each run also leaves a copy of the results per DLC set next to the results file: `BlaxDefaultsTestResults.all.txt` (every installed DLC), `.nodlc.txt` or `.dlc-<names>.txt`. The Workshop upload checks the `all` and `nodlc` copies. `-Compat` also loads the installed mods Blax Defaults is tested next to (the list is at the top of `run-tests.ps1`). Exit code 0 means all passed, 1 failures, 2 the run didn't finish.
### Workshop art
`Source/Art/` renders the preview, the mod icon and the Workshop section headers; `Source/Art/README.md` has the commands. The Workshop description is `docs/workshop-description.txt` (Steam BBCode), and `docs/workshop-media.md` lists the in-game clips worth recording.
### Workshop upload
`Tools/workshop-upload.ps1` creates or updates the Workshop item from the command line. A small tool (`Tools/WorkshopUpload`) uses the Steamworks.NET build and `steam_api64.dll` that ship with RimWorld and attaches to the running, logged-in Steam client as RimWorld, so it needs no password, no game window and no dev mode. Name, package id, version and supported versions come from `About/About.xml`.
```powershell
.\Tools\workshop-upload.ps1 # dry run: build, stage, check the Steam login and ownership
.\Tools\workshop-upload.ps1 -Check # release check: lists everything -Publish would refuse
.\Tools\workshop-upload.ps1 -Publish # upload
.\Tools\workshop-upload.ps1 -Publish -DescriptionFile docs\workshop-description.txt # also replace the description
```
Without `About/PublishedFileId.txt`, `-Publish` creates a new item. It writes the new id to `About/PublishedFileId.txt` right away, before the content upload, so a failed upload is retried as an update and never makes a second item. After a successful upload it writes `Tools/workshop-published.txt`. Commit both files. A new item needs a description: until something has been published from here, the script takes `docs/workshop-description.txt` by default. `-Visibility public|friends|private|unlisted` sets who sees the item; left out, a new item gets Steam's default.
It stages only what players need (About, 1.7, Defs, Patches, Languages, Textures, Sounds) in `%TEMP%`, sets the tags the game would (Mod plus the supported versions), and writes every CHANGELOG.md entry since the version in `Tools/workshop-published.txt` as the change note. The title is About.xml's name and the preview is `About/Preview.png`, set on every upload like the in-game uploader does. `-Publish` refuses unless the shipped files are committed and pushed, the top CHANGELOG entry matches `modVersion`, `About/Preview.png` is under 1 MB, and two test runs passed after the last build: one with every installed DLC and one with `-NoDlc` (the `all` and `nodlc` result copies, see Tests). `-Check` runs every `-Publish` check and the dry run and lists each problem; exit code 0 means none. The in-game route still works: `Tools/workshop-stage.ps1` swaps the junction for a clean copy, upload from Mods > Blax Defaults > Advanced... > Upload to Steam Workshop (dev mode), then `workshop-stage.ps1 -Done` copies `About/PublishedFileId.txt` back into the repo.
The Workshop description is `docs/workshop-description.txt` (Steam BBCode, at most 8000 bytes); `-DescriptionOnly -DescriptionFile docs\workshop-description.txt` replaces just the text, with no build, no content upload and no change note. Steam loads description images as cross-origin requests, so every `[img]` host must send an `Access-Control-Allow-Origin` header or the image shows broken; the script checks each one and `-Publish` refuses otherwise. Forgejo's raw URLs send no such header, so the Steam images are served from `cdn.blax.at/blax-gaming/`, which does. The section headers must be on `cdn.blax.at/blax-gaming/defaults/` before `-Publish` passes. Every forgejo.blax.at link in the description must also open without a login, so the repo has to be public first. `Source/Art/README.md` has the render commands.
---
## Made by Blax
[![Blax Software Open Source Initiative](docs/art/blax-oss-banner.svg)](https://www.blax.at)
🛠️ **Blax Gaming** is a project of **[Blax Software](https://www.blax.at)**, an Austrian software practice. We write Austrian-quality code in many fields: web platforms, mobile apps, backends, infrastructure, and the mods we play in our own colonies. Need something built? 👉 [www.blax.at](https://www.blax.at)