1#ifndef YAZE_APP_EDITOR_SPRITE_ZSPRITE_H
2#define YAZE_APP_EDITOR_SPRITE_ZSPRITE_H
9#include "absl/status/status.h"
20 OamTile(uint8_t
x, uint8_t
y,
bool mx,
bool my, uint16_t
id, uint8_t pal,
74 absl::Status
Load(
const std::string& filename) {
75 std::ifstream fs(filename, std::ios::binary);
77 return absl::NotFoundError(
"File not found");
80 std::vector<char> buffer(std::istreambuf_iterator<char>(fs), {});
82 int animation_count = *
reinterpret_cast<int32_t*
>(&buffer[0]);
83 int offset =
sizeof(int);
85 for (
int i = 0; i < animation_count; i++) {
86 std::string aname = std::string(&buffer[offset]);
87 offset += aname.size() + 1;
88 uint8_t afs = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
89 offset +=
sizeof(uint8_t);
90 uint8_t afe = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
91 offset +=
sizeof(uint8_t);
92 uint8_t afspeed = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
93 offset +=
sizeof(uint8_t);
99 int frame_count = *
reinterpret_cast<int32_t*
>(&buffer[offset]);
100 offset +=
sizeof(int);
101 for (
int i = 0; i < frame_count; i++) {
103 editor.Frames.emplace_back();
105 int tCount = *
reinterpret_cast<int*
>(&buffer[offset]);
106 offset +=
sizeof(int);
108 for (
int j = 0; j < tCount; j++) {
109 uint16_t tid = *
reinterpret_cast<uint16_t*
>(&buffer[offset]);
110 offset +=
sizeof(uint16_t);
111 uint8_t tpal = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
112 offset +=
sizeof(uint8_t);
113 bool tmx = *
reinterpret_cast<bool*
>(&buffer[offset]);
114 offset +=
sizeof(bool);
115 bool tmy = *
reinterpret_cast<bool*
>(&buffer[offset]);
116 offset +=
sizeof(bool);
117 uint8_t tprior = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
118 offset +=
sizeof(uint8_t);
119 bool tsize = *
reinterpret_cast<bool*
>(&buffer[offset]);
120 offset +=
sizeof(bool);
121 uint8_t tx = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
122 offset +=
sizeof(uint8_t);
123 uint8_t ty = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
124 offset +=
sizeof(uint8_t);
125 uint8_t tz = *
reinterpret_cast<uint8_t*
>(&buffer[offset]);
126 offset +=
sizeof(uint8_t);
127 OamTile to(tx, ty, tmx, tmy, tid, tpal, tsize, tprior);
129 editor.Frames[i].Tiles.push_back(to);
135 offset +=
sizeof(bool);
137 offset +=
sizeof(bool);
139 *
reinterpret_cast<bool*
>(&buffer[offset]);
140 offset +=
sizeof(bool);
142 offset +=
sizeof(bool);
144 offset +=
sizeof(bool);
146 *
reinterpret_cast<bool*
>(&buffer[offset]);
147 offset +=
sizeof(bool);
149 *
reinterpret_cast<bool*
>(&buffer[offset]);
150 offset +=
sizeof(bool);
151 property_fast.IsChecked = *
reinterpret_cast<bool*
>(&buffer[offset]);
152 offset +=
sizeof(bool);
154 offset +=
sizeof(bool);
156 offset +=
sizeof(bool);
158 *
reinterpret_cast<bool*
>(&buffer[offset]);
159 offset +=
sizeof(bool);
161 *
reinterpret_cast<bool*
>(&buffer[offset]);
162 offset +=
sizeof(bool);
164 offset +=
sizeof(bool);
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);
181 std::to_string(*
reinterpret_cast<uint8_t*
>(&buffer[offset]));
182 offset +=
sizeof(uint8_t);
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 if (offset != buffer.size()) {
203 int actionL = buffer[offset];
204 offset +=
sizeof(int);
205 for (
int i = 0; i < actionL; i++) {
206 std::string a = std::string(&buffer[offset]);
207 offset += a.size() + 1;
208 std::string b = std::string(&buffer[offset]);
209 offset += b.size() + 1;
214 if (offset != buffer.size()) {
223 return absl::OkStatus();
226 absl::Status
Save(
const std::string& filename) {
227 std::ofstream fs(filename, std::ios::binary);
230 fs.write(
reinterpret_cast<const char*
>(
animations.size()),
sizeof(
int));
232 fs.write(anim.frame_name.c_str(), anim.frame_name.size() + 1);
233 fs.write(
reinterpret_cast<const char*
>(&anim.frame_start),
235 fs.write(
reinterpret_cast<const char*
>(&anim.frame_end),
237 fs.write(
reinterpret_cast<const char*
>(&anim.frame_speed),
241 fs.write(
reinterpret_cast<const char*
>(
editor.Frames.size()),
243 for (
int i = 0; i <
editor.Frames.size(); i++) {
244 fs.write(
reinterpret_cast<const char*
>(
editor.Frames[i].Tiles.size()),
247 for (
int j = 0; j <
editor.Frames[i].Tiles.size(); j++) {
248 fs.write(
reinterpret_cast<const char*
>(&
editor.Frames[i].Tiles[j].id),
251 reinterpret_cast<const char*
>(&
editor.Frames[i].Tiles[j].palette),
253 fs.write(
reinterpret_cast<const char*
>(
254 &
editor.Frames[i].Tiles[j].mirror_x),
256 fs.write(
reinterpret_cast<const char*
>(
257 &
editor.Frames[i].Tiles[j].mirror_y),
259 fs.write(
reinterpret_cast<const char*
>(
260 &
editor.Frames[i].Tiles[j].priority),
263 reinterpret_cast<const char*
>(&
editor.Frames[i].Tiles[j].size),
265 fs.write(
reinterpret_cast<const char*
>(&
editor.Frames[i].Tiles[j].x),
267 fs.write(
reinterpret_cast<const char*
>(&
editor.Frames[i].Tiles[j].y),
269 fs.write(
reinterpret_cast<const char*
>(&
editor.Frames[i].Tiles[j].z),
291 fs.write(
reinterpret_cast<const char*
>(&
property_fast.IsChecked),
335 fs.write(
reinterpret_cast<const char*
>(
userRoutines.size()),
sizeof(
int));
337 fs.write(userR.name.c_str(), userR.name.size() + 1);
338 fs.write(userR.code.c_str(), userR.code.size() + 1);
347 return absl::OkStatus();
Namespace for the ZSprite format from Zarby's ZSpriteMaker.
Editors are the view controllers for the application.
Main namespace for the application.
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_persist
absl::Status Save(const std::string &filename)
SpriteProperty property_hitbox
SpriteProperty property_isboss
SpriteProperty property_impervious
SpriteProperty property_collisionlayer
SpriteProperty property_prize
SpriteProperty property_imperviousarrow
SpriteProperty property_smallshadow
SpriteProperty property_blockable
SpriteProperty property_shadow
absl::Status Load(const std::string &filename)
SpriteProperty property_deflectarrows
SpriteProperty property_customdeath
SpriteProperty property_imperviousmelee
SpriteProperty property_fast
SpriteProperty property_oamnbr
SpriteProperty property_interaction
SpriteProperty property_watersprite
SpriteProperty property_statue
SpriteProperty property_sprname
SpriteProperty property_damagesound
SpriteProperty property_damage
std::vector< AnimationGroup > animations
SpriteProperty property_palette
SpriteProperty property_harmless
SpriteProperty property_health
SpriteProperty property_canfall
SpriteProperty property_statis
SpriteProperty property_deflectprojectiles
SpriteProperty property_sprid