public Classe(Description.Classe classe) { _classe = classe; _reflexe = Computed.From(() => _classe.Sauvegardes.Reflexe(Niveau)); _vigueur = Computed.From(() => _classe.Sauvegardes.Vigueur(Niveau)); _volonte = Computed.From(() => _classe.Sauvegardes.Volonte(Niveau)); _bonusDeBaseAttaque = Computed.From(() => _classe.BonusDeBaseAttaque(Niveau)); }
public Personnage() { Caractéristiques = new Caractéristiques(); _reflexe = Computed.From(() => _classes.Sum(setable => setable.Reflexe) + Caractéristiques.Dexterite.Modificateur); _vigueur = Computed.From(() => _classes.Sum(setable => setable.Vigueur) + Caractéristiques.Constitution.Modificateur); _volonte = Computed.From(() => _classes.Sum(setable => setable.Volonte) + Caractéristiques.Sagesse.Modificateur); _bonusDeBaseAttaque = Computed.From(() => _classes.Sum(classe => classe.BonusDeBaseAttaque)); }
public void TestNotification() { var x = Mutable.From(1); var y = Mutable.From(2); var z = Computed.From(() => x.Value + y.Value); Assert.AreEqual(3, z.Value); Assert.AreEqual(false, z.IsActive); x.Value = 3; Assert.AreEqual(5, z.Value); Assert.AreEqual(false, z.IsActive); var p = Computed.From(() => z.Value * 2); Assert.AreEqual(10, p.Value); Assert.AreEqual(false, p.IsActive); Assert.AreEqual(false, z.IsActive); var notified = 0; PropertyChangedEventHandler changed = (s, e) => notified++; p.PropertyChanged += changed; Assert.AreEqual(true, p.IsActive); Assert.AreEqual(true, z.IsActive); Assert.AreEqual(0, notified); y.Value = 1; Assert.AreEqual(true, p.IsActive); Assert.AreEqual(true, z.IsActive); Assert.AreEqual(1, notified); Assert.AreEqual(8, p.Value); p.PropertyChanged -= changed; Assert.AreEqual(false, p.IsActive); Assert.AreEqual(false, z.IsActive); Assert.AreEqual(1, notified); Assert.AreEqual(8, p.Value); x.Value = 1; Assert.AreEqual(false, p.IsActive); Assert.AreEqual(false, z.IsActive); Assert.AreEqual(1, notified); Assert.AreEqual(4, p.Value); }
public Notes() { SelectedNotes = Computed.From( () => AllNotes.Value.Where(n => n.IsSelected.Value).ToList() ).Throttle(TimeSpan.FromMilliseconds(10)); SelectAllIsChecked = Computed.From( get: () => !SelectedNotes.Value.Any() ? false : SelectedNotes.Value.Count() == AllNotes.Value.Count ? true : default(bool?), set: state => { // only pay attention when setting to a definite state if (state == null) { return; } foreach (var note in AllNotes.Value) { note.IsSelected.Value = state == true; } }); SelectAllIsEnabled = Computed.From(() => AllNotes.Value.Count != 0); AddNote = new Command( execute: () => { var text = NewNoteText.Value; NewNoteText.Value = string.Empty; AllNotes.Value.Add(new Note { Text = { Value = text } }); }, canExecute: Computed.From(() => NewNoteText.Value.Length != 0)); }