Skip to content

Commit

Permalink
Merge pull request #229 from jetelain/config-endpoints
Browse files Browse the repository at this point in the history
Allow to change source locations
  • Loading branch information
jetelain committed Jun 2, 2024
2 parents cbbb009 + a0d7f53 commit dff5da2
Show file tree
Hide file tree
Showing 26 changed files with 342 additions and 70 deletions.
9 changes: 7 additions & 2 deletions GameRealisticMap.Arma3.CommandLine/MapWorkspace.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
using GameRealisticMap.Arma3.Assets;
using GameRealisticMap.Arma3.IO;
using GameRealisticMap.Arma3.TerrainBuilder;
using GameRealisticMap.Configuration;
using GameRealisticMap.Reporting;

namespace GameRealisticMap.Arma3.CommandLine
{
internal class MapWorkspace : IDisposable
{
public MapWorkspace(ProjectDrive projectDrive, Arma3Assets assets, Arma3MapConfig a3config, ConsoleProgressSystem progress)
public MapWorkspace(ProjectDrive projectDrive, Arma3Assets assets, Arma3MapConfig a3config, ConsoleProgressSystem progress, ISourceLocations sources)
{
ProjectDrive = projectDrive;
Assets = assets;
MapConfig = a3config;
Progress = progress;
Sources = sources;
}

public ProjectDrive ProjectDrive { get; }
public Arma3Assets Assets { get; }
public Arma3MapConfig MapConfig { get; }
public ConsoleProgressSystem Progress { get; }
public ISourceLocations Sources { get; }

public static async Task<MapWorkspace> Create(Arma3MapConfig a3config, string searchPath)
{
Expand All @@ -42,7 +45,9 @@ public static async Task<MapWorkspace> Create(Arma3MapConfig a3config, string se

var assets = await Arma3Assets.LoadFromFile(models, a3config.AssetConfigFile);

return new MapWorkspace(projectDrive, assets, a3config, progress);
var sources = await SourceLocations.Load();

return new MapWorkspace(projectDrive, assets, a3config, progress, sources);
}

public void Dispose()
Expand Down
8 changes: 4 additions & 4 deletions GameRealisticMap.Arma3.CommandLine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static async Task<int> Main(string[] args)
private static async Task<int> GenerateTerrainBuilder(GenerateTerrainBuilderOptions opts)
{
using var workspace = await opts.CreateWorkspace();
var generator = new Arma3TerrainBuilderGenerator(workspace.Assets, workspace.ProjectDrive);
var generator = new Arma3TerrainBuilderGenerator(workspace.Assets, workspace.ProjectDrive, workspace.Sources);
Directory.CreateDirectory(opts.TargetDirectory);
await generator.GenerateTerrainBuilderFiles(workspace.Progress, workspace.MapConfig, opts.TargetDirectory);
return 0;
Expand All @@ -37,7 +37,7 @@ private static async Task<int> GenerateTerrainBuilder(GenerateTerrainBuilderOpti
private static async Task<int> GenerateObjectLayer(GenerateObjectLayerOptions opts)
{
using var workspace = await opts.CreateWorkspace();
var generator = new Arma3TerrainBuilderGenerator(workspace.Assets, workspace.ProjectDrive);
var generator = new Arma3TerrainBuilderGenerator(workspace.Assets, workspace.ProjectDrive, workspace.Sources);
Directory.CreateDirectory(opts.TargetDirectory);
await generator.GenerateOnlyOneLayer(workspace.Progress, workspace.MapConfig, opts.LayerName, opts.TargetDirectory);
return 0;
Expand All @@ -46,7 +46,7 @@ private static async Task<int> GenerateObjectLayer(GenerateObjectLayerOptions op
private static async Task<int> GenerateWrp(GenerateWrpOptions opts)
{
using var workspace = await opts.CreateWorkspace();
var generator = new Arma3MapGenerator(workspace.Assets, workspace.ProjectDrive, new NonePboCompilerFactory());
var generator = new Arma3MapGenerator(workspace.Assets, workspace.ProjectDrive, new NonePboCompilerFactory(), workspace.Sources);
await generator.GenerateWrp(workspace.Progress, workspace.MapConfig, !opts.SkipPaa);
return 0;
}
Expand All @@ -58,7 +58,7 @@ private static async Task<int> GenerateMod(GenerateModOptions opts)
throw new PlatformNotSupportedException("Mod generation works only on Windows");
}
using var workspace = await opts.CreateWorkspace();
var generator = new Arma3MapGenerator(workspace.Assets, workspace.ProjectDrive, new PboCompilerFactory(workspace.ProjectDrive));
var generator = new Arma3MapGenerator(workspace.Assets, workspace.ProjectDrive, new PboCompilerFactory(workspace.ProjectDrive), workspace.Sources);
await generator.GenerateMod(workspace.Progress, workspace.MapConfig);
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion GameRealisticMap.Arma3/Arma3DemoMapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using GameRealisticMap.Arma3.Assets;
using GameRealisticMap.Arma3.GameEngine;
using GameRealisticMap.Arma3.IO;
using GameRealisticMap.Configuration;
using GameRealisticMap.Demo;
using GameRealisticMap.ElevationModel;
using GameRealisticMap.Geometries;
Expand All @@ -26,7 +27,7 @@ public class Arma3DemoMapGenerator : Arma3MapGenerator
private readonly IDemoNaming demoNaming;

public Arma3DemoMapGenerator(IArma3RegionAssets assets, ProjectDrive projectDrive, string name, IPboCompilerFactory pboCompilerFactory, IDemoNaming? demoNaming = null)
: base(assets, projectDrive, pboCompilerFactory)
: base(assets, projectDrive, pboCompilerFactory, new DefaultSourceLocations())
{
this.name = name;
this.demoNaming = demoNaming ?? new DefaultDemoNaming();
Expand Down
9 changes: 6 additions & 3 deletions GameRealisticMap.Arma3/Arma3MapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GameRealisticMap.Arma3.GameEngine;
using GameRealisticMap.Arma3.Imagery;
using GameRealisticMap.Arma3.IO;
using GameRealisticMap.Configuration;
using GameRealisticMap.ElevationModel;
using GameRealisticMap.ManMade.Places;
using GameRealisticMap.ManMade.Roads;
Expand All @@ -19,12 +20,14 @@ public class Arma3MapGenerator
protected readonly IArma3RegionAssets assets;
private readonly ProjectDrive projectDrive;
private readonly IPboCompilerFactory pboCompilerFactory;
protected readonly ISourceLocations sources;

public Arma3MapGenerator(IArma3RegionAssets assets, ProjectDrive projectDrive, IPboCompilerFactory pboCompilerFactory)
public Arma3MapGenerator(IArma3RegionAssets assets, ProjectDrive projectDrive, IPboCompilerFactory pboCompilerFactory, ISourceLocations sources)
{
this.assets = assets;
this.projectDrive = projectDrive;
this.pboCompilerFactory = pboCompilerFactory;
this.sources = sources;
}

public async Task<IImagerySource?> GetImagerySource(IProgressTask progress, Arma3MapConfig a3config, IHugeImageStorage hugeImageStorage)
Expand All @@ -49,7 +52,7 @@ public Arma3MapGenerator(IArma3RegionAssets assets, ProjectDrive projectDrive, I

protected virtual BuildContext CreateBuildContext(IProgressTask progress, Arma3MapConfig a3config, IOsmDataSource osmSource, IHugeImageStorage? hugeImageStorage = null)
{
var builders = new BuildersCatalog(progress, assets);
var builders = new BuildersCatalog(progress, assets, sources);
return new BuildContext(builders, progress, a3config.TerrainArea, osmSource, a3config.Imagery, hugeImageStorage);
}

Expand Down Expand Up @@ -115,7 +118,7 @@ protected virtual BuildContext CreateBuildContext(IProgressTask progress, Arma3M

protected virtual async Task<IOsmDataSource> LoadOsmData(IProgressTask progress, Arma3MapConfig a3config)
{
var loader = new OsmDataOverPassLoader(progress);
var loader = new OsmDataOverPassLoader(progress, sources);
return await loader.Load(a3config.TerrainArea);
}

Expand Down
9 changes: 6 additions & 3 deletions GameRealisticMap.Arma3/Arma3TerrainBuilderGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using GameRealisticMap.Arma3.IO;
using GameRealisticMap.Arma3.TerrainBuilder;
using GameRealisticMap.Arma3.TerrainBuilder.TmlFiles;
using GameRealisticMap.Configuration;
using GameRealisticMap.ElevationModel;
using GameRealisticMap.ManMade.Places;
using GameRealisticMap.ManMade.Roads;
Expand All @@ -25,20 +26,22 @@ public class Arma3TerrainBuilderGenerator
{
private readonly IArma3RegionAssets assets;
private readonly ProjectDrive projectDrive;
protected readonly ISourceLocations sources;

private const int MaxTerrainBuilderImageSize = 25000; // ~1.8 GB at 24 bpp

private record ImageryPart(int X, int Y, int E, int N, int Size, string Name);

public Arma3TerrainBuilderGenerator(IArma3RegionAssets assets, ProjectDrive projectDrive)
public Arma3TerrainBuilderGenerator(IArma3RegionAssets assets, ProjectDrive projectDrive, ISourceLocations sources)
{
this.assets = assets;
this.projectDrive = projectDrive;
this.sources = sources;
}

private BuildContext CreateBuildContext(IProgressTask progress, Arma3MapConfig a3config, IOsmDataSource osmSource, IHugeImageStorage? hugeImageStorage = null)
{
var builders = new BuildersCatalog(progress, assets);
var builders = new BuildersCatalog(progress, assets, sources);
return new BuildContext(builders, progress, a3config.TerrainArea, osmSource, a3config.Imagery, hugeImageStorage);
}

Expand Down Expand Up @@ -76,7 +79,7 @@ private BuildContext CreateBuildContext(IProgressTask progress, Arma3MapConfig a

private async Task<IOsmDataSource> LoadOsmData(IProgressTask progress, Arma3MapConfig a3config)
{
var loader = new OsmDataOverPassLoader(progress);
var loader = new OsmDataOverPassLoader(progress, sources);
return await loader.Load(a3config.TerrainArea);
}

Expand Down
3 changes: 2 additions & 1 deletion GameRealisticMap.Arma3/Demo/Arma3GdtDemoMapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GameRealisticMap.Arma3.GameEngine;
using GameRealisticMap.Arma3.GameEngine.Roads;
using GameRealisticMap.Arma3.IO;
using GameRealisticMap.Configuration;
using GameRealisticMap.ElevationModel;
using GameRealisticMap.ManMade.Places;
using GameRealisticMap.ManMade.Roads;
Expand All @@ -17,7 +18,7 @@ namespace GameRealisticMap.Arma3.Demo
public sealed class Arma3GdtDemoMapGenerator : Arma3MapGenerator
{
public Arma3GdtDemoMapGenerator(IEnumerable<TerrainMaterialDefinition> definitions, ProjectDrive projectDrive, IPboCompilerFactory pboCompilerFactory)
: base(CreateAssets(definitions), projectDrive, pboCompilerFactory)
: base(CreateAssets(definitions), projectDrive, pboCompilerFactory, new DefaultSourceLocations())
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using GameRealisticMap.Conditions;
using GameRealisticMap.Geometries;
using GameRealisticMap.Osm;
using GameRealisticMap.Studio.Modules.Main.Services;
using GameRealisticMap.Studio.Modules.MapConfigEditor.ViewModels;
using GameRealisticMap.Studio.Modules.Reporting;
using GameRealisticMap.Studio.Shared;
Expand Down Expand Up @@ -63,8 +64,9 @@ private async Task DoGenerateData(IProgressTaskUI taskUI)

var config = await map.GetBuildersConfigSafe(a3config);

var catalog = new BuildersCatalog(taskUI, config);
var loader = new OsmDataOverPassLoader(taskUI);
var sources = IoC.Get<IGrmConfigService>().GetSources();
var catalog = new BuildersCatalog(taskUI, config, sources);
var loader = new OsmDataOverPassLoader(taskUI, sources);
var osmSource = await loader.Load(a3config.TerrainArea);
var context = new BuildContext(catalog, taskUI, a3config.TerrainArea, osmSource, new ImageryOptions());
conditionEvaluator = context.GetData<ConditionEvaluator>();
Expand Down
7 changes: 6 additions & 1 deletion GameRealisticMap.Studio/Modules/Main/MainModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using Caliburn.Micro;
using GameRealisticMap.Studio.Modules.Main.Services;
using GameRealisticMap.Studio.Modules.Main.ViewModels;
using Gemini.Framework;
using Gemini.Framework.Services;
Expand All @@ -15,11 +16,13 @@ namespace GameRealisticMap.Studio.Modules.Main
public class MainModule : ModuleBase
{
private readonly IMainWindow _mainWindow;
private readonly IGrmConfigService _config;

[ImportingConstructor]
public MainModule(IMainWindow mainWindow)
public MainModule(IMainWindow mainWindow, IGrmConfigService config)
{
_mainWindow = mainWindow;
_config = config;
}

public override void Initialize()
Expand All @@ -31,6 +34,8 @@ public override void Initialize()

public override async Task PostInitializeAsync()
{
await _config.Load();

await _mainWindow.Shell.OpenDocumentAsync(IoC.Get<HomeViewModel>());

var args = Environment.GetCommandLineArgs();
Expand Down
30 changes: 30 additions & 0 deletions GameRealisticMap.Studio/Modules/Main/Services/GrmConfigService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Threading.Tasks;
using GameRealisticMap.Configuration;

namespace GameRealisticMap.Studio.Modules.Main.Services
{
[Export(typeof(IGrmConfigService))]
internal class GrmConfigService : IGrmConfigService
{
private ISourceLocations? sources;

public ISourceLocations GetSources()
{
return sources ?? new DefaultSourceLocations();
}

public async Task Load()
{
sources = await SourceLocations.Load();
}

public async Task SetSources(ISourceLocations newSources)
{
await SourceLocations.Save(newSources);
sources = await SourceLocations.Load();
}
}
}
14 changes: 14 additions & 0 deletions GameRealisticMap.Studio/Modules/Main/Services/IGrmConfigService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Threading.Tasks;
using GameRealisticMap.Configuration;

namespace GameRealisticMap.Studio.Modules.Main.Services
{
public interface IGrmConfigService
{
ISourceLocations GetSources();

Task SetSources(ISourceLocations sources);

Task Load();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using Caliburn.Micro;
using GameRealisticMap.Configuration;
using GameRealisticMap.Studio.Modules.Main.Services;
using Gemini.Modules.Settings;

namespace GameRealisticMap.Studio.Modules.Main.ViewModels
{
[PartCreationPolicy(CreationPolicy.NonShared)]
[Export(typeof(ISettingsEditorAsync))]
internal class GrmSourcesViewModel : PropertyChangedBase, ISettingsEditorAsync, ISourceLocations
{
private readonly IGrmConfigService configService;

[ImportingConstructor]
public GrmSourcesViewModel(IGrmConfigService configService)
{
this.configService = configService;
var sources = configService.GetSources();
MapToolkitSRTM15Plus = sources.MapToolkitSRTM15Plus;
MapToolkitSRTM1 = sources.MapToolkitSRTM1;
MapToolkitAW3D30 = sources.MapToolkitAW3D30;
WeatherStats = sources.WeatherStats;
OverpassApiInterpreter = sources.OverpassApiInterpreter;
S2CloudlessBasePath = sources.S2CloudlessBasePath;
}

public string SettingsPageName => "Sources";

public string SettingsPagePath => "Game Realistic Map";

public Uri MapToolkitSRTM15Plus { get; set; }

public Uri MapToolkitSRTM1 { get; set; }

public Uri MapToolkitAW3D30 { get; set; }

public Uri WeatherStats { get; set; }

public Uri OverpassApiInterpreter { get; set; }

public Uri S2CloudlessBasePath { get; set; }

public async Task ApplyChangesAsync()
{
await configService.SetSources(this);
}
}
}
41 changes: 41 additions & 0 deletions GameRealisticMap.Studio/Modules/Main/Views/GrmSourcesView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<UserControl x:Class="GameRealisticMap.Studio.Modules.Main.Views.GrmSourcesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:b="clr-namespace:GameRealisticMap.Studio.Behaviors"
xmlns:r="clr-namespace:GameRealisticMap.Studio"
xmlns:local="clr-namespace:GameRealisticMap.Studio.Modules.Arma3Data.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel>

<StackPanel Orientation="Horizontal">
<Label Width="150">MapToolkit SRTM15Plus</Label>
<TextBox Text="{Binding MapToolkitSRTM15Plus}" Width="450" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Width="150">MapToolkit SRTM1</Label>
<TextBox Text="{Binding MapToolkitSRTM1}" Width="450" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Width="150">MapToolkit AW3D30</Label>
<TextBox Text="{Binding MapToolkitAW3D30}" Width="450" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Width="150">WeatherStats</Label>
<TextBox Text="{Binding WeatherStats}" Width="450" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Width="150">OverpassApi Interpreter</Label>
<TextBox Text="{Binding OverpassApiInterpreter}" Width="450" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Width="150">S2Cloudless Base Path</Label>
<TextBox Text="{Binding S2CloudlessBasePath}" Width="450" />
</StackPanel>



</StackPanel>
</UserControl>
Loading

0 comments on commit dff5da2

Please sign in to comment.