/// <summary> /// Decodes gesture assset into play sequence /// </summary> /// <returns>true if the asset data was decoded successfully</returns> public override bool Decode() { try { string[] lines = Utils.BytesToString(AssetData).Split('\n'); Sequence = new List <GestureStep>(); int i = 0; // version int version = int.Parse(lines[i++]); if (version != 2) { throw new Exception("Only know how to decode version 2 of gesture asset"); } TriggerKey = byte.Parse(lines[i++]); TriggerKeyMask = uint.Parse(lines[i++]); Trigger = lines[i++]; ReplaceWith = lines[i++]; int count = int.Parse(lines[i++]); if (count < 0) { throw new Exception("Wrong number of gesture steps"); } for (int n = 0; n < count; n++) { GestureStepType type = (GestureStepType)int.Parse(lines[i++]); switch (type) { case GestureStepType.EOF: goto Finish; case GestureStepType.Animation: { GestureStepAnimation step = new GestureStepAnimation(); step.Name = lines[i++]; step.ID = new UUID(lines[i++]); int flags = int.Parse(lines[i++]); if (flags == 0) { step.AnimationStart = true; } else { step.AnimationStart = false; } Sequence.Add(step); break; } case GestureStepType.Sound: { GestureStepSound step = new GestureStepSound(); step.Name = lines[i++].Replace("\r", ""); step.ID = new UUID(lines[i++]); int flags = int.Parse(lines[i++]); Sequence.Add(step); break; } case GestureStepType.Chat: { GestureStepChat step = new GestureStepChat(); step.Text = lines[i++]; int flags = int.Parse(lines[i++]); Sequence.Add(step); break; } case GestureStepType.Wait: { GestureStepWait step = new GestureStepWait(); step.WaitTime = float.Parse(lines[i++], Utils.EnUsCulture); int flags = int.Parse(lines[i++]); step.WaitForTime = (flags & 0x01) != 0; step.WaitForAnimation = (flags & 0x02) != 0; Sequence.Add(step); break; } } } Finish: return(true); } catch (Exception ex) { Logger.Log("Decoding gesture asset failed:" + ex.Message, Helpers.LogLevel.Error); return(false); } }
/// <summary> /// Decodes gesture assset into play sequence /// </summary> /// <returns>true if the asset data was decoded successfully</returns> public override bool Decode() { try { string[] lines = Utils.BytesToString(AssetData).Split('\n'); Sequence = new List<GestureStep>(); int i = 0; // version int version = int.Parse(lines[i++]); if (version != 2) { throw new Exception("Only know how to decode version 2 of gesture asset"); } TriggerKey = byte.Parse(lines[i++]); TriggerKeyMask = uint.Parse(lines[i++]); Trigger = lines[i++]; ReplaceWith = lines[i++]; int count = int.Parse(lines[i++]); if (count < 0) { throw new Exception("Wrong number of gesture steps"); } for (int n = 0; n < count; n++) { GestureStepType type = (GestureStepType)int.Parse(lines[i++]); switch (type) { case GestureStepType.EOF: goto Finish; case GestureStepType.Animation: { GestureStepAnimation step = new GestureStepAnimation(); step.Name = lines[i++]; step.ID = new UUID(lines[i++]); int flags = int.Parse(lines[i++]); if (flags == 0) { step.AnimationStart = true; } else { step.AnimationStart = false; } Sequence.Add(step); break; } case GestureStepType.Sound: { GestureStepSound step = new GestureStepSound(); step.Name = lines[i++].Replace("\r", ""); step.ID = new UUID(lines[i++]); int flags = int.Parse(lines[i++]); Sequence.Add(step); break; } case GestureStepType.Chat: { GestureStepChat step = new GestureStepChat(); step.Text = lines[i++]; int flags = int.Parse(lines[i++]); Sequence.Add(step); break; } case GestureStepType.Wait: { GestureStepWait step = new GestureStepWait(); step.WaitTime = float.Parse(lines[i++], Utils.EnUsCulture); int flags = int.Parse(lines[i++]); step.WaitForTime = (flags & 0x01) != 0; step.WaitForAnimation = (flags & 0x02) != 0; Sequence.Add(step); break; } } } Finish: return true; } catch (Exception ex) { Logger.Log("Decoding gesture asset failed:" + ex.Message, Helpers.LogLevel.Error); return false; } }
/// <summary> /// Encodes gesture asset suitable for uplaod /// </summary> public override void Encode() { StringBuilder sb = new StringBuilder(); sb.Append("2\n"); sb.Append(TriggerKey + "\n"); sb.Append(TriggerKeyMask + "\n"); sb.Append(Trigger + "\n"); sb.Append(ReplaceWith + "\n"); int count = 0; if (Sequence != null) { count = Sequence.Count; } sb.Append(count + "\n"); for (int i = 0; i < count; i++) { GestureStep step = Sequence[i]; sb.Append((int)step.GestureStepType + "\n"); switch (step.GestureStepType) { case GestureStepType.EOF: goto Finish; case GestureStepType.Animation: GestureStepAnimation animstep = (GestureStepAnimation)step; sb.Append(animstep.Name + "\n"); sb.Append(animstep.ID + "\n"); if (animstep.AnimationStart) { sb.Append("0\n"); } else { sb.Append("1\n"); } break; case GestureStepType.Sound: GestureStepSound soundstep = (GestureStepSound)step; sb.Append(soundstep.Name + "\n"); sb.Append(soundstep.ID + "\n"); sb.Append("0\n"); break; case GestureStepType.Chat: GestureStepChat chatstep = (GestureStepChat)step; sb.Append(chatstep.Text + "\n"); sb.Append("0\n"); break; case GestureStepType.Wait: GestureStepWait waitstep = (GestureStepWait)step; sb.AppendFormat("{0:0.000000}\n", waitstep.WaitTime); int waitflags = 0; if (waitstep.WaitForTime) { waitflags |= 0x01; } if (waitstep.WaitForAnimation) { waitflags |= 0x02; } sb.Append(waitflags + "\n"); break; } } Finish: AssetData = Utils.StringToBytes(sb.ToString()); }