Skip to content

Commit

Permalink
Editor: move spritefile init after game load into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Aug 15, 2024
1 parent 9c09ae9 commit ab8f5db
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
51 changes: 30 additions & 21 deletions Editor/AGS.Editor/Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,36 @@ public bool LoadGameFromDisk(string gameToLoad, bool interactive)
SetDefaultValuesForNewFeatures(game);
Utilities.EnsureStandardSubFoldersExist();

InitSpritesAfterGameLoad(game, errors);

// Process after game load operations
RecentGame recentGame = new RecentGame(game.Settings.GameName, gameDirectory);
if (Factory.AGSEditor.Settings.RecentGames.Contains(recentGame))
{
Factory.AGSEditor.Settings.RecentGames.Remove(recentGame);
}
Factory.AGSEditor.Settings.RecentGames.Insert(0, recentGame);

Factory.Events.OnGamePostLoad(game);

// WARNING: this is where the "global" Factory.AGSEditor.CurrentGame is set;
// any tasks and events that expect to reference it must be called after!
Factory.AGSEditor.RefreshEditorAfterGameLoad(game, errors);
if (needToSave)
{
Factory.AGSEditor.SaveGameFiles();
}

Factory.AGSEditor.ReportGameLoad(errors);
return true;
}

/// <summary>
/// Initializes sprite file after loading a new game.
/// Tests if the file exists and suggests to recreate if one is missing.
/// </summary>
private static void InitSpritesAfterGameLoad(Game game, CompileMessages errors)
{
// Load the sprite file
bool isNewSpriteFile = false;
if (!File.Exists(Path.Combine(game.DirectoryPath, AGSEditor.SPRITE_FILE_NAME)))
Expand All @@ -155,27 +185,6 @@ public bool LoadGameFromDisk(string gameToLoad, bool interactive)
if (!isNewSpriteFile)
CreateNewSpriteFile();
}

// Process after game load operations
RecentGame recentGame = new RecentGame(game.Settings.GameName, gameDirectory);
if (Factory.AGSEditor.Settings.RecentGames.Contains(recentGame))
{
Factory.AGSEditor.Settings.RecentGames.Remove(recentGame);
}
Factory.AGSEditor.Settings.RecentGames.Insert(0, recentGame);

Factory.Events.OnGamePostLoad(game);

// WARNING: this is where the "global" Factory.AGSEditor.CurrentGame is set;
// any tasks and events that expect to reference it must be called after!
Factory.AGSEditor.RefreshEditorAfterGameLoad(game, errors);
if (needToSave)
{
Factory.AGSEditor.SaveGameFiles();
}

Factory.AGSEditor.ReportGameLoad(errors);
return true;
}

public static void CreateNewSpriteFile()
Expand Down
2 changes: 1 addition & 1 deletion Editor/AGS.Native/agsnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,7 @@ Common::Bitmap *CreateNativeBitmap(System::Drawing::Bitmap^ bmp, int spriteImpor
flags |= SPF_ALPHACHANNEL;
if (tempsprite->GetColorDepth() == 32)
{
BitmapHelper::ReplaceAlphaWithRGBMask(tempsprite);
BitmapHelper::ReplaceZeroAlphaWithRGBMask(tempsprite);
}
}
else if (tempsprite->GetColorDepth() == 32)
Expand Down

0 comments on commit ab8f5db

Please sign in to comment.