1#ifndef YAZE_APP_EDITOR_SPRITE_ZSPRITE_H
2#define YAZE_APP_EDITOR_SPRITE_ZSPRITE_H
10#include "absl/status/status.h"
12#include "imgui/imgui.h"
23 OamTile(uint8_t
x, uint8_t
y,
bool mx,
bool my, uint16_t
id, uint8_t pal,
77 absl::Status
Load(
const std::string& filename) {
78 std::ifstream fs(filename, std::ios::binary);
80 return absl::NotFoundError(
"File not found");
83 std::vector<char> buffer(std::istreambuf_iterator<char>(fs), {});
85 int animation_count = *
reinterpret_cast<int32_t*
>(&buffer[0]);
86 int offset =
sizeof(int);
88 for (
int i = 0; i < animation_count; i++) {
89 std::string aname = std::string(&buffer[offset]);
90 offset += aname.size() + 1;
91 uint8_t afs = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
92 offset +=
sizeof(uint8_t);
93 uint8_t afe = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
94 offset +=
sizeof(uint8_t);
95 uint8_t afspeed = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
96 offset +=
sizeof(uint8_t);
102 int frame_count = *
reinterpret_cast<int32_t*
>(&buffer[offset]);
103 offset +=
sizeof(int);
104 for (
int i = 0; i < frame_count; i++) {
108 int tCount = *
reinterpret_cast<int*
>(&buffer[offset]);
109 offset +=
sizeof(int);
111 for (
int j = 0; j < tCount; j++) {
112 ushort tid = *
reinterpret_cast<ushort*
>(&buffer[offset]);
114 uint8_t tpal = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
115 offset +=
sizeof(uint8_t);
116 bool tmx = *
reinterpret_cast<bool*
>(&buffer[offset]);
117 offset +=
sizeof(bool);
118 bool tmy = *
reinterpret_cast<bool*
>(&buffer[offset]);
119 offset +=
sizeof(bool);
120 uint8_t tprior = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
121 offset +=
sizeof(uint8_t);
122 bool tsize = *
reinterpret_cast<bool*
>(&buffer[offset]);
123 offset +=
sizeof(bool);
124 uint8_t tx = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
125 offset +=
sizeof(uint8_t);
126 uint8_t ty = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
127 offset +=
sizeof(uint8_t);
128 uint8_t tz = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
129 offset +=
sizeof(uint8_t);
130 OamTile to(tx, ty, tmx, tmy, tid, tpal, tsize, tprior);
138 offset +=
sizeof(bool);
140 offset +=
sizeof(bool);
142 *
reinterpret_cast<bool*
>(&buffer[offset]);
143 offset +=
sizeof(bool);
145 offset +=
sizeof(bool);
147 offset +=
sizeof(bool);
149 *
reinterpret_cast<bool*
>(&buffer[offset]);
150 offset +=
sizeof(bool);
152 *
reinterpret_cast<bool*
>(&buffer[offset]);
153 offset +=
sizeof(bool);
155 offset +=
sizeof(bool);
157 offset +=
sizeof(bool);
159 offset +=
sizeof(bool);
161 *
reinterpret_cast<bool*
>(&buffer[offset]);
162 offset +=
sizeof(bool);
164 *
reinterpret_cast<bool*
>(&buffer[offset]);
165 offset +=
sizeof(bool);
167 offset +=
sizeof(bool);
169 offset +=
sizeof(bool);
171 offset +=
sizeof(bool);
173 offset +=
sizeof(bool);
175 offset +=
sizeof(bool);
177 offset +=
sizeof(bool);
179 offset +=
sizeof(bool);
181 offset +=
sizeof(bool);
184 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
185 offset +=
sizeof(uint8_t);
187 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
188 offset +=
sizeof(uint8_t);
190 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
191 offset +=
sizeof(uint8_t);
193 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
194 offset +=
sizeof(uint8_t);
196 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
197 offset +=
sizeof(uint8_t);
199 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
200 offset +=
sizeof(uint8_t);
202 if (offset != buffer.size()) {
206 int actionL = buffer[offset];
207 offset +=
sizeof(int);
208 for (
int i = 0; i < actionL; i++) {
209 std::string a = std::string(&buffer[offset]);
210 offset += a.size() + 1;
211 std::string b = std::string(&buffer[offset]);
212 offset += b.size() + 1;
217 if (offset != buffer.size()) {
226 return absl::OkStatus();
229 absl::Status
Save(
const std::string& filename) {
230 std::ofstream fs(filename, std::ios::binary);
233 fs.write(
reinterpret_cast<const char*
>(
animations.size()),
sizeof(
int));
235 fs.write(anim.frame_name.c_str(), anim.frame_name.size() + 1);
236 fs.write(
reinterpret_cast<const char*
>(&anim.frame_start),
238 fs.write(
reinterpret_cast<const char*
>(&anim.frame_end),
240 fs.write(
reinterpret_cast<const char*
>(&anim.frame_speed),
244 fs.write(
reinterpret_cast<const char*
>(
editor.
Frames.size()),
247 fs.write(
reinterpret_cast<const char*
>(
editor.
Frames[i].Tiles.size()),
250 for (
int j = 0; j <
editor.
Frames[i].Tiles.size(); j++) {
251 fs.write(
reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].id),
254 reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].palette),
256 fs.write(
reinterpret_cast<const char*
>(
259 fs.write(
reinterpret_cast<const char*
>(
262 fs.write(
reinterpret_cast<const char*
>(
266 reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].size),
268 fs.write(
reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].x),
270 fs.write(
reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].y),
272 fs.write(
reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].z),
338 fs.write(
reinterpret_cast<const char*
>(
userRoutines.size()),
sizeof(
int));
340 fs.write(userR.name.c_str(), userR.name.size() + 1);
341 fs.write(userR.code.c_str(), userR.code.size() + 1);
350 return absl::OkStatus();
std::vector< OamTile > Tiles
AnimationGroup(uint8_t fs, uint8_t fe, uint8_t fsp, std::string fn)
OamTile(uint8_t x, uint8_t y, bool mx, bool my, uint16_t id, uint8_t pal, bool s, uint8_t p)
std::vector< AnimationGroup > Frames
std::vector< UserRoutine > user_routines
UserRoutine(std::string n, std::string c)
std::vector< UserRoutine > userRoutines
SpriteProperty property_sprname
SpriteProperty property_palette
SpriteProperty property_prize
SpriteProperty property_oamnbr
SpriteProperty property_watersprite
SpriteProperty property_imperviousmelee
SpriteProperty property_imperviousarrow
SpriteProperty property_damagesound
SpriteProperty property_harmless
SpriteProperty property_collisionlayer
SpriteProperty property_smallshadow
SpriteProperty property_damage
absl::Status Save(const std::string &filename)
SpriteProperty property_customdeath
SpriteProperty property_shadow
SpriteProperty property_interaction
SpriteProperty property_hitbox
std::vector< AnimationGroup > animations
SpriteProperty property_deflectprojectiles
SpriteProperty property_statue
SpriteProperty property_isboss
SpriteProperty property_blockable
SpriteProperty property_canfall
SpriteProperty property_fast
SpriteProperty property_statis
SpriteProperty property_health
SpriteProperty property_deflectarrows
absl::Status Load(const std::string &filename)
SpriteProperty property_persist
SpriteProperty property_impervious
SpriteProperty property_sprid