Skip to content
Open
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ set(
src/PIDStudio.h
src/File.cpp
src/File.h
src/Filters.h
src/String.cpp
src/String.h
src/Filesystem.cpp
src/Filesystem.h
src/ImGuiExtensions.cpp
src/ImGuiExtensions.h
src/formats/PCXFile.cpp
src/formats/PCXFile.h
src/formats/BMPFile.cpp
src/formats/BMPFile.h
src/formats/PIDFile.cpp
src/formats/PIDFile.h
src/formats/PIDPalette.cpp
src/formats/PIDPalette.h
src/formats/PNGFile.h
src/formats/PNGFile.cpp
src/FilesystemWatcher.h
src/FilesystemWatcher.cpp
src/AssetLibrary.cpp
src/AssetLibrary.h
src/Project.cpp
Expand All @@ -32,6 +38,16 @@ set(
src/SupportedGame.h
src/games/Claw.cpp
src/games/Claw.h
src/PaletteLUV.h
src/PaletteLUV.cpp
src/gui/GUI.h
src/gui/GUI.cpp
src/gui/Dialogs.h
src/gui/Dialogs.cpp
src/Batch.h
src/Batch.cpp
src/PaletteManager.h
src/PaletteManager.cpp
)

set(
Expand Down Expand Up @@ -113,6 +129,7 @@ endif (UNIX)
if (MSVC)
set_target_properties(
${PROJECT_NAME} PROPERTIES
LINK_FLAGS "/SUBSYSTEM:windows /ENTRY:mainCRTStartup"
VS_DEBUGGER_WORKING_DIRECTORY "$(ProjectDir)..\\")
endif (MSVC)

Expand Down
46 changes: 25 additions & 21 deletions src/AssetLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
#include "formats/PCXFile.h"
#include "SupportedGame.h"
#include "String.h"
#include "gui/GUI.h"

void palFileHandler(const std::shared_ptr<AssetLibraryTreeNode> &node) {
#define PCX_PAL_OFFSET -768

void palFileHandler(const std::shared_ptr<TreeNodeBase> &node) {
node->palette = std::make_shared<PIDPalette>();
if (node->palette->loadFromFile(node->path)) {
node->parent->palette = node->palette;
}
}

void pcxFileHandler(const std::shared_ptr<AssetLibraryTreeNode> &node) {
std::shared_ptr<PCXFile> pcxFile = std::make_shared<PCXFile>();
if (pcxFile->loadFromFile(node->path)) {
node->palette = pcxFile->getPalette();
void pcxFileHandler(const std::shared_ptr<TreeNodeBase> &node) {
node->palette = std::make_shared<PIDPalette>();
if (node->palette->loadFromFilePartially(node->path, PCX_PAL_OFFSET, std::ios_base::end)) {
node->parent->palette = node->palette;
}
node->isHidden = false;
}

void pidFileHandler(const std::shared_ptr<AssetLibraryTreeNode> &node) {
void pidFileHandler(const std::shared_ptr<TreeNodeBase> &node) {
node->isHidden = false;
}

Expand All @@ -35,17 +38,18 @@ AssetLibrary::AssetLibrary(
PIDStudio *app,
const std::filesystem::path &path,
const std::shared_ptr<SupportedGame> &game
) : FilesystemWatcher<AssetLibraryTreeNode>(path), app(app), game(game) {}
) : FilesystemWatcher(app, path), game(game) {}

void AssetLibrary::populateTree(
const std::filesystem::path &rootPath,
const std::shared_ptr<AssetLibraryTreeNode> &rootNode
) {
FilesystemWatcher::populateTree(rootPath, rootNode);
void AssetLibrary::populateTree() {
FilesystemWatcher::populateTree();
game->initializeLibrary(getRoot());
}

void AssetLibrary::processFileNode(const std::shared_ptr<AssetLibraryTreeNode> &childNode) {
bool AssetLibrary::isFileTypeSupported(std::string extension) {
return supportedFileTypes.contains(extension);
}

void AssetLibrary::processFileNode(const std::shared_ptr<TreeNodeBase> &childNode) {
std::string ext = childNode->path.extension().string();
std::transform(ext.begin(), ext.end(), ext.begin(), charToLower);

Expand All @@ -55,17 +59,17 @@ void AssetLibrary::processFileNode(const std::shared_ptr<AssetLibraryTreeNode> &
FilesystemWatcher::processFileNode(childNode);
}

void AssetLibrary::displayContextMenu(const std::shared_ptr<AssetLibraryTreeNode> &node) {
app->libraryEntryContextMenu(shared_from_this(), node, isLeaf(node), isRoot(node));
void AssetLibrary::displayContextMenu(const std::shared_ptr<TreeNodeBase> &node) {
UI::libraryEntryContextMenu(app, shared_from_this(), node);
}

void AssetLibrary::openLeafNode(const std::shared_ptr<AssetLibraryTreeNode> &node) {
app->openLibraryFile(shared_from_this(), node);
void AssetLibrary::openLeafNode(const std::shared_ptr<TreeNodeBase> &node) {
app->openImageFile(node->path, inferPalette(node));
}

bool AssetLibrary::hasFilepath(
const std::filesystem::path &filepath,
std::shared_ptr<AssetLibraryTreeNode> &outFoundNode
std::shared_ptr<TreeNodeBase> &outFoundNode
) {
const std::filesystem::path &path = getPath();

Expand All @@ -83,9 +87,9 @@ bool AssetLibrary::hasFilepath(
return isFilepathWithinLibrary && outFoundNode;
}

std::shared_ptr<PIDPalette> AssetLibrary::inferPalette(const std::shared_ptr<AssetLibraryTreeNode> &node) {
std::shared_ptr<PIDPalette> palette = node->palette;
std::shared_ptr<AssetLibraryTreeNode> parent = node->parent;
std::shared_ptr<PIDPalette> AssetLibrary::inferPalette(const std::shared_ptr<TreeNodeBase> &node) {
auto palette = node->palette;
auto parent = node->parent;

while (parent && !palette) {
palette = parent->palette;
Expand Down
27 changes: 12 additions & 15 deletions src/AssetLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@
class PIDPalette;
class SupportedGame;

struct AssetLibraryTreeNode : public TreeNodeBase<AssetLibraryTreeNode> {
std::shared_ptr<PIDPalette> palette;
};

class AssetLibrary : public FilesystemWatcher<AssetLibraryTreeNode>, public std::enable_shared_from_this<AssetLibrary>
{
class AssetLibrary : public FilesystemWatcher, public std::enable_shared_from_this<AssetLibrary> {
public:
typedef void (*FileHandler)(const std::shared_ptr<AssetLibraryTreeNode>&);
typedef void (*FileHandler)(const std::shared_ptr<TreeNodeBase>&);

AssetLibrary(class PIDStudio* app, const std::filesystem::path& path, const std::shared_ptr<SupportedGame>& game);

[[nodiscard]] const char* getIniKey() const;

bool hasFilepath(const std::filesystem::path& filepath, std::shared_ptr<AssetLibraryTreeNode>& outFoundNode);
bool hasFilepath(const std::filesystem::path& filepath, std::shared_ptr<TreeNodeBase>& outFoundNode);

static std::shared_ptr<PIDPalette> inferPalette(const std::shared_ptr<TreeNodeBase>& node);

bool isFileTypeSupported(std::string extension);

static std::shared_ptr<PIDPalette> inferPalette(const std::shared_ptr<AssetLibraryTreeNode>& node);
private:
static std::unordered_map<std::string, FileHandler> supportedFileTypes;

class PIDStudio* app;
std::shared_ptr<SupportedGame> game;

void populateTree(const std::filesystem::path& path, const std::shared_ptr<AssetLibraryTreeNode>& node) override;
void processFileNode(const std::shared_ptr<AssetLibraryTreeNode>& childNode) override;
void displayContextMenu(const std::shared_ptr<AssetLibraryTreeNode> &node) override;
void openLeafNode(const std::shared_ptr<AssetLibraryTreeNode> &node) override;
private:
void populateTree() override;
void processFileNode(const std::shared_ptr<TreeNodeBase>& childNode) override;
void displayContextMenu(const std::shared_ptr<TreeNodeBase> &node) override;
void openLeafNode(const std::shared_ptr<TreeNodeBase> &node) override;
};
Loading