diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d60b60c..e0d9076 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,7 +41,7 @@ jobs: # run: tar --exclude='*.pdb' -caf AnnoMapEditor.zip -C ./Build/ * - name: Upload - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: AnnoMapEditor path: Build/AnnoMapEditor.exe diff --git a/AnnoMapEditor.Tests/AnnoMapEditor.Tests.csproj b/AnnoMapEditor.Tests/AnnoMapEditor.Tests.csproj index 6e3e7e8..5838c38 100644 --- a/AnnoMapEditor.Tests/AnnoMapEditor.Tests.csproj +++ b/AnnoMapEditor.Tests/AnnoMapEditor.Tests.csproj @@ -1,7 +1,7 @@ - net6.0-windows + net6.0-windows10.0.17763.0 enable enable diff --git a/AnnoMapEditor/AnnoMapEditor.csproj b/AnnoMapEditor/AnnoMapEditor.csproj index f2b160c..332b132 100644 --- a/AnnoMapEditor/AnnoMapEditor.csproj +++ b/AnnoMapEditor/AnnoMapEditor.csproj @@ -2,14 +2,14 @@ WinExe - net6.0-windows7.0 + net6.0-windows10.0.17763.0 enable true AnnoMapEditor.App x64 9 MIT - 7.0 + 10.0.17763.0 true true @@ -31,7 +31,7 @@ - + @@ -89,20 +89,11 @@ - - $(DefaultXamlRuntime) - Designer - $(DefaultXamlRuntime) Designer MSBuild:Compile - - $(DefaultXamlRuntime) - Designer - MSBuild:Compile - $(DefaultXamlRuntime) MSBuild:Compile diff --git a/AnnoMapEditor/App.config b/AnnoMapEditor/App.config index 120d839..45eed15 100644 --- a/AnnoMapEditor/App.config +++ b/AnnoMapEditor/App.config @@ -25,6 +25,9 @@ + + False + \ No newline at end of file diff --git a/AnnoMapEditor/App.xaml b/AnnoMapEditor/App.xaml index 9d091b6..4fd2183 100644 --- a/AnnoMapEditor/App.xaml +++ b/AnnoMapEditor/App.xaml @@ -4,6 +4,24 @@ xmlns:local="clr-namespace:AnnoMapEditor" StartupUri="UI/Windows/Start/StartWindow.xaml"> - + + + + + + + + + + + + + + + + + + + diff --git a/AnnoMapEditor/DataArchives/Assets/Models/SessionAsset.cs b/AnnoMapEditor/DataArchives/Assets/Models/SessionAsset.cs index af21350..0e65716 100644 --- a/AnnoMapEditor/DataArchives/Assets/Models/SessionAsset.cs +++ b/AnnoMapEditor/DataArchives/Assets/Models/SessionAsset.cs @@ -131,6 +131,15 @@ public static SessionAsset DetectFromPath(string filePath) return OldWorld; } + public static SessionAsset DetectFromGuid(long guid) + { + if (guid == SESSION_SUNKENTREASURES_GUID) return CapeTrelawney; + if (guid == SESSION_ARCTIC_GUID) return Arctic; + if (guid == SESSION_NEWWORLD_GUID) return NewWorld; + if (guid == SESSION_ENBESA_GUID) return Enbesa; + else return OldWorld; + } + public override string ToString() => DisplayName; } diff --git a/AnnoMapEditor/DataArchives/Assets/Repositories/AssetRepository.cs b/AnnoMapEditor/DataArchives/Assets/Repositories/AssetRepository.cs index 00e93ce..8455cd5 100644 --- a/AnnoMapEditor/DataArchives/Assets/Repositories/AssetRepository.cs +++ b/AnnoMapEditor/DataArchives/Assets/Repositories/AssetRepository.cs @@ -126,7 +126,7 @@ public override async Task InitializeAsync() { try { - assetsXmlStream = File.OpenRead(CachedAssetsXml); + assetsXmlStream = await Task.Run(() => File.OpenRead(CachedAssetsXml)); } catch (Exception e) { @@ -135,7 +135,7 @@ public override async Task InitializeAsync() } } - var Xml = XDocument.Load(assetsXmlStream); + var Xml = await Task.Run(() => XDocument.Load(assetsXmlStream)); var assets = Xml.XPathSelectElements(xpath); if (!validCache) @@ -144,7 +144,7 @@ public override async Task InitializeAsync() UserSettings.Default.Xpath = xpath; UserSettings.Default.Save(); assetsXmlStream.Dispose(); - RenewCache(assets); + await Task.Run(() => RenewCache(assets)); } var convertAssetTasks = assets.Select(assetElement => @@ -155,13 +155,16 @@ public override async Task InitializeAsync() }); var assetList = await Task.WhenAll(convertAssetTasks); - foreach (var asset in assetList) + await Task.Run(() => { - if (asset is not null) + foreach (var asset in assetList) { - _assets.Add(asset.GUID, asset); + if (asset is not null) + { + _assets.Add(asset.GUID, asset); + } } - } + }); _logger.LogInformation($"Finished Deserialising at {watch.Elapsed.TotalMilliseconds} ms."); _logger.LogInformation($"Resolving asset references..."); diff --git a/AnnoMapEditor/DataArchives/Assets/Repositories/FixedIslandRepository.cs b/AnnoMapEditor/DataArchives/Assets/Repositories/FixedIslandRepository.cs index 7b37bd2..54d00e2 100644 --- a/AnnoMapEditor/DataArchives/Assets/Repositories/FixedIslandRepository.cs +++ b/AnnoMapEditor/DataArchives/Assets/Repositories/FixedIslandRepository.cs @@ -42,9 +42,9 @@ public override async Task InitializeAsync() var mapFilePaths = _dataArchive.Find("*.a7m"); - var tasks = mapFilePaths.Select(mapFilePath => + var tasks = mapFilePaths.Select(mapFilePath => { - return Task.Run(() => LoadIslandAsset(mapFilePath)); + return LoadIslandAssetAsync(mapFilePath); }); var islandAssets = await Task.WhenAll(tasks); @@ -58,15 +58,17 @@ public override async Task InitializeAsync() _logger.LogInformation($"Finished loading fixed islands. Loaded {_islands.Count} islands in {watch.Elapsed.TotalMilliseconds} ms."); } - public FixedIslandAsset LoadIslandAsset(String mapFilePath) + public async Task LoadIslandAssetAsync(String mapFilePath) { // thumbnail string thumbnailPath = Path.Combine( - Path.GetDirectoryName(mapFilePath)!, - "_gamedata", - Path.GetFileNameWithoutExtension(mapFilePath), - "mapimage.png"); - BitmapImage thumbnail = _dataArchive.TryLoadPng(thumbnailPath) + Path.GetDirectoryName(mapFilePath)!, + "_gamedata", + Path.GetFileNameWithoutExtension(mapFilePath), + "activemapimage.png" + ); + + BitmapImage thumbnail = await Task.Run(() => _dataArchive.TryLoadPng(thumbnailPath)) ?? throw new Exception($"Could not load island thumbnail '{thumbnailPath}'."); // open a7minfo diff --git a/AnnoMapEditor/DataArchives/Assets/Repositories/IslandRepository.cs b/AnnoMapEditor/DataArchives/Assets/Repositories/IslandRepository.cs index 47d784d..491605f 100644 --- a/AnnoMapEditor/DataArchives/Assets/Repositories/IslandRepository.cs +++ b/AnnoMapEditor/DataArchives/Assets/Repositories/IslandRepository.cs @@ -111,11 +111,8 @@ public override Task InitializeAsync() public static IslandType DetectIslandTypeFromPath(string filePath) { - if (filePath.Contains("_d_")) - return IslandType.Decoration; - - else - return IslandType.Normal; + string fileName = Path.GetFileNameWithoutExtension(filePath); + return IslandType.FromIslandFileName(fileName); } public static IslandSize DetectDefaultIslandSizeFromPath(string filePath) diff --git a/AnnoMapEditor/DataArchives/DataArchiveFactory.cs b/AnnoMapEditor/DataArchives/DataArchiveFactory.cs index 1316dc0..4c48b3f 100644 --- a/AnnoMapEditor/DataArchives/DataArchiveFactory.cs +++ b/AnnoMapEditor/DataArchives/DataArchiveFactory.cs @@ -2,6 +2,7 @@ using AnnoRDA; using AnnoRDA.Builder; using System; +using System.Threading.Tasks; namespace AnnoMapEditor.DataArchives { @@ -12,6 +13,11 @@ public class DataArchiveFactory : IDataArchiveFactory private static readonly string[] EXTENSION_WHITELIST = new[] { "*.a7tinfo", "*.png", "*.a7minfo", "*.a7t", "*.a7te", "assets.xml", "*.a7m", "*.dds" }; + public async Task CreateDataArchiveAsync(string dataPath) + { + return await Task.Run(() => CreateDataArchive(dataPath)); + } + public IDataArchive CreateDataArchive(string dataPath) { // RdaDataArchive diff --git a/AnnoMapEditor/DataArchives/DataManager.cs b/AnnoMapEditor/DataArchives/DataManager.cs index 0516bad..86d5e28 100644 --- a/AnnoMapEditor/DataArchives/DataManager.cs +++ b/AnnoMapEditor/DataArchives/DataManager.cs @@ -64,22 +64,32 @@ private DataManager() public async Task TryInitializeAsync(string dataPath) { + if (dataPath.Length == 0) + { + UpdateStatus(false, false, "Empty Data String"); + return; + } + UpdateStatus(isInitializing: true, isInitialized: false); _logger.LogInformation($"Initializing DataManager at '{dataPath}'."); try { + DataArchiveFactory dataArchiveFactory = new(); - _dataArchive = dataArchiveFactory.CreateDataArchive(dataPath); + _dataArchive = await dataArchiveFactory.CreateDataArchiveAsync(dataPath); _assetRepository = new AssetRepository(_dataArchive); - _assetRepository.Register(); - _assetRepository.Register(); - _assetRepository.Register(); - _assetRepository.Register(); - _assetRepository.Register(); - _assetRepository.Register(); - _assetRepository.Register(); + await Task.Run(() => + { + _assetRepository.Register(); + _assetRepository.Register(); + _assetRepository.Register(); + _assetRepository.Register(); + _assetRepository.Register(); + _assetRepository.Register(); + _assetRepository.Register(); + }); await _assetRepository.InitializeAsync(); _fixedIslandRepository = new FixedIslandRepository(_dataArchive); @@ -89,7 +99,7 @@ public async Task TryInitializeAsync(string dataPath) await _islandRepository.InitializeAsync(); _mapGroupRepository = new MapGroupRepository(_dataArchive); - _mapGroupRepository.InitializeAsync(); + await _mapGroupRepository.InitializeAsync(); } catch (Exception ex) { diff --git a/AnnoMapEditor/MapTemplates/Enums/IslandType.cs b/AnnoMapEditor/MapTemplates/Enums/IslandType.cs index 870365d..e7d28ee 100644 --- a/AnnoMapEditor/MapTemplates/Enums/IslandType.cs +++ b/AnnoMapEditor/MapTemplates/Enums/IslandType.cs @@ -17,7 +17,6 @@ public class IslandType public static readonly IEnumerable All = new[] { Normal, Starter, Decoration, ThirdParty, PirateIsland, Cliff }; - public readonly string Name; public readonly short? ElementValue; @@ -59,6 +58,43 @@ public static IslandType FromElementValue(short? elementValue) return type; } + public static IslandType FromIslandFileName(string fileName) + { + switch (fileName) + { + case "moderate_3rdparty02_01": + case "colony01_3rdparty05_01": + case "moderate_3rdparty06_01": + case "moderate_3rdparty07_01": + case "moderate_3rdparty08_01": + case "colony03_3rdparty09_01": + case "colony03_d_18": + return ThirdParty; + case "moderate_3rdparty03_01": + case "colony01_3rdparty04_01": + return PirateIsland; + default: + if (fileName.Contains("_d_") || fileName.Contains("_dst_") || fileName.Contains("_battlesite_")|| fileName.Contains("_encounter_")) return Decoration; + return Normal; + } + } + + public static string? DefaultIslandLabelFromFileName(string fileName) + { + return fileName switch + { + "moderate_3rdparty02_01" => "Sir Archibald Blake", + "colony01_3rdparty05_01" => "Isabel Sarmento", + "moderate_3rdparty06_01" => "Old Nate", + "colony03_d_18" => "Old Nate (Arctic)", + "moderate_3rdparty07_01" => "Eli Bleakworth", + "moderate_3rdparty08_01" => "Madame Kahina", + "colony03_3rdparty09_01" => "Qumaq", + "moderate_3rdparty03_01" => "Anne Harlow", + "colony01_3rdparty04_01" => "Jean La Fortune", + _ => null, + }; + } public override string ToString() => Name; diff --git a/AnnoMapEditor/MapTemplates/Enums/MapElementType.cs b/AnnoMapEditor/MapTemplates/Enums/MapElementType.cs index ac00470..2687b64 100644 --- a/AnnoMapEditor/MapTemplates/Enums/MapElementType.cs +++ b/AnnoMapEditor/MapTemplates/Enums/MapElementType.cs @@ -1,5 +1,6 @@ using AnnoMapEditor.Utilities; using System.Linq; +using AnnoMapEditor.MapTemplates.Models; namespace AnnoMapEditor.MapTemplates.Enums { @@ -35,5 +36,16 @@ public static MapElementType FromElementValue(int? elementValue) return mapElementType; } + + public static MapElementType FromElement(MapElement mapElement) + { + return mapElement switch + { + FixedIslandElement => FixedIsland, + RandomIslandElement => PoolIsland, + StartingSpotElement => StartingSpot, + _ => FixedIsland + }; + } } } diff --git a/AnnoMapEditor/MapTemplates/Models/FixedIslandElement.cs b/AnnoMapEditor/MapTemplates/Models/FixedIslandElement.cs index 8487693..04574fc 100644 --- a/AnnoMapEditor/MapTemplates/Models/FixedIslandElement.cs +++ b/AnnoMapEditor/MapTemplates/Models/FixedIslandElement.cs @@ -40,9 +40,7 @@ public bool RandomizeRotation get => _randomizeRotation; set { SetProperty(ref _randomizeRotation, value); - - if (!value && Rotation == null) - Rotation = 0; + if (!value && Rotation == null) Rotation = 0; } } private bool _randomizeRotation = true; @@ -70,7 +68,7 @@ public bool RandomizeFertilities public bool RandomizeSlots { get => _randomizeSlots; - set => SetProperty(ref _randomizeSlots, value); + set => SetProperty( ref _randomizeSlots, value); } private bool _randomizeSlots = true; diff --git a/AnnoMapEditor/MapTemplates/Models/IslandElement.cs b/AnnoMapEditor/MapTemplates/Models/IslandElement.cs index 4b434ee..120761e 100644 --- a/AnnoMapEditor/MapTemplates/Models/IslandElement.cs +++ b/AnnoMapEditor/MapTemplates/Models/IslandElement.cs @@ -1,6 +1,5 @@ using Anno.FileDBModels.Anno1800.MapTemplate; using AnnoMapEditor.MapTemplates.Enums; -using AnnoMapEditor.Utilities; using IslandType = AnnoMapEditor.MapTemplates.Enums.IslandType; namespace AnnoMapEditor.MapTemplates.Models @@ -45,8 +44,7 @@ public IslandElement(IslandType islandType) { _islandType = islandType; } - - + // ---- Serialization ---- public IslandElement(Element sourceTemplate) diff --git a/AnnoMapEditor/MapTemplates/Models/MapTemplate.cs b/AnnoMapEditor/MapTemplates/Models/MapTemplate.cs index 3f9f092..ee7b325 100644 --- a/AnnoMapEditor/MapTemplates/Models/MapTemplate.cs +++ b/AnnoMapEditor/MapTemplates/Models/MapTemplate.cs @@ -6,6 +6,7 @@ using System.Collections.ObjectModel; using System.IO; using System.Linq; +using AnnoMapEditor.UI.Controls.Toolbar; namespace AnnoMapEditor.MapTemplates.Models { @@ -22,10 +23,10 @@ public Vector2 Size public Rect2 PlayableArea { - get => _playableAea; - private set => SetProperty(ref _playableAea, value, dependendProperties: new[] { nameof(MapSizeText) }); + get => _playableArea; + private set => SetProperty(ref _playableArea, value, dependendProperties: new[] { nameof(MapSizeText) }); } - private Rect2 _playableAea = new(); + private Rect2 _playableArea = new(); public SessionAsset Session { @@ -49,18 +50,37 @@ public bool ResizingInProgress public string MapSizeText => $"Size: {Size.X}, Playable: {PlayableArea.Width}"; + public bool ShowLabels + { + get => _showLabels; + set + { + SetProperty(ref _showLabels, value); + ToolbarService.Instance.ShowLabelsButtonState = value; + } + } + private bool _showLabels = true; - public MapTemplate(SessionAsset session) + private MapTemplate() + { + ToolbarService.Instance.ButtonClicked += (sender, e) => + { + if (e.ButtonType == ToolbarButtonType.ShowLabels) + ShowLabels = !ShowLabels; + }; + } + + public MapTemplate(SessionAsset session) : this() { _session = session; _templateDocument = new MapTemplateDocument(); } - public MapTemplate(MapTemplateDocument document, SessionAsset session) + public MapTemplate(MapTemplateDocument document, SessionAsset session) : this() { _session = session; _size = new Vector2(document.MapTemplate?.Size); - _playableAea = new Rect2(document.MapTemplate?.PlayableArea); + _playableArea = new Rect2(document.MapTemplate?.PlayableArea); _templateDocument = document; // TODO: Allow empty templates? @@ -80,7 +100,7 @@ public MapTemplate(MapTemplateDocument document, SessionAsset session) _templateDocument.MapTemplate.TemplateElement = null; } - public MapTemplate(int mapSize, int playableSize, SessionAsset session) + public MapTemplate(int mapSize, int playableSize, SessionAsset session) : this() { int margin = (mapSize - playableSize) / 2; @@ -96,10 +116,11 @@ public MapTemplate(int mapSize, int playableSize, SessionAsset session) _session = session; _size = new Vector2(_templateDocument.MapTemplate.Size); - _playableAea = new Rect2(_templateDocument.MapTemplate.PlayableArea); + _playableArea = new Rect2(_templateDocument.MapTemplate.PlayableArea); // create starting spots in the default location Elements.AddRange(CreateNewStartingSpots(mapSize)); + } @@ -148,6 +169,11 @@ public void ResizeMapTemplate(int mapSize, (int x1, int y1, int x2, int y2) play MapSizeConfigChanged?.Invoke(this, new MapTemplateResizeEventArgs(oldMapSize, oldPlayableSize)); } + public void RestoreMapSizeConfig(int mapSize, Rect2 playableArea) + { + // TODO: Implement Map Size Config restoring + } + public void ResizeAndCommitMapTemplate(int mapSize, (int x1, int y1, int x2, int y2) playableAreaMargins) { if (_templateDocument.MapTemplate == null) @@ -189,8 +215,7 @@ public void ResizeAndCommitMapTemplate(int mapSize, (int x1, int y1, int x2, int return _templateDocument; } - - + public class MapTemplateResizeEventArgs : EventArgs { public MapTemplateResizeEventArgs(Vector2 oldMapSize, Vector2 oldPlayableSize) diff --git a/AnnoMapEditor/UI/Controls/AddIsland/AddIslandButton.xaml b/AnnoMapEditor/UI/Controls/AddIsland/AddIslandButton.xaml index 9dcf5ec..d5b0ae8 100644 --- a/AnnoMapEditor/UI/Controls/AddIsland/AddIslandButton.xaml +++ b/AnnoMapEditor/UI/Controls/AddIsland/AddIslandButton.xaml @@ -39,10 +39,12 @@ - + + diff --git a/AnnoMapEditor/UI/Controls/Fertilities/FertilitiesViewModel.cs b/AnnoMapEditor/UI/Controls/Fertilities/FertilitiesViewModel.cs deleted file mode 100644 index 371fdfb..0000000 --- a/AnnoMapEditor/UI/Controls/Fertilities/FertilitiesViewModel.cs +++ /dev/null @@ -1,45 +0,0 @@ -using AnnoMapEditor.DataArchives.Assets.Models; -using AnnoMapEditor.MapTemplates.Models; -using AnnoMapEditor.UI.Overlays; -using AnnoMapEditor.UI.Overlays.SelectFertilities; -using AnnoMapEditor.Utilities; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.Linq; - -namespace AnnoMapEditor.UI.Controls.Fertilities -{ - public class FertilitiesViewModel - { - public FixedIslandElement FixedIsland { get; init; } - - public RegionAsset Region { get; init; } - - public ObservableCollection Fertilities { get; init; } = new(); - - - public FertilitiesViewModel(FixedIslandElement fixedIsland, RegionAsset region) - { - FixedIsland = fixedIsland; - Region = region; - - if(fixedIsland.RandomizeFertilities == false) - SortFertilities(); - - fixedIsland.Fertilities.CollectionChanged += SortFertilities; - } - - private void SortFertilities(object? _ = null, NotifyCollectionChangedEventArgs? __ = null) - { - Fertilities.Clear(); - foreach (FertilityAsset fertility in FixedIsland.Fertilities.OrderBy(FertilityComparer.Instance)) - Fertilities.Add(fertility); - } - - public void OnConfigure() - { - SelectFertilitiesViewModel selectViewModel = new(Region, FixedIsland); - OverlayService.Instance.Show(selectViewModel); - } - } -} diff --git a/AnnoMapEditor/UI/Controls/Fertilities/FertilityControl.xaml b/AnnoMapEditor/UI/Controls/Fertilities/FertilityControl.xaml deleted file mode 100644 index 52bb561..0000000 --- a/AnnoMapEditor/UI/Controls/Fertilities/FertilityControl.xaml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +