From e6316d31a4a6c14dad6e4d9159698ae5917ca213 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 7 Aug 2024 16:03:39 -0400 Subject: [PATCH] add SpriteBuilder class --- src/app/zelda3/CMakeLists.txt | 1 + src/app/zelda3/sprite/sprite_builder.cc | 65 ++++++++++++++++++++ src/app/zelda3/sprite/sprite_builder.h | 79 +++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 src/app/zelda3/sprite/sprite_builder.cc create mode 100644 src/app/zelda3/sprite/sprite_builder.h diff --git a/src/app/zelda3/CMakeLists.txt b/src/app/zelda3/CMakeLists.txt index 3b021326..a59b74d1 100644 --- a/src/app/zelda3/CMakeLists.txt +++ b/src/app/zelda3/CMakeLists.txt @@ -5,6 +5,7 @@ set( app/zelda3/screen/inventory.cc app/zelda3/screen/title_screen.cc app/zelda3/sprite/sprite.cc + app/zelda3/sprite/sprite_builder.cc app/zelda3/music/tracker.cc app/zelda3/dungeon/room.cc app/zelda3/dungeon/room_object.cc diff --git a/src/app/zelda3/sprite/sprite_builder.cc b/src/app/zelda3/sprite/sprite_builder.cc new file mode 100644 index 00000000..ea9c370b --- /dev/null +++ b/src/app/zelda3/sprite/sprite_builder.cc @@ -0,0 +1,65 @@ +#include "sprite_builder.h" + +#include +#include + +namespace yaze { +namespace app { +namespace zelda3 { + +SpriteBuilder SpriteBuilder::Create(const std::string& spriteName) { + SpriteBuilder builder; + + return builder; +} + +SpriteBuilder& SpriteBuilder::SetProperty(const std::string& propertyName, + const std::string& value) { + return *this; +} + +SpriteBuilder& SpriteBuilder::SetProperty(const std::string& propertyName, + int value) { + return *this; +} + +SpriteBuilder& SpriteBuilder::SetProperty(const std::string& propertyName, + bool value) { + return *this; +} + +SpriteBuilder& SpriteBuilder::AddAction(const SpriteAction& action) { + return *this; +} + +SpriteBuilder& SpriteBuilder::SetGlobalAction(const SpriteAction& action) { + return *this; +} + +SpriteBuilder& SpriteBuilder::AddFunction(const SpriteAction& function) { + return *this; +} + +SpriteBuilder& SpriteBuilder::AddFunction(const std::string& asmCode) { + return *this; +} + +std::string SpriteBuilder::BuildProperties() const { + std::stringstream ss; + // Build the properties + for (int i = 0; i < 27; ++i) { + std::string property = "00"; + if (!properties[i].empty()) property = properties[i]; + ss << kSpriteProperties[i] << " = $" << property << std::endl; + } + return ss.str(); +} + +std::string SpriteBuilder::Build() const { + std::stringstream ss; + ss << BuildProperties(); + return ss.str(); +} +} // namespace zelda3 +} // namespace app +} // namespace yaze diff --git a/src/app/zelda3/sprite/sprite_builder.h b/src/app/zelda3/sprite/sprite_builder.h new file mode 100644 index 00000000..9929795b --- /dev/null +++ b/src/app/zelda3/sprite/sprite_builder.h @@ -0,0 +1,79 @@ +#ifndef YAZE_APP_ZELDA3_SPRITE_SPRITE_BUILDER_H_ +#define YAZE_APP_ZELDA3_SPRITE_SPRITE_BUILDER_H_ + +#include +#include + +namespace yaze { +namespace app { +namespace zelda3 { + + +// Array of sprite property names +constexpr const char* kSpriteProperties[] = {"!SPRID", + "!NbrTiles", + "!Harmless", + "!HVelocity", + "!Health", + "!Damage", + "!DeathAnimation", + "!ImperviousAll", + "!SmallShadow", + "!Shadow", + "!Palette", + "!Hitbox", + "!Persist", + "!Statis", + "!CollisionLayer", + "!CanFall", + "!DeflectArrow", + "!WaterSprite", + "!Blockable", + "!Prize", + "!Sound", + "!Interaction", + "!Statue", + "!DeflectProjectiles", + "!ImperviousArrow", + "!ImpervSwordHammer", + "!Boss"}; + +class SpriteBuilder { + public: + // Factory method to create a new sprite + static SpriteBuilder Create(const std::string& spriteName); + + // Set sprite properties + SpriteBuilder& SetProperty(const std::string& propertyName, + const std::string& value); + SpriteBuilder& SetProperty(const std::string& propertyName, int value); + SpriteBuilder& SetProperty(const std::string& propertyName, bool value); + + // Add an action to the sprite + SpriteBuilder& AddAction(const SpriteAction& action); + + // Set global action to the sprite (always runs) + SpriteBuilder& SetGlobalAction(const SpriteAction& action); + + // Add a function to be called from anywhere in the sprite code + SpriteBuilder& AddFunction(const std::string& asmCode); + SpriteBuilder& AddFunction(const SpriteAction& action); + + std::string BuildProperties() const; + + // Build and get the sprite configuration + std::string Build() const; + + private: + std::string name; + std::array properties; + std::vector actions; + SpriteAction globalAction; + std::vector functions; +}; + +} // namespace zelda3 +} // namespace app +} // namespace yaze + +#endif // YAZE_APP_ZELDA3_SPRITE_SPRITE_BUILDER_H_ \ No newline at end of file