Class Cassowary
Represents a Cassowary engine structure.
A Cassowary is a type of solver. NWN uses them internally to resize the newer GUI window.
public sealed class Cassowary : EngineStructure, IDisposable
- Inheritance
-
Cassowary
- Implements
- Inherited Members
- Extension Methods
Examples
/*
* Examples for creating and using Cassowary solvers.
*/
using Anvil.API;
using Anvil.Services;
using NLog;
namespace NWN.Anvil.Samples.API.EngineStructures
{
[ServiceBinding(typeof(CassowaryExamples))]
public class CassowaryExamples
{
// Gets the server log. By default, this reports to "anvil.log"
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
// Based on https://nwnlexicon.com/index.php?title=Cassowary & https://cassowary.readthedocs.io/en/latest/topics/theory.html
public CassowaryExamples()
{
// Create an empty cassowary solver.
Cassowary cTest = new Cassowary();
// Add some constraints
cTest.AddConstraint("middle == (left + right) / 2");
cTest.AddConstraint("right == left + 10");
cTest.AddConstraint("right <= 100");
cTest.AddConstraint("left >= 0");
// Results should be 90, 95 and 100
Log.Info($"Solution 1: Left: {cTest.GetValue("left")}, Middle: {cTest.GetValue("middle")}, Right: {cTest.GetValue("right")}");
// Suggest middle is 45
cTest.SuggestValue("middle", 45f);
// Results should now be 40, 45 and 50
Log.Info($"Solution 2: Left: {cTest.GetValue("left")}, Middle: {cTest.GetValue("middle")}, Right: {cTest.GetValue("right")}");
}
}
}
Constructors
- Cassowary()
Creates a new Cassowary solver.
Properties
- DebugState
Gets a printable debug state of this solver, which may help you debug complex systems.
Methods
- AddConstraint(string, float)
Adds a constraint to the system.
You cannot multiply or divide variables and expressions with each other.
Doing so will result in a error when attempting to add the constraint.
(You can, of course, multiply or divide by constants).
- GetValue(string)
Gets the value for the specified variable.
- Reset()
Clear out this solver, removing all state, constraints and suggestions.
- SuggestValue(string, float, float)
Suggests a value to the solver.