public IPromise ThenDo(Action callback) { if (CurrentState == EPromiseState.Resolved) { callback(); } else { _resolutions.Add(ActionResolution.Create(callback)); } return(this); }
public IEnumerator IEUpdateBoardFancy(List <ActionReq> actions, CellStruct[,] pGrid, CellStruct[,] eGrid) { Debug.Log("Got input of " + actions.Count.ToString() + " actions"); int rem; List <ActionReq> nextActions = getNextActions(actions, out rem); int maxloops = 20; // TODO remove when done int loops = 0; // TODO remove when done while (nextActions != null && loops < maxloops) { loops++; Debug.LogFormat("input ac count: {0}, next ac count: {1}", actions.Count, nextActions.Count); switch (nextActions[0].a) { case pAction.buildIntelTower: case pAction.buildOffenceTower: case pAction.buildDefenceTower: case pAction.buildWall: case pAction.buildReflector: case pAction.buildDefenceGrid: case pAction.placeMine: { Debug.Log("In the build section of fancy update"); ActionResolution buildRes = Instantiate(defaultBuild).GetComponent <ActionResolution>(); buildRes.Init(nextActions, this, pGrid, eGrid); yield return(buildRes.IEResolve()); break; } case pAction.fireBasic: case pAction.fireAgain: case pAction.firePiercing: { Debug.Log("In the fire section of fancy update"); ActionResolution fireRes = Instantiate(defaultProjectile).GetComponent <ActionResolution>(); fireRes.Init(nextActions, this, pGrid, eGrid); yield return(fireRes.IEResolve()); break; } case pAction.fireSquare: case pAction.hellFire: case pAction.fireRow: { Debug.Log("In the fire multi section of fancy update"); ActionResolution fireMultiRes = Instantiate(fireMultiObj).GetComponent <ActionResolution>(); fireMultiRes.Init(nextActions, this, pGrid, eGrid); yield return(fireMultiRes.IEResolve()); break; } default: Debug.Log("OtherAction happened"); break; } nextActions = getNextActions(actions, out rem); } SetGridStates(pGrid, eGrid); // At end, make sure to set the board incase we muck up... //Interior function to get next action(s) feels janky, probably needs to be simplified //Goal is to get the next action or set of matching actions that were expanded List <ActionReq> getNextActions(List <ActionReq> inActions, out int remove) { List <pAction> multiArs = new List <pAction>() { pAction.hellFire, pAction.fireSquare, pAction.fireRow, pAction.blockingShot, pAction.flare }; List <ActionReq> outActions = null; remove = 0; if (inActions.Count > 0) { outActions = new List <ActionReq>(); outActions.Add(inActions[0]); inActions.RemoveAt(0); remove++; } else { return(outActions); } if (multiArs.Contains(outActions[0].a)) { while (inActions.Count > 0 && inActions[0].a == outActions[0].a && inActions[0].p == outActions[0].p) //While we've got more matching actions from same player { outActions.Add(inActions[0]); inActions.RemoveAt(0); remove++; } } return(outActions); } }
void Start() { this.pieceSelection = this.gameObject.GetComponent <PieceSelection> (); this.actionResolution = this.gameObject.GetComponent <ActionResolution> (); }
// Use this for initialization void Start() { this.actionResolution = this.gameObject.GetComponent <ActionResolution> (); this.addEventListeners(); }