//internal uint Handle { get { return mHandle; } } static void InitializeHandle(out uint handle, MegaloScriptModelObjectType type, int id) { var encoder = new Bitwise.HandleBitEncoder(); encoder.EncodeNoneable32(id, Constants.kIdBitField); encoder.Encode32(type, BitEncoders.MegaloScriptModelObjectType); Contract.Assert(encoder.UsedBitCount == MegaloScriptModelObjectHandle.BitCount); handle = encoder.GetHandle32(); }
static bool CanEmbed(MegaloScriptModelObjectType type) { switch (type) { case MegaloScriptModelObjectType.Condition: case MegaloScriptModelObjectType.Action: case MegaloScriptModelObjectType.Trigger: case MegaloScriptModelObjectType.VirtualTrigger: return(true); default: return(false); } }
static MegaloScriptModelObject CreateForWriteSansId(MegaloScriptModel model, MegaloScriptModelObjectType type) { switch (type) { case MegaloScriptModelObjectType.Condition: return(model.CreateCondition()); case MegaloScriptModelObjectType.Action: return(model.CreateAction()); case MegaloScriptModelObjectType.Trigger: return(model.CreateTrigger()); case MegaloScriptModelObjectType.VirtualTrigger: return(model.CreateVirtualTrigger()); default: throw new KSoft.Debug.UnreachableException(type.ToString()); } }
internal void SerializeOperationId <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, ref int type, MegaloScriptModelObjectType objType) where TDoc : class where TCursor : class { if (objType == MegaloScriptModelObjectType.Condition && TagElementStreamSerializeFlags.UseConditionTypeNames()) { string name = s.IsReading ? null : Database.Conditions[type].Name; s.StreamAttribute("name", ref name); if (s.IsReading) { Proto.MegaloScriptProtoCondition proto; if (Database.TryGetCondition(name, out proto)) { type = proto.DBID; } else { var ex = new KeyNotFoundException("Not a valid condition name: " + name); s.ThrowReadException(ex); } } } else if (objType == MegaloScriptModelObjectType.Action && TagElementStreamSerializeFlags.UseActionTypeNames()) { string name = s.IsReading ? null : Database.Actions[type].Name; s.StreamAttribute("name", ref name); if (s.IsReading) { Proto.MegaloScriptProtoAction proto; if (Database.TryGetAction(name, out proto)) { type = proto.DBID; } else { var ex = new KeyNotFoundException("Not a valid action name: " + name); s.ThrowReadException(ex); } } } else { s.StreamAttribute("DBID", ref type); } }
public MegaloScriptModelObjectHandle(MegaloScriptModelObjectType type, int id = TypeExtensions.kNone) { Contract.Requires(ValidateId(id)); InitializeHandle(out mHandle, type, id); }