Den hier wollte ich nämlich: MultiFalsableBool, Babey!!

This commit is contained in:
Simon Lübeß 2024-04-04 18:04:28 +02:00
parent c1bc5ec714
commit 8013ec62a0
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,53 @@
using System;
using UnityEngine;
/// <summary>
/// Stell dir vor, du hättest einen Bool und der könnte einfach mehrmals falsch sein. Wäre das nicht total cool?
/// </summary>
[Serializable]
public struct MultiFalsableBool
{
[SerializeField]
private int _falseness;
public bool IsTrue => _falseness == 0;
public bool IsFalse => _falseness > 0;
/// <summary>
/// Macht den bool noch falscher als er vorher war. Wenn er vorher wahr wahr, dann ist er jetzt definitiv falsch.
/// </summary>
/// <returns>Der neue Wert.</returns>
public bool MakeFalslier()
{
_falseness++;
return this;
}
/// <summary>
/// Macht den bool nicht wahr, sondern lediglich wahrer als er vorher wahr. Wenn er allerdings nur einfach falsch wahr, dann ist er jetzt wahr.
/// Wenn er vorher wahr war, bleibt er wahr.
/// </summary>
/// <returns>Der neue Wert.</returns>
public bool MakeTruer()
{
if (_falseness > 0)
_falseness--;
return this;
}
public MultiFalsableBool(bool value) => _falseness = value ? 0 : 1;
/// <summary>
/// Erzeugt eine neue Instanz von MultiFalsableBool und initialisiert diese mit dem gegebenen Wert.
/// </summary>
/// <param name="value">Der Wert, der angibt, wie falsch der bool ist.</param>
public MultiFalsableBool(int value) => _falseness = (value > 0 ? value : 0);
public static implicit operator bool(MultiFalsableBool value) => value.IsTrue;
public static bool operator ==(MultiFalsableBool a, bool b) => a.IsTrue == b;
public static bool operator !=(MultiFalsableBool a, bool b) => a.IsTrue != b;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bc62ec449b954b119f12024eac70da9b
timeCreated: 1712244471