Exemplo n.º 1
0
        static int SerializeUserOptionToggle <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                             Collections.BitSet bitset, int bitIndex, GameEngineMegaloVariant variant)
            where TDoc : class
            where TCursor : class
        {
            if (!variant.TagElementStreamSerializeFlags.UseUserOptionNames())
            {
                s.StreamCursor(ref bitIndex);
            }
            else if (s.IsReading)
            {
                string option_name = null;
                s.ReadCursor(ref option_name);
                bitIndex = variant.EngineDefinition.FromIndexName(
                    Megalo.Proto.MegaloScriptValueIndexTarget.Option, option_name);
            }
            else if (s.IsWriting)
            {
                string option_name = variant.EngineDefinition.ToIndexName(
                    Megalo.Proto.MegaloScriptValueIndexTarget.Option, bitIndex);
                s.WriteCursor(option_name);
            }

            return(bitIndex);
        }
Exemplo n.º 2
0
        protected override void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
        {
            if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) != 0)
            {
                using (s.EnterCursorBookmark("VT"))                 // have to nest or MegaloScriptModelObjectHandle will overwrite our Param ID with the VT's
                    MegaloScriptModelObjectHandle.SerializeForEmbed(s, model, ref mVirtualTriggerHandle);
            }
            else
            {
                if (s.IsReading)
                {
                    int id = TypeExtensions.kNone; s.ReadCursor(ref id);
                    if (id < 0)
                    {
                        throw new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo,
                                                                               "VirtualTrigger value #{0} has an invalid value {1}", Id, id));
                    }

                    mVirtualTriggerHandle = model.VirtualTriggers[id].Handle;
                }
                else
                {
                    s.WriteCursor(VirtualTriggerHandle.Id);
                }
            }
        }
        protected override void Read <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, BXmlSerializerInterface xs, int iteration)
        {
            int index = ReadExplicitIndex(s, xs);

            ListExplicitIndex.InitializeItem(index);
            int value = 0;

            s.ReadCursor(ref value);
            ListExplicitIndex[index] = value;
        }
Exemplo n.º 4
0
        internal static void SerializeValueForEmbed <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s,
                                                                    ref int valueId)
            where TDoc : class
            where TCursor : class
        {
            bool is_global = false;
            MegaloScriptValueBase value = null;

            if (s.IsReading)
            {
                if (s.ReadAttributeOpt(kIsGlobalAttributeName, ref is_global) && is_global)
                {
                    s.ReadCursor(ref valueId);
                }
                else
                {
                    bool streamed_sans_ids = model.TagElementStreamSerializeFlags.EmbedObjectsWriteSansIds();
                    var  value_type        = ReadType(s, model.Database);

                    if (streamed_sans_ids)
                    {
                        valueId = TypeExtensions.kNone;                                         // set to NONE to automatically add
                    }
                    else
                    {
                        SerializeId(s, ref valueId);
                    }

                    value = model.Recreate(value_type, valueId);

                    if (streamed_sans_ids)                     // since the stream didn't have the id, we need to explicit set it via value
                    {
                        valueId = value.Id;
                    }
                }
            }
            else
            {
                value = model.Values[valueId];
                if (is_global = value.IsGlobal)
                {
                    s.WriteAttribute(kIsGlobalAttributeName, true);
                    s.WriteCursor(valueId);
                }
            }

            if (!is_global)             // stream non-global values essentially like locals
            {
                Contract.Assume(value != null);
                value.Serialize(model, s);
            }
        }
        static int SerializeObjectTypeReference <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                                Collections.BitSet bitset, int bitIndex, MegaloScriptModel model)
            where TDoc : class
            where TCursor : class
        {
            if (s.IsReading)
            {
                string object_name = null;
                s.ReadCursor(ref object_name);
                bitIndex = model.FromIndexName(Proto.MegaloScriptValueIndexTarget.ObjectType, object_name);
            }
            else if (s.IsWriting)
            {
                string object_name = model.ToIndexName(Proto.MegaloScriptValueIndexTarget.ObjectType, bitIndex);
                s.WriteCursor(object_name);
            }

            return(bitIndex);
        }
Exemplo n.º 6
0
        static int SerializeBitIndex <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                     Collections.BitSet bitset, int bitIndex, object _null)
            where TDoc : class
            where TCursor : class
        {
            if (s.IsReading)
            {
                string platform_name = null;
                s.ReadCursor(ref platform_name);
                bitIndex = TargetPlatformIdResolver(null, platform_name);
            }
            else if (s.IsWriting)
            {
                string platform_name = TargetPlatformNameResolver(null, bitIndex);
                s.WriteCursor(platform_name);
            }

            return(bitIndex);
        }
        public static bool StreamCursorBytesOpt <TDoc, TCursor, T>(this IO.TagElementStream <TDoc, TCursor, string> s, T obj, Exprs.Expression <Func <T, byte[]> > propExpr)
            where TDoc : class
            where TCursor : class
        {
            Contract.Requires(s != null);

            bool executed = false;

            var property = Reflection.Util.PropertyFromExpr(propExpr);

            if (s.IsReading)
            {
                string str_value = null;
                s.ReadCursor(ref str_value);
                if (str_value.IsNotNullOrEmpty())
                {
                    var value = Text.Util.ByteStringToArray(str_value);
                    if (value.IsNotNullOrEmpty())
                    {
                        property.SetValue(obj, value, null);
                        executed = true;
                    }
                }
            }
            else if (s.IsWriting)
            {
                var value = (byte[])property.GetValue(obj, null);
                if (value.IsNotNullOrEmpty())
                {
                    string str_value = Text.Util.ByteArrayToString(value);
                    if (str_value.IsNotNullOrEmpty())
                    {
                        s.WriteCursor(str_value);
                        executed = true;
                    }
                }
            }

            return(executed);
        }