GithubHelp home page GithubHelp logo

nomessyspawns's Introduction

No Messy Spawns

RimWorld 1.0 License: MIT

A shared Rimworld assembly to help eliminate code reuse while suppressing item spawn displacements (which became a thing with B19).

Usage

NoMessySpawns.Instance offers three methods:

/// <summary>
/// Adds a potential spawn displacement predicate. 
/// </summary>
/// <param name="discriminator">
/// A spawn displacement predicate. It should return <see langword = "false" /> if no displacement should
/// occur for the set of <c>position</c>/<c>map</c>/<c>respawningAfterLoad</c> arguments.
/// <seealso cref="DisplaceSuppressionDiscriminatorPredicate"/>
/// </param>
/// <param name="executionPriority">
/// Controls execution order of registered predicates. Lower values execute first.
/// </param>
/// <return>
/// A token which can optionally be used to remove this displacement suppression if no longer needed
/// <seealso cref="Remove"/>
/// </return>
public object Add(DisplaceSuppressionDiscriminatorPredicate discriminator,
                  int executionPriority = 0)

/// <summary>
/// Adds a potential spawn displacement predicate.
/// </summary>
/// <param name="discriminator">
/// A spawn displacement predicate. It should return <see langword = "false" /> if no displacement should
/// occur for the set of <c>position</c>/<c>map</c>/<c>respawningAfterLoad</c> arguments.
/// <seealso cref="DisplaceSuppressionDiscriminatorPredicate"/>
/// </param>
/// <param name="prioritySpawnCallback">
/// Allows prioritized spawning of things after map load (if those things need to already exist to allow
/// <paramref name="discriminator"/> to make a valid decision.
/// <typeparamref name="T"/> must derive from <see cref="Thing"/>. Priority spawning will happen for all
/// things which are of type <typeparamref name="T"/> for which <paramref name="prioritySpawnCallback"/>
/// returns <see langword="true" /> for the set of arguments <c>thing</c> and <c>map</c>.
/// <seealso cref="SpawnPrioritizationPredicate{T}"/>
/// </param>
/// <param name="executionPriority">
/// Controls execution order of registered predicates. Lower values execute first.
/// </param>
/// <return>
/// A token which can optionally be used to remove this displacement suppression if no longer needed
/// <seealso cref="Remove"/>
/// </return>
public object Add<T>(DisplaceSuppressionDiscriminatorPredicate discriminator,
                     SpawnPrioritizationPredicate<T> prioritySpawnCallback,
                     int executionPriority = 0) where T : Thing

/// <summary>
/// Allows removing a previously registered spawn displacement suppression handler
/// </summary>
/// <param name="token">Previous value from a call to <see cref="Add"/> or <see cref="Add{T}"/>.</param>
/// <returns><see langword="true" /> if a previous registration had been made for <paramref name="token"/>
/// and was successfully removed; <see langword="false"/> otherwise.</returns>
public bool Remove(object token)

Example

  • Reference (and embed in your distriubution) Assembly 0NoMessySpawns.dll (Also requires Harmony)
  • Add code for your displacement supression to your mod's initializer:
    partial class ExtendedStorageMod : Mod {
        public ExtendedStorageMod(ModContentPack content) : base(content)
        {
            try {
                ...
                NoMessySpawns.Instance.Add(
                    (position, map, respawningAfterLoad) => !respawningAfterLoad
                                                            || map?.thingGrid
                                                                   .ThingsListAtFast(position)
                                                                   .OfType<Building_ExtendedStorage>()
                                                                   .Any() != true,
                    (Building_ExtendedStorage b, Map m) => true);

            } catch (Exception ex) {
                Log.Error("Extended Storage :: Caught exception: " + ex);
            }
        }
    }

nomessyspawns's People

Contributors

doctorvangogh avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.