Caves of Qud

Caves of Qud

Not enough ratings
More Modding Goodies!
   
Award
Favorite
Favorited
Unfavorite
Branch: Stable
File Size
Posted
Updated
147.762 KB
9 Jan @ 8:28am
17 Jan @ 2:41pm
13 Change Notes ( view )

Subscribe to download
More Modding Goodies!

Description
This mod is primarily a library required by my other mods.

Do you desire to express your wishes in the C# language? Well this is the mod for you! With this mod, you can wish up anything you can imagine (if you can sufficiently express it in C#).

Aside from the C# wish feature, this has some goodies you might find useful for making your own mods. It is primarily a library where I put common code and utilities used in my other mods, but feel free to use them.

Features
  • [RequiredGameSystem]: Attribute that ensures your IScribedSystem/IGameSystem is initialized correctly (See Code Example section below).
  • MoreCore: Adds additional core features.
    • TurnStart: Callback for the beginning of the turn for each actor. Unlike the available QudCore begin/end turn events, this callback occurs precisely at turn start, immediately before an action is taken.
    • PlayerTurnStart: Same as above, but only called for the player's turn start.
    • GetIsSkilledWithMissileWeaponEvent: Event for determining whether a creature is skilled with a MissileWeapon e.g. for adding a new skill tree.
    • GetMagazineAmmoLoaderReloadEnergyCostEvent: Event for determining the energy cost of reloading a weapon with the MagazineAmmoLoader part (most standard firearms).
    • GetEquipItemEnergyCostEvent: Event for determining the energy cost of equipping an object.
    • GetCombatMissileEnergyCostEvent: Event for determining the energy cost of firing a MissileWeapon.
    • Also has some notes on Qud Core object lifetime cycles, IScribedSystem, IGameSystem, IGameStateSingleton, IPlayerMutator, ModSensitiveStaticCache, GameBasedStaticCache, etc.
  • MoreOutput: Adds functions to log, show popups, add to the player's message queue, display loading toast messages, etc.
    • Error, Warn, Info, and Debug log levels. Fixed some bugs and inconsistencies with Qud Core's logging APIs. Stack traces always have file and line numbers where available. Error logs always have stack traces. Colors are escaped in exceptions in error popups.
    • Logging APIs to assign Error/Warn logs to the calling mod, if other mods are clients of your code.
    • Includes some options to control log verbosity (toggle popups, toggle display in message window, enable/disable debug level) for any logging events sent through the MoreOutput logging APIs. See Options -> Debug -> More Modding Goodies.
    • LoadAndDisplayMessage: API to show the animated toast message at the bottom of the screen while running long-duration tasks, with your mod's name ascribed.
  • MoreOptions: A few methods to make it easier to parse options from Options.xml with default values as fallbacks.
  • CSharpWishMaker: You can create wishes using C# incantations, if you know the language.
  • ToDebugString Extension Method
    • Extension method for any object. It walks an object's fields and attempts to pretty print the object's structure.
    • The CSharpWishMaker uses this to print the returned object.
    • It is also useful when printing to debug logs.
    • Has options to control verbosity in Options -> Debug -> More Modding Goodies

Usage
  • To make this library a dependency of your mod, in steam on your workshop item's page, under the Owner Controls panel on the right, click Add/Remove Required Items. Add this mod to your mod's list so that steam will also download this mod when users download yours.

C# Wish Examples
To make a C# wish, use the prefix c# and one of the following.
  • an expression e.g.
    cs The.Player.DisplayName
  • statements e.g.
    cs var newName = "bob"; The.Player.DisplayName = newName;
  • a file containing only an expression or statements, placed in Configuration Files[wiki.cavesofqud.com]. It will have string[] args in scope e.g.
    c# --file myfile.txt arg1 arg2

Code Examples
using tyrir.lib; [tyrir.lib.RequiredGameSystem] [HasModSensitiveStaticCache] [HasOptionFlagUpdate] public class MyMod : IScribedSystem { static int MyIntOption; [OptionFlagUpdate] public static void OnOptionFlagUpdate() { MoreOptions.TryParseOption("OptionMyIntOpt", out MyIntOption, defaultValue: 5); MoreOutput.Info("my option is now " + MyIntOption); } [ModSensitiveCacheInit] public static void OnModSensitiveCacheInit() { MoreCore.RegisterPlayerTurnStartCallback(OnPlayerTurnStart); MoreOutput.LoadAndDisplayMessage("Initializing...", Init); } public static void Init() { // do slow, static initialization stuff here } public static void OnPlayerTurnStart(GameObject player) { MoreOutput.Message($"It is {player.DisplayName}'s turn!"); MoreOutput.Popup("It's my turn!"); } public void OnGameStart(GameObject player, bool isNewGame, bool isInitialGameSystemCreation) { // [tyrir.lib.RequiredGameSystem] will automatically construct MyMod at game start/load. // do non-static initialization here e.g. adding IParts to player } }
using tyrir.lib; public class MySkill : BaseSkill , IModEventHandler<GetIsSkilledWithMissileWeaponEvent> { public override bool WantEvent(int ID, int cascade) { return ID == GetIsSkilledWithMissileWeaponEvent.ID || base.WantEvent(ID, cascade); } public bool HandleEvent(GetIsSkilledWithMissileWeaponEvent E) { if (E.Actor == ParentObject && E.MissileWeapon.Skill == "MySkill") E.IsSkilled = true; return base.HandleEvent(E); } }
1 Comments
wizardlibrarian 9 Jan @ 2:29pm 
This would probably be more useful if it was open sourced and/or the things it fixed were reported to the game’s bug tracker

Very interesting though!