Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ obj/
*.user
.vs/
publish/
.vscode/launch.json
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/MapExplorer.App/MapExplorer.App.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
25 changes: 25 additions & 0 deletions src/MapExplorer.App/Converters/BlockColorConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
using RenderColors = MapExplorer.Rendering.Colors;

namespace MapExplorer.App.Converters;

/// <summary>Converts a block name (e.g. "minecraft:dirt") to its curated swatch color — used by the
/// edit-mode material palette/search list/recents, which bind directly to plain block-name strings
/// rather than a wrapping view-model per entry (unlike OreOption, this list is filtered/reordered
/// live by search text and MRU order, so a lightweight converter is simpler than keeping a parallel
/// ObservableCollection of wrapper objects in sync).</summary>
public sealed class BlockColorConverter : IValueConverter
{
public static readonly BlockColorConverter Instance = new();

public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var rgb = RenderColors.GetBlockColor(value as string ?? "minecraft:air");
return new SolidColorBrush(Color.FromRgb(rgb.R, rgb.G, rgb.B));
}

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
throw new NotSupportedException();
}
16 changes: 16 additions & 0 deletions src/MapExplorer.App/Converters/SavingLabelConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Globalization;
using Avalonia.Data.Converters;

namespace MapExplorer.App.Converters;

/// <summary>Save button label: "Saving…" while EditViewModel.SaveCommand is running, "Save" otherwise.</summary>
public sealed class SavingLabelConverter : IValueConverter
{
public static readonly SavingLabelConverter Instance = new();

public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is true ? "Saving…" : "Save";

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
throw new NotSupportedException();
}
5 changes: 5 additions & 0 deletions src/MapExplorer.App/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@
IsEnabled="{Binding IsEndAvailable}" ToolTip.Tip="{Binding EndTooltip}" />
<Button Content="Players" Click="OnPlayersClicked"
Classes.active="{Binding IsPlayersPanelOpen}" Classes="dimBtn" Margin="24,0,0,0" />
<Button Content="Edit" Click="OnEditClicked"
Classes.active="{Binding Edit.IsEditModeOn}" Classes="dimBtn" />
<Button Content="← Worlds" Click="OnBackClicked" Margin="24,0,0,0"
Background="Transparent" Foreground="#aaaaaa" BorderBrush="#444444" BorderThickness="1" />
</StackPanel>
</Border>
<Border DockPanel.Dock="Left" IsVisible="{Binding IsPlayersPanelOpen}">
<views:PlayersView DataContext="{Binding Players}" />
</Border>
<Border DockPanel.Dock="Left" IsVisible="{Binding Edit.IsEditModeOn}">
<views:EditPanelView DataContext="{Binding Edit}" />
</Border>
<views:LayerPanelView DockPanel.Dock="Right" DataContext="{Binding Map}" />
<Grid>
<views:MapCanvasControl x:Name="MapCanvas" />
Expand Down
27 changes: 27 additions & 0 deletions src/MapExplorer.App/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public MainWindow()

MapCanvas.Config = _viewModel.Map.BuildLayerConfig();
_viewModel.Map.RenderConfigChanged += () => MapCanvas.Config = _viewModel.Map.BuildLayerConfig();
MapCanvas.EditContext = _viewModel.Edit;
_viewModel.Edit.Saved += ResummarizeDirtyChunks;
MapCanvas.HoveredBlockChanged += OnHoveredBlockChanged;
MapCanvas.ZoomChanged += OnZoomChanged;
_viewModel.RegionDirRequested += async regionDir =>
Expand Down Expand Up @@ -70,6 +72,8 @@ private void OnDimensionClicked(object? sender, Avalonia.Interactivity.RoutedEve

private void OnPlayersClicked(object? sender, Avalonia.Interactivity.RoutedEventArgs e) => _viewModel.TogglePlayersPanel();

private void OnEditClicked(object? sender, Avalonia.Interactivity.RoutedEventArgs e) => _viewModel.ToggleEditMode();

private void OnHoveredBlockChanged(HoveredBlock? block)
{
Dispatcher.UIThread.Post(() =>
Expand Down Expand Up @@ -106,6 +110,7 @@ private async Task LoadWorld(string regionDir, CancellationToken cancellationTok
var blockNames = new NamePalette();
var biomeNames = new NamePalette();
var chunkStore = new WorldChunkStore(regionDir);
_viewModel.Edit.SetRegionDir(regionDir, chunkStore);

// WorldLoader.Load only hands back one summary per chunk (the return value below), so the
// ore summary is captured as a side effect of the same summarize callback instead of a
Expand Down Expand Up @@ -197,4 +202,26 @@ private async Task LoadWorld(string regionDir, CancellationToken cancellationTok
map.StatusText = $"Loaded {result.RegionCount} regions, {result.Chunks.Count} chunks in {sw.ElapsedMilliseconds}ms " +
$"(threads: {Environment.ProcessorCount})";
}

/// <summary>After a successful edit-mode Save, refreshes the always-resident summary/ore data for
/// just the chunks that changed, so Surface/Heightmap/ore-overlay views reflect the edit without
/// requiring a full world reload. Slice-mode rendering doesn't need this at all — it already
/// renders straight from the edit overlay regardless of save state (see MapCanvasControl).</summary>
private void ResummarizeDirtyChunks()
{
var world = MapCanvas.World;
if (world is null) return;

foreach (var (cx, cz) in _viewModel.Edit.Overlay.DirtyChunks)
{
world.ChunkStore.InvalidateChunk(cx, cz);
var chunkData = world.ChunkStore.GetOrDecode(cx, cz);
if (chunkData is null) continue;

world.Summaries[(cx, cz)] = ChunkSummaryBuilder.Build(chunkData, world.BlockNames, world.BiomeNames);
world.OreSummaries[(cx, cz)] = OreSummaryBuilder.Build(chunkData);
}

MapCanvas.NotifyChunksGrew();
}
}
Loading
Loading