-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add import functionality to SpawnableTypes
- Loading branch information
Showing
9 changed files
with
163 additions
and
9 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/DayzServerTools.Application/Stores/PresetImportStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
using DayzServerTools.Application.Extensions; | ||
using DayzServerTools.Library.Xml; | ||
|
||
namespace DayzServerTools.Application.Stores; | ||
|
||
public class PresetImportStore : IClassnameImportStore | ||
{ | ||
private readonly ObservableCollection<SpawnableItem> _target; | ||
|
||
public PresetImportStore(ObservableCollection<SpawnableItem> target) | ||
{ | ||
_target = target; | ||
} | ||
|
||
public void Accept(IEnumerable<string> classnames) | ||
{ | ||
var total = classnames.Count(); | ||
var items = classnames.Select(name => | ||
new SpawnableItem(name, Math.Round(1.0 / total, 2)) | ||
); | ||
_target.AddRange(items); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/DayzServerTools.Application/Stores/SpawnableTypePresetsImportStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
using DayzServerTools.Application.Extensions; | ||
using DayzServerTools.Application.ViewModels; | ||
using DayzServerTools.Library.Xml; | ||
|
||
namespace DayzServerTools.Application.Stores; | ||
|
||
public class SpawnableTypePresetsImportStore : IClassnameImportStore | ||
{ | ||
private readonly ObservableCollection<SpawnablePresetViewModel> _target; | ||
|
||
public SpawnableTypePresetsImportStore(ObservableCollection<SpawnablePresetViewModel> target) | ||
{ | ||
_target = target; | ||
} | ||
|
||
public void Accept(IEnumerable<string> classnames) | ||
{ | ||
var items = classnames.Select(name => new SpawnableItem(name, 1)); | ||
var presetVMs = items.Select(item => | ||
{ | ||
var preset = new SpawnablePreset() { Chance = 1 }; | ||
preset.Items.Add(item); | ||
return new SpawnablePresetViewModel(preset); | ||
}); | ||
_target.AddRange(presetVMs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters