Skip to content

Commit

Permalink
fixed asset ids at load time
Browse files Browse the repository at this point in the history
  • Loading branch information
NotImplementedLife committed Sep 17, 2024
1 parent 71493d8 commit ca6ee31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions FlipnoteDotNet/App/Service/AssetsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public AssetsService(UndoStack undoStack)
BindingAssets = new BindingList<Asset>(fAssets);
}

public void LoadSavedAssets(Asset[] assets)
{
foreach (Asset asset in assets)
{
Assets.Add(asset);
IdCounter = Math.Max(IdCounter, asset.Id + 1);
}
}

public void AddAsset(Asset asset)
{
if(asset.Id==0)
Expand Down
7 changes: 3 additions & 4 deletions FlipnoteDotNet/App/Storage/Codecs/V1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ public static AppState DecodeProject(Project project, AppState baseState, Canvas

var paletteConfig = projv1.PaletteConfig.ToPaletteConfig();

var appState = new AppState(paletteConfig, baseState.UndoStack);

foreach (var a in projv1.Assets)
appState.AssetsService.Assets.Add(a.ToAsset());
var appState = new AppState(paletteConfig, baseState.UndoStack);

appState.AssetsService.LoadSavedAssets(projv1.Assets.Select(_ => _.ToAsset()).ToArray());

Func<int, Asset> findAssetById = (id) => appState.AssetsService.Assets.Where(a => a.Id == id).FirstOrDefault();

foreach (var f in projv1.Frames)
Expand Down

0 comments on commit ca6ee31

Please sign in to comment.