add SpriteBuilder class

This commit is contained in:
scawful
2024-08-07 16:03:39 -04:00
parent 86f3a119c4
commit e6316d31a4
3 changed files with 145 additions and 0 deletions

View File

@@ -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

View File

@@ -0,0 +1,65 @@
#include "sprite_builder.h"
#include <sstream>
#include <string>
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

View File

@@ -0,0 +1,79 @@
#ifndef YAZE_APP_ZELDA3_SPRITE_SPRITE_BUILDER_H_
#define YAZE_APP_ZELDA3_SPRITE_SPRITE_BUILDER_H_
#include <string>
#include <vector>
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<std::string, 27> properties;
std::vector<SpriteAction> actions;
SpriteAction globalAction;
std::vector<SpriteAction> functions;
};
} // namespace zelda3
} // namespace app
} // namespace yaze
#endif // YAZE_APP_ZELDA3_SPRITE_SPRITE_BUILDER_H_