示例#1
0
 public override void WriteCopyTo(StreamWriter function, Variable variable)
 {
     if (variable is Pointer <VarBool> pointer)
     {
         pointer.Variable = this;
     }
     else if (variable is VarInt varInt || variable.TryCast(VarInt.StaticTypeName, out varInt))
     {
         function.WriteLine($"scoreboard players operation var {varInt.Objective.ID} = var {Objective.ID}");
     }
示例#2
0
 public override Variable InvokeOperation(Operation operation, Variable operand, ScriptTrace trace)
 {
     switch (operation)
     {
     case Operation.Set: {
         if (operand is VarEntity entity || operand.TryCast(TypeName, out entity))
         {
             Selector    = entity.Selector;
             Constructed = true;
             return(this);
         }
示例#3
0
 public override Variable InvokeOperation(Operation operation, Variable operand, ScriptTrace trace)
 {
     switch (operation)
     {
     case Operation.Equal: {
         if (operand is VarPrimitive right || operand.TryCast(TypeName, out right))
         {
             VarBool result;
             if (Usage == Usage.Constant)
             {
                 if (right.Usage == Usage.Constant)
                 {
                     result = new VarBool(Access.Private, Usage.Constant, GetNextHiddenID(), Scope);
                     result.SetValue(Constant == right.Constant ? 1 : 0);
                 }
                 else
                 {
                     result = new VarBool(Access.Private, Usage.Default, GetNextHiddenID(), Scope);
                     result.SetValue(0);
                     new Spy(null, $"execute if score " +
                             $"{right.Selector.GetConstant()} {right.Objective.GetConstant()} matches " +
                             $"{Constant} run " +
                             $"scoreboard players set {result.Selector.GetConstant()} {result.Objective.GetConstant()} 1", null);
                 }
             }
             else
             {
                 if (right.Usage == Usage.Constant)
                 {
                     result = new VarBool(Access.Private, Usage.Default, GetNextHiddenID(), Scope);
                     result.SetValue(0);
                     new Spy(null, $"execute if score " +
                             $"{Selector.GetConstant()} {Objective.GetConstant()} matches " +
                             $"{right.Constant} run " +
                             $"scoreboard players set {result.Selector.GetConstant()} {result.Objective.GetConstant()} 1", null);
                 }
                 else
                 {
                     result = new VarBool(Access.Private, Usage.Default, GetNextHiddenID(), Scope);
                     result.SetValue(0);
                     new Spy(null, $"execute if score " +
                             $"{Selector.GetConstant()} {Objective.GetConstant()} = " +
                             $"{right.Selector.GetConstant()} {right.Objective.GetConstant()} run " +
                             $"scoreboard players set {result.Selector.GetConstant()} {result.Objective.GetConstant()} 1", null);
                 }
             }
             return(result);
         }
示例#4
0
        public override Variable InvokeOperation(Operation operation, Variable operand, ScriptTrace trace)
        {
            switch (operation)
            {
            case Operation.Set: {
#if DEBUG_OUT
                new Spy(null, $"# OP # {this}@{Scope} := {operand}@{operand.Scope}", null);
#endif
                if ((operand is VarStruct varStruct || operand.TryCast(TypeName, out varStruct)) &&
                    varStruct.TypeName == TypeName /* || [TODO:  user-defined casts] */)
                {
                    foreach ((string field, Variable value) in varStruct.Fields)
                    {
                        Fields[field].InvokeOperation(Operation.Set, value, trace);
                    }
                    return(this);
                }
示例#5
0
 public override void WriteCopyTo(StreamWriter function, Variable variable)
 {
     if (variable is Pointer <VarInt> pointer)
     {
         pointer.Variable = this;
     }
     else if (variable is VarInt varInt || variable.TryCast(StaticTypeName, out varInt))
     {
         if (Usage == Usage.Constant)
         {
             function.WriteLine($"scoreboard players set {varInt.Selector.GetConstant()} {varInt.Objective.GetConstant()} {Constant}");
         }
         else
         {
             function.WriteLine($"scoreboard players operation {varInt.Selector.GetConstant()} {varInt.Objective.GetConstant()} = {Selector.GetConstant()} {Objective.GetConstant()}");
         }
     }