Class MultiReasonBool

java.lang.Object
com.prineside.tdi2.utils.MultiReasonBool
All Implemented Interfaces:
KryoSerializable

public final class MultiReasonBool extends Object implements KryoSerializable
Acts as a regular boolean field / flag which can be affected by multiple sources. Instead of storing a plain "true" / "false" data, it stores a list of reasons why the field is true, and acts as a boolean "true" (isTrue() method) if there's at least one reason. Max 127 reasons at the same time.
  • Constructor Details

    • MultiReasonBool

      public MultiReasonBool()
  • Method Details

    • write

      public void write(Kryo kryo, Output output)
      Specified by:
      write in interface KryoSerializable
    • read

      public void read(Kryo kryo, Input input)
      Specified by:
      read in interface KryoSerializable
    • addReason

      public boolean addReason(String reason)
      Sets maximum duration
      Returns:
      true if added or updated
    • addReasonForDuration

      public boolean addReasonForDuration(String reason, float duration)
      Returns:
      true if added or updated
    • hasReason

      public boolean hasReason(String reason)
    • removeReason

      public boolean removeReason(String reason)
      Returns:
      true if has been removed
    • getReasonCount

      public int getReasonCount()
    • isTrue

      public boolean isTrue()
    • update

      public void update(float deltaTime)
      Expire reasons
    • clear

      public void clear()
    • getReasonsBuffer

      public MultiReasonBool.Entry[] getReasonsBuffer()
      Use getReasonCount() first If reason count is 0, this method may return null Iteration: String[] reasons = getReasonsBuffer(); for (int i = 0, n = bool.getReasonCount(); i < n; i++) { reasons[i] ... }
    • toString

      public String toString()
      Overrides:
      toString in class Object