{
  "markdown": "# Homebrewed Toolkit for RimWorld\n\n## Description\n\nHomebrewed Toolkit is a shared code library for RimWorld 1.6 mods (targets .NET Framework 4.7.2). It is not a content mod. Other mods reference its assembly and use the static `Toolkit` facade for:\n\n- **Hooks** — run code when game events fire\n- **Indexing** — build read-only snapshots of game data that can be queried outside the main game loop\n- **Collecting** — define named collections of objects that match conditions\n- **Services** — register and resolve shared objects by type or name\n\nThe examples below follow patterns from Homebrewed Dynamic Filters, a mod built on this toolkit.\n\n## Installation\n\n### Players\n\nInstall like any other mod and enable \"Homebrewed Toolkit\" in the mod list. Requires [Harmony](https://steamcommunity.com/sharedfiles/filedetails/?id=2009463077).\n\n### Mod developers\n\nReference the built assembly from `1.6/Assemblies/` and ship it with your mod:\n\n```xml\n<ItemGroup>\n  <Reference Include=\"HomebrewDot.Net.Rimworld.Toolkit\">\n    <HintPath>path\\to\\HomebrewDot.Net.Rimworld.Toolkit.dll</HintPath>\n    <Private>false</Private>\n  </Reference>\n</ItemGroup>\n```\n\n## Usage\n\nAll public APIs live under the `HomebrewDot.Net.Rimworld` namespace.\n\n### Hooks\n\nUse hooks to run code when game events fire.\n\n```csharp\nusing HomebrewDot.Net.Rimworld;\nusing HomebrewDot.Net.Rimworld.Hooks.Triggers;\n\nToolkit.Hooks.Manager.RegisterHook<OnGameLoadedTrigger>(Toolkit.Instance, e =>\n{\n    Toolkit.Indexing.StartIndexing(e.Game, takeSnapshot: true);\n});\n```\n\n### Indexing\n\nIndex game data into read-only snapshots that are safe to read from background threads.\n\n```csharp\nusing HomebrewDot.Net.Rimworld;\nusing Verse;\n\nToolkit.Indexing.Def.EnsureGatherer();\nToolkit.Indexing.Def.Thing.EnsureTable();\nToolkit.Indexing.Thing.TrackMap();\nToolkit.Indexing.ReloadOrchestration();\n\nvar thingDefs = Toolkit.Indexing.Manager.DatabaseSnapshot?.GetTable<ThingDef>(\n    Toolkit.Indexing.Def.Thing.FullTableName);\n```\n\nDefine your own tables and metadata indexers:\n\n```csharp\nusing HomebrewDot.Net.Rimworld;\nusing Verse;\n\nToolkit.Indexing.ConfigureSchema += b => b.WithTable<ThingDef>(nameof(ThingDef));\n\nToolkit.Indexing.Indexers.BuildIndexer<ThingDef>(\"Map\", x =>\n    x.Include<Map>(ToolkitConstants.Thing.Map, true));\n\nToolkit.Indexing.ReloadOrchestration();\n```\n\n### Collecting\n\nDefine a named collection, start it, then read the matches:\n\n```csharp\nusing System;\nusing System.Collections.Generic;\nusing HomebrewDot.Net.Rimworld;\nusing HomebrewDot.Net.Rimworld.Indexing;\nusing Verse;\n\nvar table = $\"{nameof(Def)}.{nameof(ThingDef)}.Weapon.Ranged\";\nvar getThings = new Func<IReadOnlyDatabase, IEnumerable<IIndexed<ThingDef>>>(\n    s => s.GetTable<ThingDef>(table));\n\nToolkit.Collecting.Build(\"Snipers\", b => b\n    .Compare.Indexed(ToolkitConstants.Stats.Weapon.Def.Range).With.GreaterThanOrEqual().To.Value(30)\n    .CollectFromSnapshot(getThings));\n\nToolkit.Collecting.StartCollection();\n\nif (Toolkit.Collecting.GetAllCollectors().TryGetValue(\"Snipers\", out var collector))\n{\n    foreach (IIndexed<ThingDef> item in collector.GetAll())\n    {\n        Log.Message(item.Value.defName);\n    }\n}\n```\n\nRemove a collection when it is no longer needed:\n\n```csharp\nToolkit.Collecting.Remove(\"Snipers\");\n```\n\n### Services\n\nRegister and resolve shared objects by type or by name:\n\n```csharp\nusing HomebrewDot.Net.Rimworld;\n\nToolkit.Services.Register<IMyService>(new MyService());\nvar service = Toolkit.Services.GetRequired<IMyService>();\nToolkit.Services.Unregister<IMyService>(service);\n\nToolkit.Services.Register<IMyService>(new MyService(\"ui\"), \"ui\");\nvar uiService = Toolkit.Services.Get<IMyService>(\"ui\");\nvar allNamed = Toolkit.Services.GetAllNamed<IMyService>();\nToolkit.Services.UnregisterByName<IMyService>(\"ui\");\n```\n\n## Contributing\n\nNot accepting direct contributions right now. Feel free to fork.\n\n## License\n\nLicensed under Apache License 2.0. See [LICENSE.md](LICENSE.md).\n",
  "bytes": 3934,
  "sha": "0787b70e4e211a03ea12b613110da6549ca41b668e9a12ffa3bd0388033523eb",
  "repo_slug": "homebrewdotnet/homebrewdot.net.rimworld.toolkit",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/okf_homebrewdotnet_homebrewdot_net_rimworld__9fad89d8/readme"
}