1#ifndef YAZE_APP_EDITOR_SPRITE_ZSPRITE_H
2#define YAZE_APP_EDITOR_SPRITE_ZSPRITE_H
11#include "absl/status/status.h"
13#include "imgui/imgui.h"
24 OamTile(uint8_t
x, uint8_t
y,
bool mx,
bool my, uint16_t
id, uint8_t pal,
78 absl::Status
Load(
const std::string& filename) {
79 std::ifstream fs(filename, std::ios::binary);
81 return absl::NotFoundError(
"File not found");
84 std::vector<char> buffer(std::istreambuf_iterator<char>(fs), {});
86 int animation_count = *
reinterpret_cast<int32_t*
>(&buffer[0]);
87 int offset =
sizeof(int);
89 for (
int i = 0; i < animation_count; i++) {
90 std::string aname = std::string(&buffer[offset]);
91 offset += aname.size() + 1;
92 uint8_t afs = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
93 offset +=
sizeof(uint8_t);
94 uint8_t afe = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
95 offset +=
sizeof(uint8_t);
96 uint8_t afspeed = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
97 offset +=
sizeof(uint8_t);
103 int frame_count = *
reinterpret_cast<int32_t*
>(&buffer[offset]);
104 offset +=
sizeof(int);
105 for (
int i = 0; i < frame_count; i++) {
109 int tCount = *
reinterpret_cast<int*
>(&buffer[offset]);
110 offset +=
sizeof(int);
112 for (
int j = 0; j < tCount; j++) {
113 ushort tid = *
reinterpret_cast<ushort*
>(&buffer[offset]);
115 uint8_t tpal = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
116 offset +=
sizeof(uint8_t);
117 bool tmx = *
reinterpret_cast<bool*
>(&buffer[offset]);
118 offset +=
sizeof(bool);
119 bool tmy = *
reinterpret_cast<bool*
>(&buffer[offset]);
120 offset +=
sizeof(bool);
121 uint8_t tprior = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
122 offset +=
sizeof(uint8_t);
123 bool tsize = *
reinterpret_cast<bool*
>(&buffer[offset]);
124 offset +=
sizeof(bool);
125 uint8_t tx = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
126 offset +=
sizeof(uint8_t);
127 uint8_t ty = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
128 offset +=
sizeof(uint8_t);
129 uint8_t tz = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
130 offset +=
sizeof(uint8_t);
131 OamTile to(tx, ty, tmx, tmy, tid, tpal, tsize, tprior);
139 offset +=
sizeof(bool);
141 offset +=
sizeof(bool);
143 *
reinterpret_cast<bool*
>(&buffer[offset]);
144 offset +=
sizeof(bool);
146 offset +=
sizeof(bool);
148 offset +=
sizeof(bool);
150 *
reinterpret_cast<bool*
>(&buffer[offset]);
151 offset +=
sizeof(bool);
153 *
reinterpret_cast<bool*
>(&buffer[offset]);
154 offset +=
sizeof(bool);
156 offset +=
sizeof(bool);
158 offset +=
sizeof(bool);
160 offset +=
sizeof(bool);
162 *
reinterpret_cast<bool*
>(&buffer[offset]);
163 offset +=
sizeof(bool);
165 *
reinterpret_cast<bool*
>(&buffer[offset]);
166 offset +=
sizeof(bool);
168 offset +=
sizeof(bool);
170 offset +=
sizeof(bool);
172 offset +=
sizeof(bool);
174 offset +=
sizeof(bool);
176 offset +=
sizeof(bool);
178 offset +=
sizeof(bool);
180 offset +=
sizeof(bool);
182 offset +=
sizeof(bool);
185 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
186 offset +=
sizeof(uint8_t);
188 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
189 offset +=
sizeof(uint8_t);
191 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
192 offset +=
sizeof(uint8_t);
194 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
195 offset +=
sizeof(uint8_t);
197 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
198 offset +=
sizeof(uint8_t);
200 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
201 offset +=
sizeof(uint8_t);
203 if (offset != buffer.size()) {
207 int actionL = buffer[offset];
208 offset +=
sizeof(int);
209 for (
int i = 0; i < actionL; i++) {
210 std::string a = std::string(&buffer[offset]);
211 offset += a.size() + 1;
212 std::string b = std::string(&buffer[offset]);
213 offset += b.size() + 1;
218 if (offset != buffer.size()) {
227 return absl::OkStatus();
230 absl::Status
Save(
const std::string& filename) {
231 std::ofstream fs(filename, std::ios::binary);
234 fs.write(
reinterpret_cast<const char*
>(
animations.size()),
sizeof(
int));
236 fs.write(anim.frame_name.c_str(), anim.frame_name.size() + 1);
237 fs.write(
reinterpret_cast<const char*
>(&anim.frame_start),
239 fs.write(
reinterpret_cast<const char*
>(&anim.frame_end),
241 fs.write(
reinterpret_cast<const char*
>(&anim.frame_speed),
245 fs.write(
reinterpret_cast<const char*
>(
editor.
Frames.size()),
248 fs.write(
reinterpret_cast<const char*
>(
editor.
Frames[i].Tiles.size()),
251 for (
int j = 0; j <
editor.
Frames[i].Tiles.size(); j++) {
252 fs.write(
reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].id),
255 reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].palette),
257 fs.write(
reinterpret_cast<const char*
>(
260 fs.write(
reinterpret_cast<const char*
>(
263 fs.write(
reinterpret_cast<const char*
>(
267 reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].size),
269 fs.write(
reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].x),
271 fs.write(
reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].y),
273 fs.write(
reinterpret_cast<const char*
>(&
editor.
Frames[i].Tiles[j].z),
339 fs.write(
reinterpret_cast<const char*
>(
userRoutines.size()),
sizeof(
int));
341 fs.write(userR.name.c_str(), userR.name.size() + 1);
342 fs.write(userR.code.c_str(), userR.code.size() + 1);
351 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