public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var xs = s.GetSerializerInterface(); s.StreamAttributeEnum("type", ref mDataType); s.StreamAttribute("name", ref mName); switch (DataType) { case ProtoPowerDataType.Float: s.StreamCursor(ref mDataFloat); break; case ProtoPowerDataType.Int: s.StreamCursor(ref mDataInt); break; case ProtoPowerDataType.ProtoObject: xs.StreamDBID(s, XML.XmlUtil.kNoXmlName, ref mDataInt, DatabaseObjectKind.Object, isOptional: false, xmlSource: XML.XmlUtil.kSourceCursor); break; case ProtoPowerDataType.ProtoSquad: xs.StreamDBID(s, XML.XmlUtil.kNoXmlName, ref mDataInt, DatabaseObjectKind.Squad, isOptional: false, xmlSource: XML.XmlUtil.kSourceCursor); break; case ProtoPowerDataType.Tech: xs.StreamDBID(s, XML.XmlUtil.kNoXmlName, ref mDataInt, DatabaseObjectKind.Tech, isOptional: false, xmlSource: XML.XmlUtil.kSourceCursor); break; case ProtoPowerDataType.ObjectType: xs.StreamDBID(s, XML.XmlUtil.kNoXmlName, ref mDataInt, DatabaseObjectKind.ObjectType, isOptional: false, xmlSource: XML.XmlUtil.kSourceCursor); break; case ProtoPowerDataType.Bool: s.StreamCursor(ref mDataBool); break; case ProtoPowerDataType.Sound: s.StreamCursor(ref mDataString); break; case ProtoPowerDataType.Texture: s.StreamCursor(ref mDataString); break; } //xs.StreamDBID(s, "ObjectType", ref mObjectType, DatabaseObjectKind.ObjectType, isOptional: false, xmlSource: XML.XmlUtil.kSourceAttr); }
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); }
static void StreamIconLocation <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, XML.BXmlSerializerInterface xs, ref int value) where TDoc : class where TCursor : class { s.StreamCursor(ref value); }
public bool StreamStringID <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, string xmlName, ref int value, IO.TagElementNodeType xmlSource = XmlUtil.kSourceElement) where TDoc : class where TCursor : class { Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName)); bool was_streamed = false; if (xmlSource == XmlUtil.kSourceElement) { was_streamed = s.StreamElementOpt(xmlName, ref value, Predicates.IsNotNone); } else if (xmlSource == XmlUtil.kSourceAttr) { was_streamed = s.StreamAttributeOpt(xmlName, ref value, Predicates.IsNotNone); } else if (xmlSource == XmlUtil.kSourceCursor) { was_streamed = true; s.StreamCursor(ref value); } if (s.IsReading) { if (value.IsNotNone()) { Database.AddStringIDReference(value); } } return(was_streamed); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { if (!s.StreamAttributeOpt("name", ref mCodeName, Predicates.IsNotNullOrEmpty)) { mCodeName = ""; } using (var bm = s.EnterCursorBookmarkOpt("String", this, obj => obj.JustEnglish)) if (bm.IsNotNull) { LanguageRegistry.CodeExpectsEnglishFirst(); int k_english_index = mLanguageTable.EnglishGameLangaugeHandle.GameIndex; s.StreamCursor(ref mLanguageStrings[k_english_index]); if (s.IsReading) { // empty cursor text returns null, at least in the XML implementation if (mLanguageStrings[k_english_index] == null) { mLanguageStrings[k_english_index] = ""; } for (int x = 1; x < mLanguageStrings.Length; x++) { mLanguageStrings[x] = mLanguageStrings[k_english_index]; } } } else { SerializeLanguages(s); } }
static void SerializeTriggerExecutionOrder <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, MegaloScriptModel model, ref int triggerIndex) where TDoc : class where TCursor : class { if (model.TagElementStreamSerializeFlags.EmbedObjects()) { var id_resolving_ctxt = new TriggerIndexNameResolvingContext(model); var id_resolver = TriggerIndexNameResolvingContext.IdResolver; var name_resolver = TriggerIndexNameResolvingContext.NameResolver; s.StreamCursorIdAsString(ref triggerIndex, id_resolving_ctxt, id_resolver, name_resolver); } else { s.StreamCursor(ref triggerIndex); if (model.Triggers.SlotIsFreeOrInvalidIndex(triggerIndex)) { var ex = new System.IO.InvalidDataException(string.Format( "Couldn't define execution order for invalid trigger index {0}", triggerIndex)); s.ThrowReadException(ex); } } if (!model.Triggers[triggerIndex].TriggerType.IsUpdatedOnGameTick()) { var ex = new System.IO.InvalidDataException(string.Format( "Trigger '{0}' can't have its execution explicitly ordered", triggerIndex.ToString() )); s.ThrowReadException(ex); } }
void Read <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s, bool embedValues) where TDoc : class where TCursor : class { int param_index = 0; foreach (var node in s.ElementsByName("Param")) { using (s.EnterCursorBookmark(node)) { if (embedValues) { MegaloScriptValueBase.SerializeValueForEmbed(model, s, ref mValueIds[param_index]); } else { s.StreamCursor(ref mValueIds[param_index]); } Contract.Assert(mValueIds[param_index].IsNotNone()); param_index++; if (param_index == mValueIds.Length) { break; } } } }
/// <summary>Stream the current element's Text as a a string</summary> internal static void StreamStringValue <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, BXmlSerializerInterface xs, ref string value) where TDoc : class where TCursor : class { s.StreamCursor(ref value); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { s.StreamAttribute("Max", ref mMax); s.StreamCursor(ref mCount); }
void Write <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s, bool embedValues) where TDoc : class where TCursor : class { bool multiple_params = mValueIds.Length > 1; bool write_extra_info = s.IsWriting && model.TagElementStreamSerializeFlags.HasParamFlags(); for (int x = 0; x < mValueIds.Length; x++) { using (s.EnterCursorBookmark("Param")) { if (write_extra_info) { ProtoData.ParameterList[x].WriteExtraModelInfo(model.Database, s, multiple_params, model.TagElementStreamSerializeFlags); } Contract.Assert(mValueIds[x].IsNotNone()); if (embedValues) { MegaloScriptValueBase.SerializeValueForEmbed(model, s, ref mValueIds[x]); } else { s.StreamCursor(ref mValueIds[x]); } } } }
protected static void StreamValue <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, string valueName, ref string value, bool useInnerText, bool useElement, bool internValue, bool toLower) where TDoc : class where TCursor : class { if (useInnerText) { s.StreamCursor(ref value); } else if (useElement) { s.StreamElement(valueName, ref value); } else if (valueName != null) { s.StreamAttribute(valueName, ref value); } if (s.IsReading) { if (toLower) { value = value.ToLowerInvariant(); } if (internValue) { value = string.Intern(value); } } }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { s.StreamAttributeEnum("Mode", ref mMode); s.StreamCursor(ref mAnimType); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { s.StreamCursor(ref mAttachmentName); s.StreamElementOpt("Hitpoints", ref mHitpoints, PhxPredicates.IsNotInvalid); s.StreamElementOpt("Shieldpoints", ref mShieldpoints, PhxPredicates.IsNotInvalid); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var xs = s.GetSerializerInterface(); xs.StreamDBID(s, "ObjectType", ref mObjectType, DatabaseObjectKind.ObjectType, isOptional: false, xmlSource: XML.XmlUtil.kSourceAttr); s.StreamCursor(ref mEffectiveness); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var xs = s.GetSerializerInterface(); xs.StreamDBID(s, "type", ref mUnitTypeID, DatabaseObjectKind.Unit, false, XML.XmlUtil.kSourceAttr); s.StreamCursor(ref mPriority); }
static int SerializeEngineOptionToggle <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, Collections.BitSet bitset, int bitIndex, GameEngineMegaloVariant variant) where TDoc : class where TCursor : class { s.StreamCursor(ref bitIndex); return(bitIndex); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { s.StreamAttributeOpt("rating", ref mRating, PhxPredicates.IsNotOne); s.StreamCursor(ref mDamagePercentage); s.StreamAttributeOpt("reflectDamageFactor", ref mReflectDamageFactor, Predicates.IsNotZero); s.StreamAttributeOpt("bowlable", ref mBowlable, Predicates.IsTrue); s.StreamAttributeOpt("rammable", ref mRammable, Predicates.IsTrue); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { s.StreamCursor(ref mName); s.StreamAttribute("ikRange", ref mIKRange); s.StreamAttribute("linkCount", ref mLinkCount); s.StreamAttributeOpt("x", ref mAxisPositioning.X, Predicates.IsNotZero); s.StreamAttributeOpt("z", ref mAxisPositioning.Z, Predicates.IsNotZero); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { s.StreamAttributeOpt("sizeX", ref mSize.X, f => f != 2.0f); s.StreamAttributeOpt("sizeZ", ref mSize.Z, f => f != 2.0f); s.StreamAttributeOpt("timeFullyOpaque", ref mTimeFullyOpaque, f => f != 5.0f); s.StreamAttributeOpt("fadeOutTime", ref mFadeOutTime, f => f != 10.0f); s.StreamAttributeEnumOpt("orientation", ref mOrientation, e => e != OrientationType.Random); s.StreamCursor(ref mTextureName); }
void SerializeData <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s, Proto.MegaloScriptValueType valueType) where TDoc : class where TCursor : class { var base_type = valueType.BaseType; switch (base_type) { case Proto.MegaloScriptValueBaseType.Int: case Proto.MegaloScriptValueBaseType.UInt: s.StreamCursor(ref Data); break; case Proto.MegaloScriptValueBaseType.Var: if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.UseIndexNames) != 0) { var resolving_ctxt = new MegaloScriptModelVariableSet.IndexNameResolvingContext(model, valueType); s.StreamCursorIdAsString(ref Data, resolving_ctxt, MegaloScriptModelVariableSet.IndexNameResolvingContext.IdResolver, MegaloScriptModelVariableSet.IndexNameResolvingContext.NameResolver); } else { s.StreamCursor(ref Data); } break; case Proto.MegaloScriptValueBaseType.Enum: MegaloScriptEnumValue.SerializeValue(model, s, valueType, ref Data, IO.TagElementNodeType.Text); break; case Proto.MegaloScriptValueBaseType.Index: MegaloScriptIndexValue.SerializeValue(model, s, valueType, ref Data, IO.TagElementNodeType.Text); break; default: throw new KSoft.Debug.UnreachableException(base_type.ToString()); } }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { if (s.IsReading) { s.ReadCursorName(ref mType); } s.StreamAttribute(kXmlAttrSigId, ref mSigID); s.StreamAttribute(DatabaseNamedObject.kXmlAttrNameN, ref mName); s.StreamAttribute(kXmlAttrOptional, ref mOptional); s.StreamCursor(ref mVarID); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var xs = s.GetSerializerInterface(); s.StreamCursor(ref mSound); if (s.StreamAttributeEnumOpt("Type", ref mType, e => e != BObjectSoundType.None)) { xs.StreamDBID(s, "Squad", ref mSquadID, DatabaseObjectKind.Squad, xmlSource: XML.XmlUtil.kSourceAttr); s.StreamAttributeOpt("Action", ref mAction, Predicates.IsNotNullOrEmpty); } }
public void Serialize<TDoc, TCursor>(IO.TagElementStream<TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var xs = s.GetSerializerInterface(); xs.StreamDBID(s, "Civ", ref mCivID, DatabaseObjectKind.Civ, xmlSource: XML.XmlUtil.kSourceAttr); if (!xs.StreamTypeName(s, BResource.kBListTypeValuesXmlParams_Cost.DataName, ref mResourceType, GameDataObjectKind.Cost, isOptional: false, xmlSource: XML.XmlUtil.kSourceAttr)) s.ThrowReadException(new System.IO.InvalidDataException(string.Format( "ProtoObject's {0} XML doesn't define a {1}", kBListXmlParams.ElementName, BResource.kBListTypeValuesXmlParams_Cost.DataName))); s.StreamCursor(ref mCost); }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { s.StreamAttribute("_locID", ref mID); s.StreamAttributeEnumOpt("category", ref mCategory, e => e != LocStringCategory.None); s.StreamAttributeOpt("scenario", ref mScenario, Predicates.IsNotNullOrEmpty); s.StreamAttributeOpt("subtitle", ref mIsSubtitle, Predicates.IsTrue); s.StreamAttributeOpt("Update", ref mIsUpdate, Predicates.IsTrue); s.StreamAttributeOpt("_mouseKeyboard", ref mMouseKeyboardID, Predicates.IsNotNone); s.StreamAttributeOpt("originally", ref mOriginalID, Predicates.IsNotNullOrEmpty); if (s.IsReading || mText.IsNotNullOrEmpty()) { s.StreamCursor(ref mText); } }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var xs = s.GetSerializerInterface(); s.StreamCursor(ref mSound); if (s.StreamAttributeEnumOpt("Type", ref mType, e => e != BSquadSoundType.None)) { // #NOTE Engine, in debug builds, asserts Squad is valid when specified xs.StreamDBID(s, "Squad", ref mSquadID, DatabaseObjectKind.Squad, xmlSource: XML.XmlUtil.kSourceAttr); // #NOTE Engine, in debug builds, asserts the world ID is not cWorldIdNone when the World value is defined. // It doesn't explicitly parse None, but defaults to None when it doesn't recognize the provided value s.StreamProtoEnum("World", ref mWorldID, xs.Database.GameScenarioWorlds, xmlSource: XML.XmlUtil.kSourceAttr , isOptionalDefaultValue: cWorldIdNone); s.StreamAttributeOpt("CastingUnitOnly", ref mCastingUnitOnly, Predicates.IsTrue); } }
protected static void StreamValue <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, string valueName, ref int value, bool useInnerText, bool useElement) where TDoc : class where TCursor : class { if (useInnerText) { s.StreamCursor(ref value); } else if (useElement) { s.StreamElement(valueName, ref value); } else if (valueName != null) { s.StreamAttribute(valueName, ref value); } }
protected override void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s) { if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.UseIndexNames) != 0) { var resolving_ctxt = new MegaloScriptModelVariableSet.IndexNameResolvingContext(model, ValueType, supportNone: true); s.StreamCursorIdAsString(ref mValue, resolving_ctxt, MegaloScriptModelVariableSet.IndexNameResolvingContext.IdResolver, MegaloScriptModelVariableSet.IndexNameResolvingContext.NameResolver); } else { s.StreamCursor(ref mValue); } if (!ValidateValue(model)) { throw new System.IO.InvalidDataException(string.Format("VarIndex value #{0} has an invalid value {1}", Id, Value)); } }
internal static void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s, MegaloScriptValueType valueType, ref uint value, IO.TagElementNodeType nodeType = IO.TagElementNodeType.Text, string nodeName = null) where TDoc : class where TCursor : class { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Flags); if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.UseEnumNames) != 0) { var id_resolving_ctxt = new Proto.MegaloScriptEnum.FlagsNameResolvingContext(model.Database, valueType); var id_resolver = Proto.MegaloScriptEnum.FlagsNameResolvingContext.IdResolver; var name_resolver = Proto.MegaloScriptEnum.FlagsNameResolvingContext.NameResolver; switch (nodeType) { case IO.TagElementNodeType.Element: s.StreamElementIdAsString(nodeName, ref value, id_resolving_ctxt, id_resolver, name_resolver); break; case IO.TagElementNodeType.Attribute: s.StreamAttributeIdAsString(nodeName, ref value, id_resolving_ctxt, id_resolver, name_resolver); break; case IO.TagElementNodeType.Text: s.StreamCursorIdAsString(ref value, id_resolving_ctxt, id_resolver, name_resolver); break; } } else { switch (nodeType) { case IO.TagElementNodeType.Element: s.StreamElement(nodeName, ref value); break; case IO.TagElementNodeType.Attribute: s.StreamAttribute(nodeName, ref value); break; case IO.TagElementNodeType.Text: s.StreamCursor(ref value); break; } } }
void SerializeLanguages <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { bool writing = s.IsWriting; GameLanguageHandle english_game_lang_hHandle = mLanguageTable.EnglishGameLangaugeHandle; for (int x = 0; x < mLanguageStrings.Length; x++) { if (writing && mLanguageStrings[x] == null) { continue; } GameLanguageHandle game_lang_handle = mLanguageTable.GetGameLanguage(x); using (var bm = s.EnterCursorBookmarkOpt(game_lang_handle.LanguageName)) if (bm.IsNotNull) { s.StreamCursor(ref mLanguageStrings[x]); } else { if (x == english_game_lang_hHandle.GameIndex) { s.ThrowReadException(new System.IO.InvalidDataException( "Tried to serialize multilingual string with no English translation")); } // Eg, HaloReach didn't originally ship with Polish loc support, so don't force to English at this level in those cases. bool game_lang_is_optional = mLanguageTable.IsGameLanguageOptional(x); // If ChineseSimple is empty, engine will fall back to ChineseTraditional (for HaloReach and H4 at least) bool game_lang_is_chinese_simple = game_lang_handle.LanguageIndex == LanguageRegistry.ChineseSimpleIndex; if (!game_lang_is_chinese_simple && !game_lang_is_optional) { // default to english if there's no element for this lang mLanguageStrings[x] = mLanguageStrings[english_game_lang_hHandle.GameIndex]; } } } }
internal static void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s, MegaloScriptValueType valueType, ref int value, IO.TagElementNodeType nodeType = IO.TagElementNodeType.Text, string nodeName = null) where TDoc : class where TCursor : class { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Index); var target = valueType.IndexTarget; if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) != 0 && target == MegaloScriptValueIndexTarget.Trigger) { SerializeTriggerReferenceValue(model, s, valueType, ref value); } #region UseIndexNames else if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.UseIndexNames) != 0 && target.HasIndexName()) { var id_resolving_ctxt = new MegaloScriptModel.IndexNameResolvingContext(model, target); var id_resolver = MegaloScriptModel.IndexNameResolvingContext.IdResolver; var name_resolver = MegaloScriptModel.IndexNameResolvingContext.NameResolver; switch (nodeType) { case IO.TagElementNodeType.Element: s.StreamElementIdAsString(nodeName, ref value, id_resolving_ctxt, id_resolver, name_resolver); break; case IO.TagElementNodeType.Attribute: s.StreamAttributeIdAsString(nodeName, ref value, id_resolving_ctxt, id_resolver, name_resolver); break; case IO.TagElementNodeType.Text: s.StreamCursorIdAsString(ref value, id_resolving_ctxt, id_resolver, name_resolver); break; } } #endregion else { switch (nodeType) { case IO.TagElementNodeType.Element: s.StreamElement(nodeName, ref value); break; case IO.TagElementNodeType.Attribute: s.StreamAttribute(nodeName, ref value); break; case IO.TagElementNodeType.Text: s.StreamCursor(ref value); break; } } // #REVIEW_BLAM: this will fail when embedding and the target is a Trigger since we don't preload triggers or such if (s.IsReading && ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) == 0 || target != MegaloScriptValueIndexTarget.Trigger) ) { if (!model.IndexTargetIsValid(target, valueType.IndexTraits, value)) { s.ThrowReadException(new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo, "A {0} reference has an invalid value {1}", target, value))); } } }