diff --git a/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs b/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs new file mode 100644 index 00000000..0375c1cf --- /dev/null +++ b/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs @@ -0,0 +1,53 @@ +using System; +using UnityEngine; + +/// +/// Stell dir vor, du hättest einen Bool und der könnte einfach mehrmals falsch sein. Wäre das nicht total cool? +/// +[Serializable] +public struct MultiFalsableBool +{ + [SerializeField] + private int _falseness; + + public bool IsTrue => _falseness == 0; + public bool IsFalse => _falseness > 0; + + /// + /// Macht den bool noch falscher als er vorher war. Wenn er vorher wahr wahr, dann ist er jetzt definitiv falsch. + /// + /// Der neue Wert. + public bool MakeFalslier() + { + _falseness++; + + return this; + } + + /// + /// 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. + /// + /// Der neue Wert. + public bool MakeTruer() + { + if (_falseness > 0) + _falseness--; + + return this; + } + + public MultiFalsableBool(bool value) => _falseness = value ? 0 : 1; + + /// + /// Erzeugt eine neue Instanz von MultiFalsableBool und initialisiert diese mit dem gegebenen Wert. + /// + /// Der Wert, der angibt, wie falsch der bool ist. + 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; +} diff --git a/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs.meta b/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs.meta new file mode 100644 index 00000000..afb565a5 --- /dev/null +++ b/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bc62ec449b954b119f12024eac70da9b +timeCreated: 1712244471 \ No newline at end of file