Skip to content

Commit

Permalink
*Improved asset corruption notification.
Browse files Browse the repository at this point in the history
  • Loading branch information
paladin-t committed Mar 19, 2024
1 parent 5c72b93 commit 524dbfc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ class Asset : public NonCopyable {
bool revertible(void) const;

/**
* @brief Gets whether the asset is referencing.
* @brief Gets whether the asset would reference another.
*
* @return The possible referencing type.
*/
unsigned referencing(void) const;

Expand Down
1 change: 1 addition & 0 deletions src/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ bool Theme::open(class Renderer* rnd) {
dialogItem_InputAnimationName("Input animation name:");
dialogItem_InputAssetName("Input asset name:");
dialogItem_InputInterval("Input interval:");
dialogItem_InvalidAssetOrCorruptData("Invalid asset or corrupt data: \"%s\".");
dialogItem_MapSize("Map size:");
dialogItem_Palette("Palette:");
dialogItem_Path("Path:");
Expand Down
1 change: 1 addition & 0 deletions src/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class Theme {
BITTY_PROPERTY_READONLY(std::string, dialogItem_InputAnimationName)
BITTY_PROPERTY_READONLY(std::string, dialogItem_InputAssetName)
BITTY_PROPERTY_READONLY(std::string, dialogItem_InputInterval)
BITTY_PROPERTY_READONLY(std::string, dialogItem_InvalidAssetOrCorruptData)
BITTY_PROPERTY_READONLY(std::string, dialogItem_MapSize)
BITTY_PROPERTY_READONLY(std::string, dialogItem_Palette)
BITTY_PROPERTY_READONLY(std::string, dialogItem_Path)
Expand Down
36 changes: 34 additions & 2 deletions src/workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1839,8 +1839,12 @@ void Workspace::editing(class Window* wnd, class Renderer* rnd, const class Proj

asset->prepare(Asset::EDITING, false);

if (!asset->object(Asset::EDITING))
resolveAssetRef(wnd, rnd, project, asset->entry().c_str());
if (!asset->object(Asset::EDITING)) {
if (asset->referencing())
resolveAssetRef(wnd, rnd, project, asset->entry().c_str());
else
notifyAssetCorrupt(wnd, rnd, project, asset->entry().c_str());
}

editor = asset->editor();

Expand Down Expand Up @@ -3577,6 +3581,34 @@ void Workspace::resolveAssetRef(class Window* /* wnd */, class Renderer* rnd, co
);
}

void Workspace::notifyAssetCorrupt(class Window* /* wnd */, class Renderer* /* rnd */, const class Project* project, const char* asset_) {
LockGuard<RecursiveMutex>::UniquePtr acquired;
Project* prj = project->acquire(acquired);
if (!prj)
return;

Asset* asset = prj->get(asset_);
if (!asset)
return;

const std::string entry = asset->entry().name();

const std::string msg = Text::cformat(theme()->dialogItem_InvalidAssetOrCorruptData().c_str(), entry.c_str());
error(msg.c_str());

Asset::States* states = asset->states();
states->deactivate();

asset->finish(Asset::EDITING, false);

messagePopupBox(
msg,
nullptr,
nullptr,
nullptr
);
}

void Workspace::beginSplash(class Window* wnd, class Renderer* rnd, const class Project* project) {
#if BITTY_SPLASH_ENABLED
if (workspaceHasSplashImage()) {
Expand Down
1 change: 1 addition & 0 deletions src/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ class Workspace : public Executable::Observer, public Dispatchable, public NonCo
void resizeAssetTile(class Window* wnd, class Renderer* rnd, const class Project* project, Asset::List::Index index);
void rebindAssetRef(class Window* wnd, class Renderer* rnd, const class Project* project, Asset::List::Index index);
void resolveAssetRef(class Window* wnd, class Renderer* rnd, const class Project* project, const char* asset);
void notifyAssetCorrupt(class Window* wnd, class Renderer* rnd, const class Project* project, const char* asset);

void beginSplash(class Window* wnd, class Renderer* rnd, const class Project* project);
void endSplash(class Window* wnd, class Renderer* rnd, const Text::Dictionary &options);
Expand Down

0 comments on commit 524dbfc

Please sign in to comment.