13 #include "lcf/rpg/eventcommand.h"
19 static void ReadLcf(rpg::EventCommand& ref, LcfReader& stream, uint32_t length);
20 static void WriteLcf(
const rpg::EventCommand& ref, LcfWriter& stream);
21 static int LcfSize(
const rpg::EventCommand& ref, LcfWriter& stream);
22 static void WriteXml(
const rpg::EventCommand& ref, XmlWriter& stream);
23 static void BeginXml(rpg::EventCommand& ref, XmlReader& stream);
28 static void ReadLcf(std::vector<rpg::EventCommand>& ref, LcfReader& stream, uint32_t length);
29 static void WriteLcf(
const std::vector<rpg::EventCommand>& ref, LcfWriter& stream);
30 static int LcfSize(
const std::vector<rpg::EventCommand>& ref, LcfWriter& stream);
31 static void WriteXml(
const std::vector<rpg::EventCommand>& ref, XmlWriter& stream);
32 static void BeginXml(std::vector<rpg::EventCommand>& ref, XmlReader& stream);
39 stream.Read(event_command.code);
40 if (event_command.code != 0) {
41 stream.Read(event_command.indent);
42 stream.ReadString(event_command.string, stream.ReadInt());
44 auto& param_buf = stream.IntBuffer();
47 for (
int i = stream.ReadInt(); i > 0; i--) {
48 param_buf.push_back(stream.ReadInt());
50 if (!param_buf.empty()) {
51 event_command.parameters = DBArray<int32_t>(param_buf.begin(), param_buf.end());
57 stream.Write(event_command.code);
58 stream.Write(event_command.indent);
59 stream.WriteInt(stream.Decode(event_command.string).size());
60 stream.Write(event_command.string);
61 int32_t count = (int32_t)event_command.parameters.size();
63 for (
int i = 0; i < count; i++)
64 stream.Write(event_command.parameters[i]);
69 result += LcfReader::IntSize(event_command.code);
70 result += LcfReader::IntSize(event_command.indent);
71 result += LcfReader::IntSize(stream.Decode(event_command.string).size());
72 result += stream.Decode(event_command.string).size();
73 int count = event_command.parameters.size();
74 result += LcfReader::IntSize(count);
75 for (
int i = 0; i < count; i++)
76 result += LcfReader::IntSize(event_command.parameters[i]);
81 stream.BeginElement(
"EventCommand");
82 stream.WriteNode(
"code", event_command.code);
83 stream.WriteNode(
"indent", event_command.indent);
84 stream.WriteNode(
"string", event_command.string);
85 stream.WriteNode(
"parameters", event_command.parameters);
86 stream.EndElement(
"EventCommand");
91 rpg::EventCommand&
ref;
101 void StartElement(XmlReader& stream,
const char* name,
const char** ) {
102 if (strcmp(name,
"code") == 0)
104 else if (strcmp(name,
"indent") == 0)
106 else if (strcmp(name,
"string") == 0)
108 else if (strcmp(name,
"parameters") == 0)
111 stream.Error(
"Unrecognized field '%s'", name);
123 XmlReader::Read(
ref.code, data);
126 XmlReader::Read(
ref.indent, data);
129 XmlReader::Read(
ref.string, data);
132 XmlReader::Read(
ref.parameters, data);
146 std::vector<rpg::EventCommand>& event_commands, LcfReader& stream, uint32_t length) {
149 unsigned long startpos = stream.Tell();
150 unsigned long endpos = startpos + length;
156 uint8_t ch = (uint8_t)stream.Peek();
158 stream.Seek(4, LcfReader::FromCurrent);
162 if (stream.Tell() >= endpos) {
163 stream.Seek(endpos, LcfReader::FromStart);
164 fprintf(stderr,
"Event command corrupted at %" PRIu32
"\n", stream.Tell());
176 if (i == 4 || stream.Eof()) {
184 rpg::EventCommand command;
186 event_commands.push_back(command);
191 int count = event_commands.size();
192 for (
int i = 0; i < count; i++)
194 for (
int i = 0; i < 4; i++)
200 int count = event_commands.size();
201 for (
int i = 0; i < count; i++)
208 std::vector<rpg::EventCommand>::const_iterator it;
209 for (it = event_commands.begin(); it != event_commands.end(); it++)
217 void StartElement(XmlReader& stream,
const char* name,
const char** ) {
218 if (strcmp(name,
"EventCommand") != 0)
219 stream.Error(
"Expecting %s but got %s",
"EventCommand", name);
220 ref.resize(
ref.size() + 1);
221 rpg::EventCommand& obj =
ref.back();
225 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)
EventCommandXmlHandler(rpg::EventCommand &ref)
void EndElement(XmlReader &, const char *)
void CharacterData(XmlReader &, const std::string &data)
void StartElement(XmlReader &stream, const char *name, const char **)
enum lcf::EventCommandXmlHandler::@0 field
static void WriteXml(const T &ref, XmlWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static void WriteLcf(const T &ref, LcfWriter &stream)
static int LcfSize(const T &ref, LcfWriter &stream)