14#include "lcf/rpg/eventcommand.h"
20 static void ReadLcf(rpg::EventCommand& ref, LcfReader& stream, uint32_t length);
21 static void WriteLcf(
const rpg::EventCommand& ref, LcfWriter& stream);
22 static int LcfSize(
const rpg::EventCommand& ref, LcfWriter& stream);
23 static void WriteXml(
const rpg::EventCommand& ref, XmlWriter& stream);
24 static void BeginXml(rpg::EventCommand& ref, XmlReader& stream);
29 static void ReadLcf(std::vector<rpg::EventCommand>& ref, LcfReader& stream, uint32_t length);
30 static void WriteLcf(
const std::vector<rpg::EventCommand>& ref, LcfWriter& stream);
31 static int LcfSize(
const std::vector<rpg::EventCommand>& ref, LcfWriter& stream);
32 static void WriteXml(
const std::vector<rpg::EventCommand>& ref, XmlWriter& stream);
33 static void BeginXml(std::vector<rpg::EventCommand>& ref, XmlReader& stream);
40 stream.Read(event_command.code);
41 if (event_command.code != 0) {
42 stream.Read(event_command.indent);
43 stream.ReadString(event_command.string, stream.ReadInt());
45 auto& param_buf = stream.IntBuffer();
48 for (
int i = stream.ReadInt(); i > 0; i--) {
49 param_buf.push_back(stream.ReadInt());
51 if (!param_buf.empty()) {
52 event_command.parameters = DBArray<int32_t>(param_buf.begin(), param_buf.end());
58 stream.Write(event_command.code);
59 stream.Write(event_command.indent);
60 stream.WriteInt(stream.Decode(event_command.string).size());
61 stream.Write(event_command.string);
62 int32_t count = (int32_t)event_command.parameters.size();
64 for (
int i = 0; i < count; i++)
65 stream.Write(event_command.parameters[i]);
70 result += LcfReader::IntSize(event_command.code);
71 result += LcfReader::IntSize(event_command.indent);
72 result += LcfReader::IntSize(stream.Decode(event_command.string).size());
73 result += stream.Decode(event_command.string).size();
74 int count = event_command.parameters.size();
75 result += LcfReader::IntSize(count);
76 for (
int i = 0; i < count; i++)
77 result += LcfReader::IntSize(event_command.parameters[i]);
82 stream.BeginElement(
"EventCommand");
83 stream.WriteNode(
"code", event_command.code);
84 stream.WriteNode(
"indent", event_command.indent);
85 stream.WriteNode(
"string", event_command.string);
86 stream.WriteNode(
"parameters", event_command.parameters);
87 stream.EndElement(
"EventCommand");
92 rpg::EventCommand&
ref;
103 if (strcmp(name,
"code") == 0)
105 else if (strcmp(name,
"indent") == 0)
107 else if (strcmp(name,
"string") == 0)
109 else if (strcmp(name,
"parameters") == 0)
112 Log::Error(
"XML: Unrecognized field '%s'", name);
124 XmlReader::Read(
ref.code, data);
127 XmlReader::Read(
ref.indent, data);
130 XmlReader::Read(
ref.string, data);
133 XmlReader::Read(
ref.parameters, data);
147 std::vector<rpg::EventCommand>& event_commands, LcfReader& stream, uint32_t length) {
150 unsigned long startpos = stream.Tell();
151 unsigned long endpos = startpos + length;
157 uint8_t ch = (uint8_t)stream.Peek();
159 stream.Seek(4, LcfReader::FromCurrent);
163 if (stream.Tell() >= endpos) {
164 stream.Seek(endpos, LcfReader::FromStart);
165 Log::Warning(
"Event command corrupted at %" PRIu32
"", stream.Tell());
177 if (i == 4 || stream.Eof()) {
185 rpg::EventCommand command;
187 event_commands.push_back(command);
192 int count = event_commands.size();
193 for (
int i = 0; i < count; i++)
195 for (
int i = 0; i < 4; i++)
201 int count = event_commands.size();
202 for (
int i = 0; i < count; i++)
209 std::vector<rpg::EventCommand>::const_iterator it;
210 for (it = event_commands.begin(); it != event_commands.end(); it++)
218 void StartElement(XmlReader& stream,
const char* name,
const char** ) {
219 if (strcmp(name,
"EventCommand") != 0)
220 Log::Error(
"XML: Expecting %s but got %s",
"EventCommand", name);
221 ref.resize(
ref.size() + 1);
222 rpg::EventCommand& obj =
ref.back();
226 std::vector<rpg::EventCommand>&
ref;
std::vector< rpg::EventCommand > & ref
void StartElement(XmlReader &stream, const char *name, const char **)
EventCommandVectorXmlHandler(std::vector< rpg::EventCommand > &ref)
void StartElement(XmlReader &, const char *name, const char **)
EventCommandXmlHandler(rpg::EventCommand &ref)
void EndElement(XmlReader &, const char *)
void CharacterData(XmlReader &, const std::string &data)
enum lcf::EventCommandXmlHandler::@0 field
void Warning(const char *fmt,...) LIKE_PRINTF
void Error(const char *fmt,...) LIKE_PRINTF
static void ReadLcf(rpg::EventCommand &ref, LcfReader &stream, uint32_t length)
static void ReadLcf(std::vector< rpg::EventCommand > &ref, LcfReader &stream, uint32_t length)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static void WriteXml(const T &ref, XmlWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
static void WriteLcf(const T &ref, LcfWriter &stream)
static int LcfSize(const T &ref, LcfWriter &stream)