internal Object Unmarshal(HParsedToken tok) { // TODO switch (tok.token_type) { case HTokenType.TT_NONE: return(null); case HTokenType.TT_BYTES: { byte[] ret = new byte[tok.token_data.bytes.len]; Marshal.Copy(tok.token_data.bytes.token, ret, 0, ret.Length); return(ret); } case HTokenType.TT_SINT: return((System.Int64)tok.token_data.sint); case HTokenType.TT_UINT: return((System.UInt64)tok.token_data._uint); case HTokenType.TT_SEQUENCE: { Object[] ret = new Object[tok.token_data.seq.used]; for (uint i = 0; i < ret.Length; i++) { ret[i] = Unmarshal(tok.token_data.seq.at(i)); } return(ret); } default: if (tok.token_type == Hammer.tt_dotnet) { HTaggedToken tagged = hammer.h_parsed_token_get_tagged_token(tok); Object cb = Hammer.tag_to_action[tagged.label]; Object unmarshalled = Unmarshal(tagged.token); if (cb is HAction) { HAction act = (HAction)cb; return(act(unmarshalled)); } else if (cb is HPredicate) { HPredicate pred = (HPredicate)cb; if (!pred(unmarshalled)) { throw new ParseError("Predicate failed"); } else { return(unmarshalled); } } } throw new Exception("Should not reach here"); } }
internal static ulong RegisterAction(HAction action) { ulong newAction = (ulong)tag_to_action.Count; tag_to_action[newAction] = action; return(newAction); }
/// <summary> /// Initializes a new instance of the <see cref="HEntityAction"/> class with the specified information. /// </summary> /// <param name="isEmpowered">The value that determines whether the <see cref="IHEntity"/> has privileges.</param> /// <param name="index">The room index value of the <see cref="IHEntity"/>.</param> /// <param name="tile">The <see cref="HPoint"/> of where the <see cref="IHEntity"/> is currently on.</param> /// <param name="movingTo">The <see cref="HPoint"/> of where the <see cref="IHEntity"/> will move to next.</param> /// <param name="sign">The <see cref="HSign"/> that the <see cref="IHEntity"/> has raised.</param> /// <param name="stance">The current <see cref="HStance"/> of the <see cref="IHEntity"/>.</param> /// <param name="headDirection">The <see cref="HDirection"/> of the <see cref="IHEntity"/>'s head.</param> /// <param name="bodyDirection">The <see cref="HDirection"/> of the <see cref="IHEntity"/>'s body.</param> /// <param name="lastAction">The <see cref="HAction"/> that the <see cref="IHEntity"/> has recently done.</param> public HEntityAction(bool isEmpowered, int index, HPoint tile, HPoint movingTo, HSign sign, HStance stance, HDirection headDirection, HDirection bodyDirection, HAction lastAction) { Index = index; IsEmpowered = isEmpowered; Tile = tile; MovingTo = movingTo; Sign = sign; Stance = stance; HeadDirection = headDirection; BodyDirection = bodyDirection; LastAction = lastAction; }
public HPlayerAction(bool empowered, int playerIndex, HPoint tile, HPoint movingTo, HSign sign, HStance stance, HDirection headDirection, HDirection bodyDirection, HAction latestAction) { Empowered = empowered; PlayerIndex = playerIndex; Tile = tile; MovingTo = movingTo; Sign = sign; Stance = stance; HeadDirection = headDirection; BodyDirection = bodyDirection; LatestAction = latestAction; }
/// <summary> /// Returns a <see cref="IReadOnlyList{T}"/> of type <see cref="HEntityAction"/> found in the <see cref="HMessage"/>. /// </summary> /// <param name="packet">The <see cref="HMessage"/> that contains the <see cref="HEntityAction"/> data to parse.</param> /// <returns></returns> public static IReadOnlyList <HEntityAction> Parse(HMessage packet) { int entityActionCount = packet.ReadInteger(); var entityActionList = new List <HEntityAction>(entityActionCount); for (int i = 0; i < entityActionList.Capacity; i++) { int index = packet.ReadInteger(); int x = packet.ReadInteger(); int y = packet.ReadInteger(); var z = double.Parse(packet.ReadString(), CultureInfo.InvariantCulture); var headDirection = (HDirection)packet.ReadInteger(); var bodyDirection = (HDirection)packet.ReadInteger(); string actionString = packet.ReadString(); string[] actionData = actionString.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); HSign sign = HSign.One; HAction action = HAction.None; HStance stance = HStance.Stand; double movingToZ = 0.0; bool isEmpowered = false; int movingToX = 0, movingToY = 0; foreach (string actionInfo in actionData) { string[] actionValues = actionInfo.Split(' '); if (actionValues.Length < 2) { continue; } if (string.IsNullOrWhiteSpace(actionValues[0])) { continue; } #region Switch Statement: actionValues[] switch (actionValues[0]) { case "flatctrl": { isEmpowered = true; break; } case "mv": { string[] movingToValues = actionValues[1].Split(','); if (movingToValues.Length >= 3) { movingToX = int.Parse(movingToValues[0]); movingToY = int.Parse(movingToValues[1]); movingToZ = double.Parse(movingToValues[2], CultureInfo.InvariantCulture); } action = HAction.Move; break; } case "sit": { action = HAction.Sit; stance = HStance.Sit; break; } case "lay": { action = HAction.Lay; stance = HStance.Lay; break; } case "sign": { sign = (HSign)int.Parse(actionValues[1]); action = HAction.Sign; break; } } #endregion } var entityAction = new HEntityAction(isEmpowered, index, new HPoint(x, y, z), new HPoint(movingToX, movingToY, movingToZ), sign, stance, headDirection, bodyDirection, action); entityActionList.Add(entityAction); } return(entityActionList); }
public static Parser Action(Parser p, HAction action) { ulong actionNo = Hammer.RegisterAction(action); return new Parser(hammer.h_tag(p.wrapped, actionNo)).Pin(p).Pin(action); }
internal static ulong RegisterAction(HAction action) { ulong newAction = (ulong)tag_to_action.Count; tag_to_action[newAction] = action; return newAction; }
public static async Task Preview(Window window, int fps, Action <HAction> mButtonAction = null) { if (window == null || !window.Exists) { return; } Edge corner = new Edge(EdgeType.BottomRight, Monitor.Primary.Area.BottomRight - new Coord(60, 60)); var area = new Area(0, 0, 576, 324).SetEdge(corner); var gui = new ImageBox(window.GetImage(), area); gui.Launch(form => form.ShowInTaskbar = false); await gui.WaitForForm(); gui.Window.SetAlwaysOnTop(true); //try { gui.Window.Pin(true); } catch { } var t = new TaskCompletionSource <object>(); bool Context() => Window.FromMouse == gui.Window; var focus = Hotkey.Create(Key.LButton, HAction.Single(a => window.Activate()), priority: 100, context: Context); var hotkey = Hotkey.Create(Key.RButton, HAction.Single(a => t.TrySetResult(null)), priority: 100, context: Context); var mba = Hotkey.Create(Key.MButton, HAction.Single(mButtonAction), priority: 100, context: Context); bool hidden = false; bool trans = false; while (!t.Task.IsCompleted) { await Task.Delay(1000 / fps); if (!window.Exists) { break; } else if (window.IsActive) { if (!hidden) { gui.Window.SetOpacity(0); gui.Window.SetClickThrough(true); hidden = true; } } else { if (hidden) { gui.Window.SetOpacity(100); gui.Window.SetClickThrough(false); hidden = false; } gui.SetImage(window.GetImagePrint(true)); var newArea = gui.Window.Area; var contains = newArea.Contains(Mouse.Position); if (contains && !trans) { trans = true; gui.Window.SetOpacity(50); } else if (!contains && trans) { trans = false; gui.Window.SetOpacity(100); } if (newArea != area) { newArea.SetEdge(corner); area = newArea; gui.Window.Move(area); } } } gui.Close(); hotkey.Remove(); mba.Remove(); focus.Remove(); Console.WriteLine("Preview closed"); }
public static Parser Action(Parser p, HAction action) { ulong actionNo = Hammer.RegisterAction(action); return(new Parser(hammer.h_tag(p.wrapped, actionNo)).Pin(p).Pin(action)); }