Created
February 24, 2018 10:31
-
-
Save clarvalon/10591acb4392d1b5c09af67513d63af4 to your computer and use it in GitHub Desktop.
IntegerBool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace Clarvalon.XAGE.Global | |
{ | |
/// <summary> | |
/// Can operate as both an integer and a bool (as a workaround for lax AGS typing). | |
/// </summary> | |
public struct IntegerBool | |
{ | |
/// <summary> | |
/// 0 = false, 1+ = true | |
/// </summary> | |
public int Value; | |
/// <summary> | |
/// Integer Constructor | |
/// </summary> | |
/// <param name="v"></param> | |
public IntegerBool(int v) | |
{ | |
Value = v; | |
} | |
/// <summary> | |
/// Boolean Constructor | |
/// </summary> | |
/// <param name="b"></param> | |
public IntegerBool(bool b) | |
{ | |
if (b) | |
Value = 1; | |
else | |
Value = 0; | |
} | |
/// <summary> | |
/// Get integer value from IntegerBool | |
/// </summary> | |
/// <param name="b"></param> | |
public static implicit operator int(IntegerBool b) | |
{ | |
return b.Value; | |
} | |
/// <summary> | |
/// Get bool value from IntegerBool | |
/// </summary> | |
/// <param name="b"></param> | |
public static implicit operator bool(IntegerBool b) | |
{ | |
if (b.Value > 0) | |
return true; | |
else | |
return false; | |
} | |
/// <summary> | |
/// Get IntegerBool from integer | |
/// </summary> | |
/// <param name="i"></param> | |
public static implicit operator IntegerBool(int i) | |
{ | |
return new IntegerBool(i); | |
} | |
/// <summary> | |
/// Get IntegerBool from bool | |
/// </summary> | |
/// <param name="b"></param> | |
public static implicit operator IntegerBool(bool b) | |
{ | |
return new IntegerBool(b); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment