Skip to content

Commit

Permalink
Merge pull request #115 from jetelain/multipart-eden-import
Browse files Browse the repository at this point in the history
Specific multi-part import to avoid elevation errors
  • Loading branch information
jetelain committed Aug 27, 2023
2 parents 479d651 + b919960 commit 8ff454e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 17 deletions.
3 changes: 2 additions & 1 deletion @ArmaMapStudio/addons/eden/functions/fnc_copyPart.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "script_component.hpp"

copyToClipboard (GVAR(results) # GVAR(current));
copyToClipboard ([(GVAR(results) # GVAR(current)), [".part", GVAR(current), count GVAR(results)]] joinString endl);

GVAR(current) = GVAR(current) + 1;
systemChat (format ["Part %1 on %2 copied", GVAR(current), count GVAR(results)]);

Expand Down
2 changes: 1 addition & 1 deletion @ArmaMapStudio/addons/main/script_version.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define MAJOR 0
#define MINOR 3
#define PATCH 1
#define PATCH 2
#define BUILD 0
16 changes: 13 additions & 3 deletions GameRealisticMap.Arma3/Edit/WrpEditBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ public class WrpEditBatch
public List<WrpAddObject> Add { get; } = new List<WrpAddObject>();

public List<WrpRemoveObject> Remove { get; } = new List<WrpRemoveObject>();

public List<WrpSetElevationGrid> Elevation { get; } = new List<WrpSetElevationGrid>();

public bool ElevationAdjustObjects { get; set; }

public string WorldName { get; internal set; } = string.Empty;
public string WorldName { get; set; } = string.Empty;

public float WorldSize { get; set; }

public int Revision { get; set; }

public int? PartCount { get; set; }

public List<int> PartIndexes { get; } = new List<int>();

public int? PartIndex => PartIndexes.Count == 0 ? null : PartIndexes.Max();

public float WorldSize { get; internal set; }
public int Revision { get; internal set; }
public bool IsComplete => PartCount == null || PartCount.Value == PartIndexes.Count;
}
}
5 changes: 5 additions & 0 deletions GameRealisticMap.Arma3/Edit/WrpEditBatchParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public WrpEditBatch Parse(IReadOnlyCollection<string> entries)
ElevationData(exportData, array);
break;

case ".part":
exportData.PartIndexes.Add(Convert.ToInt32(array[1]));
exportData.PartCount = Convert.ToInt32(array[2]);
break;

}
}
report.ReportOneDone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public double WorkingPercent
set { _workingPercent = value; NotifyOfPropertyChange(); }
}

public bool IsReadyToImport => Batch != null && Batch.IsComplete && string.IsNullOrEmpty(ClipboardError);

public Task ClipboardRefresh()
{
ClipboardError = Labels.CompositionClipboardInvalid;
Expand Down Expand Up @@ -85,24 +87,59 @@ private void DoDetect(string value)
try
{
var parser = new WrpEditBatchParser(task, parent.GameFileSystem);
Batch = parser.ParseFromText(value);

if (!string.IsNullOrEmpty(Batch.WorldName))
var batch = parser.ParseFromText(value);
if (!string.IsNullOrEmpty(batch.WorldName))
{
ClipboardError = string.Empty;
var worldName = Path.GetFileNameWithoutExtension(parent.FilePath);
if (!string.Equals(Batch.WorldName, worldName, StringComparison.OrdinalIgnoreCase))
if (!string.Equals(batch.WorldName, worldName, StringComparison.OrdinalIgnoreCase))
{
ClipboardWarning = string.Format(Labels.ExportedDataMapMismatch, batch.WorldName, worldName);
}
else if (batch.Revision != (parent.ConfigFile?.Revision ?? 0))
{
ClipboardWarning = string.Format(Labels.ExportedDataRevisionMismatch, batch.Revision, parent.ConfigFile?.Revision);
}

if (batch.IsComplete)
{
Batch = batch;
}
else
{
ClipboardWarning = string.Format(Labels.ExportedDataMapMismatch, Batch.WorldName, worldName);
if (Batch == null || Batch.IsComplete)
{
Batch = batch;
}
else
{
var intersect = Batch.PartIndexes.Intersect(batch.PartIndexes).ToList();
if (intersect.Any())
{
ClipboardError = string.Format("Part #{0} has been already imported.", intersect.First());
}
else
{
Batch.PartIndexes.AddRange(batch.PartIndexes);
Batch.Add.AddRange(batch.Add);
Batch.Remove.AddRange(batch.Remove);
Batch.Elevation.AddRange(batch.Elevation);
}
}
if (!Batch.IsComplete)
{
ClipboardWarning = GetNextPartMessage(Batch);
}
}
else if (Batch.Revision != (parent.ConfigFile?.Revision ?? 0))

if (Batch != null)
{
ClipboardWarning = string.Format(Labels.ExportedDataRevisionMismatch, Batch.Revision, parent.ConfigFile?.Revision);
ClipboardMessage = string.Format(Labels.ExportedDataStats,
Batch.Add.Count,
Batch.Remove.Count,
Batch.Elevation.Count);
}
ClipboardMessage = string.Format(Labels.ExportedDataStats,
Batch.Add.Count,
Batch.Remove.Count,
Batch.Elevation.Count);
}
}
catch (Exception e)
Expand All @@ -115,11 +152,22 @@ private void DoDetect(string value)
NotifyOfPropertyChange(nameof(IsClipboardValid));
NotifyOfPropertyChange(nameof(IsClipboardWarning));
NotifyOfPropertyChange(nameof(IsClipboardNotValid));
NotifyOfPropertyChange(nameof(IsReadyToImport));
NotifyOfPropertyChange(nameof(ClipboardError));
NotifyOfPropertyChange(nameof(ClipboardWarning));
NotifyOfPropertyChange(nameof(ClipboardMessage));
}

private static string GetNextPartMessage(WrpEditBatch batch)
{
var missing = Enumerable.Range(0, batch.PartCount ?? 1).Except(batch.PartIndexes).ToList();
if (missing.Count == 0)
{
return string.Empty;
}
return string.Format("Click on Refresh button when part #{0} is copied to continue import.", missing.Min() + 1);
}

public Task ClipboardImport()
{
if (Batch != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<Button Padding="10 5" Margin="0 0 5 0" cal:Message.Attach="ClipboardRefresh">
<Run Text="{x:Static r:Labels.Refresh}"/>
</Button>
<Button Padding="10 5" Margin="5 0" cal:Message.Attach="ClipboardImport">
<Button Padding="10 5" Margin="5 0" cal:Message.Attach="ClipboardImport" Visibility="{Binding IsReadyToImport, Converter={StaticResource BooleanToVisibilityConverter}}">
<Run Text="{x:Static r:Labels.ImportFromClipboad}"/>
</Button>
<TextBlock VerticalAlignment="Center" Foreground="DarkOrange" Margin="0 0 5 0" FontWeight="Bold">⚠</TextBlock>
Expand All @@ -88,7 +88,7 @@
<Button Padding="10 5" Margin="0 0 5 0" cal:Message.Attach="ClipboardRefresh">
<Run Text="{x:Static r:Labels.Refresh}"/>
</Button>
<Button Padding="10 5" Margin="5 0" cal:Message.Attach="ClipboardImport">
<Button Padding="10 5" Margin="5 0" cal:Message.Attach="ClipboardImport" Visibility="{Binding IsReadyToImport, Converter={StaticResource BooleanToVisibilityConverter}}">
<Run Text="{x:Static r:Labels.ImportFromClipboad}"/>
</Button>
<TextBlock VerticalAlignment="Center" Foreground="Green" Margin="0 0 5 0">✔</TextBlock>
Expand Down

0 comments on commit 8ff454e

Please sign in to comment.