public static Element Encode(ActionSet actionSet, LambdaAction lambdaAction) { var meta = new List <IWorkshopTree>(); // The first element is the lambda's identifier. meta.Add(Num(actionSet.ToWorkshop.LambdaBuilder.GetIdentifier(actionSet, new AnonymousWorkshopPortableFunction(lambdaAction)))); // The second element is the 'this' if applicable. meta.Add(actionSet.This ?? Null()); // Add captured variables. foreach (var captured in lambdaAction.CapturedVariables) { // Get the assigner from the captured variable. var gettable = actionSet.IndexAssigner[captured.Provider]; // Struct if (gettable is IStructValue structValue) { foreach (var child in structValue.GetAllValues()) { meta.Add(child); } } // Normal else { meta.Add(gettable.GetVariable()); } } return(CreateArray(meta.ToArray())); }
public bool GiveControl(GameEntity entity) { // todo: maybe instead when an actor is blocked, he should resolve his action // and store it and don't execute it until ready if (entity.hasBlockedUntil && DateTime.UtcNow < entity.blockedUntil.BlockedUntil) { return(false); } IGameAction gameAction; try { gameAction = _actionResolver.GetAction(entity); } catch (Exception e) { Debug.LogError(e.Message + ", stack trace: " + e.StackTrace); gameAction = new LambdaAction(entity, 1f, null, gameEntity => Enumerable.Empty <IActionEffect>()); } bool gameActionIsResolved = gameAction != null; if (gameActionIsResolved) { // Debug.Log($"{entity.view.Controller.Name} has action: {gameAction.GetType().Name}"); PerformTurn(entity, gameAction); return(true); } return(false); }
public Control RegisterControl( Control c, Func <object, LambdaAction> setValue, LambdaAction takeOverLambda = null) { // add item var it = new RepoItem(); it.control = c; it.setValueLambda = setValue; it.takeOverLambda = takeOverLambda; items.Add(c, it); // put callbacks accordingly if (c is TextBox) { var tb = c as TextBox; it.originalValue = "" + tb.Text; tb.TextChanged += Tb_TextChanged; tb.KeyUp += Tb_KeyUp; } if (c is Button) { var b = c as Button; b.Click += B_Click; } if (c is ComboBox) { var cb = c as ComboBox; it.originalValue = "" + cb.Text; cb.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new System.Windows.Controls.TextChangedEventHandler(Tb_TextChanged)); if (!cb.IsEditable) { // we need this event cb.SelectionChanged += Cb_SelectionChanged; } if (cb.IsEditable) { // add this for comfort cb.KeyUp += Tb_KeyUp; } } if (c is CheckBox) { var cb = c as CheckBox; it.originalValue = cb.IsChecked; cb.Checked += Cb_Checked; cb.Unchecked += Cb_Checked; } return(c); }
public void Listen(IPlotChooserAction action, IAction defaultAction, List <PLOT> excludedPlots = null, float timeToChoose = DEFAULT_TIME_TO_CHOOSE_PLOT) { ListeningAction = action; this.defaultAction = defaultAction; this.timeToChoose = timeToChoose; // Master initiate the skip count down if (PhotonNetwork.IsMasterClient) { StartTimer(); SkipButtonUI.GetInstance().ListenClick(new LambdaAction(() => { photonView.RPC("OnTimeoutEvent", RpcTarget.All); })); } if (!TurnDirector.Ins.IsMyTurn()) { return; } // Player choose the plot CameraTopDown cameraComponent = CameraTopDown.GetInstance(); cameraComponent.Active = true; cameraComponent.ListenTargetReached(new LambdaAction(() => { gameObject.SetActive(true); if (excludedPlots != null) { foreach (PLOT plot in excludedPlots) { TileChooserButton.buttonDictionary[plot].button.enabled = false; } } postChosenTile = new LambdaAction(() => { cameraComponent.Active = true; gameObject.SetActive(false); if (excludedPlots != null) { foreach (PLOT plot in excludedPlots) { TileChooserButton.buttonDictionary[plot].button.enabled = true; } } }); })); }
public AnonymousRunner(LambdaAction lambda, RecycleWorkshopVariableAssigner parameterAssigner) { _lambda = lambda; _parameters = (from parameter in _lambda.Parameters select new AssignedPortableParameter( parameter, // Create the gettable. parameter.CodeType .GetGettableAssigner(new AssigningAttributes(parameter.Name, true, false)) .GetValue(new GettableAssignerValueInfo(parameterAssigner) { SetInitialValue = SetInitialValue.DoNotSet }))).ToArray(); }
public static void DecodeCaptured(ActionSet actionSet, IWorkshopTree source, LambdaAction lambdaAction) { // 0 is the lambda identifier, 1 is the local object, so start at 2 for captured variables. var unfolder = new LambdaUnfolder(source, 2); foreach (var captured in lambdaAction.CapturedVariables) { // Get the gettable from the captured variable. var gettable = captured.GetAssigner(new(actionSet)).Unfold(unfolder); // Add to the assigner. actionSet.IndexAssigner.Add(captured.Provider, gettable); } }
public override bool Activate(string activeCase) { if (canActivate) { canActivate = false; } else { return(false); } Debug.Log("Activate Sunnary Wings."); TileChooserManager tileChooser = TileChooserManager.GetInstance(); IAction actionEndPhase = new LambdaAction( () => { Owner.AddItem(this); canActivate = true; }); // Not Building tiles List <PLOT> banned = Plot.BuildingPlot.Union(Plot.TemplePlot).ToList(); banned.Add(PLOT.TRAVEL); tileChooser.Listen(this, actionEndPhase, banned, 10f); Owner.RemoveItem(this); Remove(true); // player active animation // DO NOT add item back to Item pool // ItemManager.Ins.AddItemToPool(this); return(true); }
public override IAction ActionOnEnter(Player obj) { IAction result = new LambdaAction(() => { NotifyPlotEnter(obj); var tileChooser = TileChooserManager.GetInstance(); ActionTravel travel = new ActionTravel(obj); IAction actionEndPhase = base.ActionOnEnter(obj); tileChooser.Listen(travel, actionEndPhase, null, 10f); }); NotifyPlotEnter(obj); return(result); }
public FrameworkElement RegisterControl( FrameworkElement fe, Func <object, LambdaAction> setValue, LambdaAction takeOverLambda = null) { // add item var it = new RepoItem(); it.fwElem = fe; it.setValueLambda = setValue; it.takeOverLambda = takeOverLambda; items.Add(fe, it); // put callbacks accordingly if (fe is TextBox) { var tb = fe as TextBox; it.originalValue = "" + tb.Text; tb.TextChanged += Tb_TextChanged; tb.KeyUp += Tb_KeyUp; } if (fe is Button btn) { btn.Click += B_Click; } if (fe is ComboBox cb) { it.originalValue = "" + cb.Text; cb.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new System.Windows.Controls.TextChangedEventHandler(Tb_TextChanged)); if (!cb.IsEditable) { // we need this event cb.SelectionChanged += Cb_SelectionChanged; } if (cb.IsEditable) { // add this for comfort cb.KeyUp += Tb_KeyUp; } } if (fe is CheckBox ch) { it.originalValue = ch.IsChecked; ch.Checked += Cb_Checked; ch.Unchecked += Cb_Checked; } if (fe is MenuItem mi) { mi.Click += B_Click; } if (fe is Border brd && brd.Tag is string tag && tag == "DropBox") { brd.AllowDrop = true; brd.DragEnter += (object sender2, DragEventArgs e2) => { e2.Effects = DragDropEffects.Copy; }; brd.PreviewDragOver += (object sender3, DragEventArgs e3) => { e3.Handled = true; }; brd.Drop += (object sender4, DragEventArgs e4) => { if (e4.Data.GetDataPresent(DataFormats.FileDrop, true)) { // Note that you can have more than one file. string[] files = (string[])e4.Data.GetData(DataFormats.FileDrop); // Assuming you have one file that you care about, pass it off to whatever // handling code you have defined. if (files != null && files.Length > 0 && sender4 is FrameworkElement fe2 && items.ContainsKey(fe2)) { var it2 = items[fe2]; if (it2.fwElem is Border brd2 && it2.setValueLambda != null) { // update UI if (brd2.Child is TextBlock tb2) { tb2.Text = "" + files[0]; } // value changed it2.setValueLambda(files[0]); // contents changed WishForOutsideAction.Add(new LambdaActionContentsChanged()); } } } e4.Handled = true; }; } return(fe); }
public void AddWishForAction(LambdaAction la) { WishForOutsideAction.Add(la); }
public AnonymousWorkshopPortableFunction(LambdaAction lambda) => _action = lambda;