cmdfx 0.3.2
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
costumes.hpp
Go to the documentation of this file.
1
11#pragma once
12
13extern "C" {
14#include "cmdfx/core/costumes.h"
15}
16
18#include <memory>
19#include <string>
20#include <vector>
21
22namespace CmdFX
23{
24
33class SpriteCostumes final {
34 private:
35 std::unique_ptr<Sprite> sprite;
36 CmdFX_SpriteCostumes* costumes;
37
38 public:
39 SpriteCostumes(CmdFX_SpriteCostumes* costumes) : costumes(costumes) {
40 }
41 SpriteCostumes(std::unique_ptr<Sprite> sprite, int count)
42 : sprite(std::move(sprite)) {
43 costumes = Sprite_createCostumes(this->sprite->getSprite(), count);
44 }
45
46 ~SpriteCostumes() {
47 if (costumes) {
48 Sprite_freeCostumes(sprite->getSprite());
49 }
50 }
51
52 CmdFX_SpriteCostumes* getSpriteCostumes() {
53 return costumes;
54 }
55
56 int getCount() {
57 return costumes->costumeCount;
58 }
59
60 void setCostume(int index, char** text, char*** ansi) {
61 Sprite_setCostumeAt(sprite->getSprite(), index, text, ansi);
62 }
63
64 void setCostume(
65 int index, std::vector<std::string> text,
66 std::vector<std::vector<std::string>> ansi
67 ) {
68 char** textArray = to2DArray(text);
69 char*** ansiArray = to3DArray(ansi);
70
71 Sprite_setCostumeAt(sprite->getSprite(), index, textArray, ansiArray);
72 }
73};
74
75} // namespace CmdFX
Sprite Costumes API for managing sprite states.
CmdFX_SpriteCostumes * Sprite_createCostumes(CmdFX_Sprite *sprite, int costumeCount)
Creates a sprite costumes holder.
int Sprite_setCostumeAt(CmdFX_Sprite *sprite, int index, char **costume, char ***ansiCostume)
Sets a costume at the specified index.
int Sprite_freeCostumes(CmdFX_Sprite *sprite)
Frees the sprite costumes.
Primary namespace for CmdFX.
Definition cmdfx.hpp:26
char ** to2DArray(std::vector< std::string > string)
Converts a 1D vector of strings to a 2D array of characters.
Definition builder.hpp:64
char *** to3DArray(std::vector< std::vector< std::string > > string)
Converts a 2D vector of strings to a 3D array of characters.
Definition builder.hpp:80
C++ Extensions for the CmdFX Sprites API.
Represents the holder for sprite costumes.
Definition costumes.h:38
int costumeCount
Represents the number of sprite costumes.
Definition costumes.h:76