protected async Task CheckAnswer(AnswerData answer) { bool isCorrect; if (answer.Answer == DisplayCard.Answer) { answer.IsCorrect = true; answer.IsIncorrect = false; answer.CssClass = "correct"; correctTotal++; isCorrect = true; } else { answer.IsCorrect = false; answer.IsIncorrect = true; answer.CssClass = "wrong"; wrongTotal++; isCorrect = false; } await DeckState.UpdateStats(isCorrect); var stats = DeckState.DeckStats; StateHasChanged(); }
// Start is called before the first frame update private async void Start() { _newState = _state; _animator = GetComponentInParent <Animator>(); Debug.Log($"Subscribing to {Topic}"); await EnsureSubscribeRegisteredAsync(); }
protected async Task ShowDeckCards(Deck deck) { deckEdit = deck; DisplayCards = await DeckState.GetDeckCards(deck); showCards = true; StateHasChanged(); }
protected async Task UpdateCard() { cardEdit.Answer = answer; cardEdit.Question = question; await DeckState.UpdateDeckCard(deckEdit, cardEdit); showEdit = false; StateHasChanged(); }
protected async Task SelectDeck() { SelectedDeck = UserDecks.Find(x => x.Name == deckName); await DeckState.UpdateSelectedDeckAsync(SelectedDeck); isAddCard = true; DeckCards = DeckState.SelectedDeck?.Cards; isSelectDeck = true; StateHasChanged(); }
protected async Task AddDeck() { UserDecks ??= new List <Deck>(); UserDecks.Add(newDeck); SelectedDeck = newDeck; deckName = newDeck.Name; await DeckState.UpdateSelectedDeckAsync(SelectedDeck, true); isAddCard = true; isSelectDeck = true; }
public HandState(DeckState _deckState) { deckState = _deckState; cards = new List <Card>(); for (int i = 0; i < CARDS_INITIALLY; i++) { Card card = deckState.NextCardFromDeck(); card.state = Card.State.IN_HAND; cards.Add(card); } }
// Update is called once per frame private async void Update() { await EnsureSubscribeRegisteredAsync(); if (_state == _newState) { return; } _state = _newState; _animator.SetBool(Open, _state == DeckState.Open); }
private async Task EnsureSubscribeRegisteredAsync() { if (_isSubscribed || !communicationsManager.IsInitialized || topic == null) { return; } await communicationsManager.Client.SubscribeAsync(Topic, state => { Debug.Log($"Received state {state} for {Topic}"); _newState = (DeckState)int.Parse(state); }); _isSubscribed = true; }
internal void OscMessage(string[] address, List <object> arguments) { if (address.Length >= 3 && arguments.Count == 1) { switch (address[2]) { case "tc": Tc?.Invoke(this, new TcEventArgs(arguments[0].ToString())); break; case "control": DeckControl control; if (Enum.TryParse(arguments[0].ToString(), out control)) { DeckControl?.Invoke(this, new DeckControlEventArgs(control)); } break; case "state": DeckState state; if (Enum.TryParse(arguments[0].ToString(), out state)) { DeckState?.Invoke(this, new DeckStateEventArgs(state)); } break; case "connected": bool isConnected; if (bool.TryParse(arguments[0].ToString(), out isConnected)) { IsConnected = isConnected; } break; case "frames_left": if (arguments[0] is long) { FramesLeft?.Invoke(this, new FramesLeftEventArgs((long)arguments[0])); } break; default: Debug.WriteLine($"Unrecognized message: {string.Join("/", address)}:{string.Join(",", arguments)}"); break; } } }
protected async Task AddCardToDeck() { SelectedDeck.Cards ??= new List <Card>(); var newCard = new Card() { Question = question, Answer = answer }; SelectedDeck.Cards.Add(newCard); await DeckState.AddCardToDeck(newCard, SelectedDeck); question = null; answer = null; DeckCards = SelectedDeck.Cards; await DeckState.UpdateDeckCards(SelectedDeck, DeckCards); StateHasChanged(); }
private void SetDeckState(LaneTypes lanetype, int groupID, int componentID, DeckState newState) { //Finds all decks with id List <Bridge> bridgeList = bridges.FindAll(b => b.laneType == lanetype && b.GroupId == groupID && b.ComponentID == componentID); //No barrier found if (bridgeList == null) { Debug.LogError($"ERROR: Bridge with groupID: {groupID} and componentID: {componentID} not found"); return; } foreach (var bridge in bridgeList) { if (newState != bridge.state) { bridge.state = newState; } } }
protected async Task DeleteCard(Card card) { if (card.IsDeleteConfirm) { await DeckState.RemoveCardFromDeck(card); SelectedDeck.Cards.Remove(card); await DeckState.UpdateDeckCards(SelectedDeck, SelectedDeck.Cards); card.ConfirmDelete = ""; card.CssConfirmClass = ""; } else { card.ConfirmDelete = "Delete forever?"; card.CssConfirmClass = "wrong"; } card.IsDeleteConfirm = !card.IsDeleteConfirm; StateHasChanged(); }
protected async Task DeleteDeck(Deck deck) { if (deck.IsDeleteConfirm) { var cards = await DeckState.GetDeckCards(deck); await DeckState.RemoveDeck(deck, cards); UserDecks.Remove(deck); deck.ConfirmDelete = ""; deck.CssConfirmClass = ""; } else { deck.ConfirmDelete = "Delete this deck and all card contents, forever?"; deck.CssConfirmClass = "deckDelete zoom"; } deck.IsDeleteConfirm = !deck.IsDeleteConfirm; deckDeleteMessage = deck.ConfirmDelete; }
public DeckStateEventArgs(DeckState state) { State = state; }
//Handles MQTT messages when they are received public void HandleMessage(string topic, string message) { //Parse and store topic information TopicInformation info = ParseTopic(topic); switch (info.componentType) { case ComponentTypes.traffic_light: //Handle traffic lights //Try setting new traffic light state try { TrafficLightState newState = (TrafficLightState)System.Enum.Parse(typeof(TrafficLightState), message); SetTrafficLightState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid traffic light state: '{message}' for traffic light with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.warning_light: //Handle warning lights //Try setting new warning light state try { WarningLightState newState = (WarningLightState)System.Enum.Parse(typeof(WarningLightState), message); SetWarningLightState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid warning light state: '{message}' for warning light with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.boat_light: //Handle boat lights //Try setting new boat light state try { BoatAndTrainLightState newState = (BoatAndTrainLightState)System.Enum.Parse(typeof(BoatAndTrainLightState), message); SetBoatLightState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid boat light state: '{message}' for boat light with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.sensor: //Don't have to handle sensor data break; case ComponentTypes.barrier: //Handle barriers //Try setting new barrier state try { BarrierState newState = (BarrierState)System.Enum.Parse(typeof(BarrierState), message); SetBarrierState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid barrier state: '{message}' for barrier with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.deck: //Handle deck(bridge) //Try setting new deck(bridge) state try { DeckState newState = (DeckState)System.Enum.Parse(typeof(DeckState), message); SetDeckState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid deck(bridge) state: '{message}' for deck with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.train_light: //Handle train_light //Try setting new train_light state try { BoatAndTrainLightState newState = (BoatAndTrainLightState)System.Enum.Parse(typeof(BoatAndTrainLightState), message); SetTrainLightState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid train_light state: '{message}' for train_light with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; } }
public Player(bool _isHuman, List <Card> deckCards) { isHuman = _isHuman; deckState = new DeckState(deckCards); handState = new HandState(deckState); }