예제 #1
0
        /// <summary>
        ///     Decodes a command.
        /// </summary>
        public static LogicCommand DecodeCommand(ByteStream stream)
        {
            LogicCommand command = LogicCommandManager.CreateCommand(stream.ReadInt());

            if (command == null)
            {
                Debugger.Error("LogicCommandManager::decodeCommand() - command is null");
            }
            else
            {
                command.Decode(stream);
            }

            return(command);
        }
예제 #2
0
        /// <summary>
        ///     Decodes this instance.
        /// </summary>
        public void Decode(ByteStream stream)
        {
            if (this._commandList.Count != 0)
            {
                do
                {
                    this._commandList[0].Destruct();
                    this._commandList.Remove(0);
                } while (this._commandList.Count != 0);
            }

            stream.EnableCheckSum(false);

            for (int i = 0, commandCount = stream.ReadInt(); i < commandCount; i++)
            {
                this._commandList.Add(LogicCommandManager.DecodeCommand(stream));
            }

            stream.EnableCheckSum(true);
        }
예제 #3
0
        /// <summary>
        ///     Loads command from json.
        /// </summary>
        public static LogicCommand LoadCommandFromJSON(LogicJSONObject jsonObject)
        {
            LogicJSONNumber jsonNumber = jsonObject.GetJSONNumber("ct");

            if (jsonNumber == null)
            {
                Debugger.Error("loadCommandFromJSON - Unknown command type");
            }
            else
            {
                LogicCommand command = LogicCommandManager.CreateCommand(jsonNumber.GetJSONNodeType());

                if (command != null)
                {
                    command.LoadFromJSON(jsonObject.GetJSONObject("c"));
                }

                return(command);
            }

            return(null);
        }