GameData Changes

- when changing the gamedata files (add, delete, reload) it will reload all the gamedata files and repopulate the server managers.
- updated the viewmodels to check for valid class names.
This commit is contained in:
Brett Hewitson 2022-06-17 18:41:05 +10:00
parent 1bf04ed33e
commit 479e4a64dc
33 changed files with 427 additions and 305 deletions

View file

@ -17,6 +17,8 @@ namespace ServerManagerTool.Lib
public const string RCONINPUTMODE_COMMAND = "Command";
public static event EventHandler GameDataLoaded;
public static string MainDataFolder = Path.Combine(Environment.CurrentDirectory, Config.Default.GameDataDir);
public static string UserDataFolder = Path.Combine(Config.Default.DataDir, Config.Default.GameDataDir);
@ -26,6 +28,12 @@ namespace ServerManagerTool.Lib
private static MainGameData gameData = null;
public static void Initialize()
{
Load();
OnGameDataLoaded();
}
private static void Load()
{
// read static game data
GameDataUtils.ReadAllData(out gameData, MainDataFolder, Config.Default.GameDataExtension, Config.Default.GameDataApplication);
@ -174,6 +182,19 @@ namespace ServerManagerTool.Lib
}
}
private static void OnGameDataLoaded()
{
GameDataLoaded?.Invoke(null, EventArgs.Empty);
}
public static void Reload()
{
gameData = null;
Load();
OnGameDataLoaded();
}
public static string FriendlyNameForClass(string className, bool returnNullIfNotFound = false) => string.IsNullOrWhiteSpace(className) ? (returnNullIfNotFound ? null : string.Empty) : GlobalizedApplication.Instance.GetResourceString(className) ?? (returnNullIfNotFound ? null : className);
#region Creatures

View file

@ -26,10 +26,6 @@ namespace ServerManagerTool.Lib
{
}
public void UpdateForLocalization()
{
}
public void Update(bool recursive = true)
{
IsEnabled = this.Count > 0;
@ -118,7 +114,15 @@ namespace ServerManagerTool.Lib
resource.Update();
}
ValidStatus = IsValid ? (BaseCraftingResourceRequirements.Any(i => i.ValidStatus == "N") ? "N" : (BaseCraftingResourceRequirements.Any(i => i.ValidStatus == "W") ? "W" : "Y")) : "N";
ValidStatus = IsValid
? (BaseCraftingResourceRequirements.Any(i => i.ValidStatus == "N")
? "N"
: (BaseCraftingResourceRequirements.Any(i => i.ValidStatus == "W")
? "W"
: (GameData.HasItemForClass(ItemClassString)
? "Y"
: "W")))
: "N";
}
}
@ -186,7 +190,11 @@ namespace ServerManagerTool.Lib
public void Update()
{
ValidStatus = IsValid ? (GameData.HasItemForClass(ResourceItemTypeString) ? "Y" : "W") : "N";
ValidStatus = IsValid
? (GameData.HasItemForClass(ResourceItemTypeString)
? "Y"
: "W")
: "N";
}
}
}

View file

@ -25,10 +25,6 @@ namespace ServerManagerTool.Lib
{
}
public void UpdateForLocalization()
{
}
public void Update()
{
IsEnabled = this.Count > 0;
@ -98,7 +94,11 @@ namespace ServerManagerTool.Lib
public void Update()
{
ValidStatus = IsValid ? (GameData.HasCreatureForClass(DinoClassString) ? "Y" : "W") : "N";
ValidStatus = IsValid
? (GameData.HasCreatureForClass(DinoClassString)
? "Y"
: "W")
: "N";
}
}
}

View file

@ -44,10 +44,6 @@ namespace ServerManagerTool.Lib
}
}
public void UpdateForLocalization()
{
}
public void Update()
{
IsEnabled = this.Count > 0;
@ -160,7 +156,11 @@ namespace ServerManagerTool.Lib
public void Update()
{
ValidStatus = IsValid ? (GameData.HasItemForClass(ItemClassString) ? "Y" : "W") : "N";
ValidStatus = IsValid
? (GameData.HasItemForClass(ItemClassString)
? "Y"
: "W")
: "N";
}
}

View file

@ -72,10 +72,6 @@ namespace ServerManagerTool.Lib
}
}
public void UpdateForLocalization()
{
}
public void Update(bool recursive = true)
{
IsEnabled = this.Count > 0;
@ -226,7 +222,15 @@ namespace ServerManagerTool.Lib
itemSet.Update(recursive);
}
ValidStatus = IsViewValid ? (ItemSets.Any(i => i.ValidStatus == "N") ? "N" : (ItemSets.Any(i => i.ValidStatus == "W") ? "W" : "Y")) : "N";
ValidStatus = IsViewValid
? (ItemSets.Any(i => i.ValidStatus == "N")
? "N"
: (ItemSets.Any(i => i.ValidStatus == "W")
? "W"
: (GameData.HasSupplyCrateForClass(SupplyCrateClassString)
? "Y"
: "W")))
: "N";
}
}
@ -340,7 +344,13 @@ namespace ServerManagerTool.Lib
itemEntry.Update(recursive);
}
ValidStatus = IsViewValid ? (ItemEntries.Any(i => i.ValidStatus == "N") ? "N" : (ItemEntries.Any(i => i.ValidStatus == "W") ? "W" : "Y")) : "N";
ValidStatus = IsViewValid
? (ItemEntries.Any(i => i.ValidStatus == "N")
? "N"
: (ItemEntries.Any(i => i.ValidStatus == "W")
? "W"
: "Y"))
: "N";
}
}
@ -495,7 +505,13 @@ namespace ServerManagerTool.Lib
item.Update();
}
ValidStatus = IsViewValid ? (Items.Any(i => i.ValidStatus == "N") ? "N" : (Items.Any(i => i.ValidStatus == "W") ? "W" : "Y")) : "N";
ValidStatus = IsViewValid
? (Items.Any(i => i.ValidStatus == "N")
? "N"
: (Items.Any(i => i.ValidStatus == "W")
? "W"
: "Y"))
: "N";
}
}
}

View file

@ -317,13 +317,5 @@ namespace ServerManagerTool.Lib.ViewModel
}
}
}
public void UpdateForLocalization()
{
//foreach (var dinoSetting in this)
//{
// dinoSetting.FriendlyName = GameData.FriendlyNameForClass(dinoSetting.ClassName);
//}
}
}
}

View file

@ -174,10 +174,6 @@ namespace ServerManagerTool.Lib.ViewModel
}
}
public void UpdateForLocalization()
{
}
#region INotifyPropertyChanged
private Dictionary<string, object> _properties = new Dictionary<string, object>();

View file

@ -0,0 +1,51 @@
using System;
using System.Windows;
namespace ServerManagerTool.Lib.ViewModel
{
public class GameDataFile : DependencyObject
{
public static readonly DependencyProperty CreatedDateProperty = DependencyProperty.Register(nameof(CreatedDate), typeof(DateTime), typeof(GameDataFile), new PropertyMetadata(DateTime.MinValue));
public static readonly DependencyProperty FileProperty = DependencyProperty.Register(nameof(File), typeof(string), typeof(GameDataFile), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty FileNameProperty = DependencyProperty.Register(nameof(FileName), typeof(string), typeof(GameDataFile), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty IsUserDataProperty = DependencyProperty.Register(nameof(IsUserData), typeof(bool), typeof(GameDataFile), new PropertyMetadata(true));
public static readonly DependencyProperty VersionProperty = DependencyProperty.Register(nameof(Version), typeof(string), typeof(GameDataFile), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty HasErrorProperty = DependencyProperty.Register(nameof(HasError), typeof(bool), typeof(GameDataFile), new PropertyMetadata(false));
public DateTime CreatedDate
{
get { return (DateTime)GetValue(CreatedDateProperty); }
set { SetValue(CreatedDateProperty, value); }
}
public string File
{
get { return (string)GetValue(FileProperty); }
set { SetValue(FileProperty, value); }
}
public string FileName
{
get { return (string)GetValue(FileNameProperty); }
set { SetValue(FileNameProperty, value); }
}
public bool IsUserData
{
get { return (bool)GetValue(IsUserDataProperty); }
set { SetValue(IsUserDataProperty, value); }
}
public string Version
{
get { return (string)GetValue(VersionProperty); }
set { SetValue(VersionProperty, value); }
}
public bool HasError
{
get { return (bool)GetValue(HasErrorProperty); }
set { SetValue(HasErrorProperty, value); }
}
}
}

View file

@ -0,0 +1,12 @@
using ServerManagerTool.Common.Model;
namespace ServerManagerTool.Lib.ViewModel
{
public class GameDataFileList : SortableObservableCollection<GameDataFile>
{
public override string ToString()
{
return $"{nameof(GameDataFile)} - {Count}";
}
}
}

View file

@ -195,10 +195,6 @@ namespace ServerManagerTool.Lib.ViewModel
}
}
public void UpdateForLocalization()
{
}
public void Update(bool recursive = true)
{
foreach (var npcSpawn in this)
@ -307,7 +303,15 @@ namespace ServerManagerTool.Lib.ViewModel
itemSet.Update();
}
ValidStatus = IsViewValid ? (NPCSpawnEntrySettings.Any(i => i.ValidStatus == "N") ? "N" : (NPCSpawnEntrySettings.Any(i => i.ValidStatus == "W") ? "W" : "Y")) : "N";
ValidStatus = IsViewValid
? (NPCSpawnEntrySettings.Any(i => i.ValidStatus == "N")
? "N"
: (NPCSpawnEntrySettings.Any(i => i.ValidStatus == "W")
? "W"
: (GameData.HasMapSpawnerForClass(NPCSpawnEntriesContainerClassString)
? "Y"
: "W")))
: "N";
}
}
@ -354,7 +358,11 @@ namespace ServerManagerTool.Lib.ViewModel
public void Update()
{
ValidStatus = IsValid ? (GameData.HasCreatureForClass(NPCClassString) ? "Y" : "W") : "N";
ValidStatus = IsValid
? (GameData.HasCreatureForClass(NPCClassString)
? "Y"
: "W")
: "N";
}
}
}

View file

@ -40,7 +40,11 @@ namespace ServerManagerTool.Lib.ViewModel
public void Update()
{
ValidStatus = IsViewValid ? (GameData.HasItemForClass(ItemClassString) ? "Y" : "W") : "N";
ValidStatus = IsViewValid
? (GameData.HasItemForClass(ItemClassString)
? "Y"
: "W")
: "N";
}
}
}