public TP SetupProperty <TP, T>(string type, string fragment, Func <T> getter, IValueChecker <T> checker, IValueWatcher <T> watcher) where TP : class, IProperty <T> { string key = GetSubKey(fragment); TP prop = SetupProperty <TP>(type, fragment); if (prop != null) { T val = getter(); prop.Setup(val); SavePropertySyncer <TP, T>(key, prop, getter); if (checker != null && !prop.AddValueChecker(checker)) { Error("Add Checker Failed: {0} -> {1}, {2}", this, type, fragment); } if (watcher != null && !prop.AddValueWatcher(watcher)) { Error("Add Watcher Failed: {0} -> {1}, {2}", this, type, fragment); } } return(prop); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="inputState">Manages input visible to the game.</param> /// <param name="gameLocations">The observable list of game locations.</param> public WatcherCore(SInputState inputState, ObservableCollection <GameLocation> gameLocations) { // init watchers this.CursorWatcher = WatcherFactory.ForEquatable(() => inputState.CursorPosition); this.MouseWheelScrollWatcher = WatcherFactory.ForEquatable(() => inputState.LastMouse.ScrollWheelValue); this.SaveIdWatcher = WatcherFactory.ForEquatable(() => Game1.hasLoadedGame ? Game1.uniqueIDForThisGame : 0); this.WindowSizeWatcher = WatcherFactory.ForEquatable(() => new Point(Game1.viewport.Width, Game1.viewport.Height)); this.TimeWatcher = WatcherFactory.ForEquatable(() => Game1.timeOfDay); this.ActiveMenuWatcher = WatcherFactory.ForReference(() => Game1.activeClickableMenu); this.LocationsWatcher = new WorldLocationsTracker(gameLocations, MineShaft.activeMines); this.LocaleWatcher = WatcherFactory.ForGenericEquality(() => LocalizedContentManager.CurrentLanguageCode); this.Watchers.AddRange(new IWatcher[] { this.CursorWatcher, this.MouseWheelScrollWatcher, this.SaveIdWatcher, this.WindowSizeWatcher, this.TimeWatcher, this.ActiveMenuWatcher, this.LocationsWatcher, this.LocaleWatcher }); }
/// <summary>Update the snapshot.</summary> /// <param name="watcher">The value watcher to snapshot.</param> public void Update(IValueWatcher <T> watcher) { this.Update(watcher.IsChanged, watcher.PreviousValue, watcher.CurrentValue); }