void SerializeData(MegaloScriptModel model, IO.BitStream s, Proto.MegaloScriptValueType valueType) { var base_type = valueType.BaseType; switch (base_type) { case Proto.MegaloScriptValueBaseType.Int: s.Stream(ref Data, valueType.BitLength, signExtend: true); break; case Proto.MegaloScriptValueBaseType.UInt: case Proto.MegaloScriptValueBaseType.Var: s.Stream(ref Data, valueType.BitLength); break; case Proto.MegaloScriptValueBaseType.Enum: MegaloScriptEnumValue.SerializeValue(model, s, valueType, ref Data); break; case Proto.MegaloScriptValueBaseType.Index: MegaloScriptIndexValue.SerializeValue(model, s, valueType, ref Data); break; default: throw new KSoft.Debug.UnreachableException(base_type.ToString()); } }
public bool EnumIndexIsValid(Proto.MegaloScriptValueType enumType, int index) { Contract.Requires(enumType.BaseType == Proto.MegaloScriptValueBaseType.Enum); var e = Database.Enums[enumType.EnumIndex]; var etraits = enumType.EnumTraits; if (etraits == Proto.MegaloScriptValueEnumTraits.HasNoneMember) { index += 1; } return(index >= 0 && index < e.Members.Count); }
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 IndexNameResolvingContext(MegaloScriptModel model, Proto.MegaloScriptValueType valueType, bool supportNone = false) { Model = model; VarSet = valueType.VarSet; VarType = valueType.VarType; SupportNone = supportNone; }
protected MegaloScriptValueBase(Proto.MegaloScriptValueType valueType) { ValueType = valueType; }
/// <summary>Create the identiy of an existing value based on an its core traits</summary> /// <param name="valueType"></param> /// <param name="id"></param> /// <returns></returns> internal MegaloScriptValueBase Recreate(Proto.MegaloScriptValueType valueType, int id) { return(CreateValue(valueType, id)); }
public MegaloScriptValueBase CreateValue(Proto.MegaloScriptValueType valueType, int id = TypeExtensions.kNone) { return(CreateObjectPostprocess(Values, NewValue(valueType), id)); }