10#include "lcf/rpg/movecommand.h"
18 static void ReadLcf(rpg::MoveCommand& ref, LcfReader& stream, uint32_t length);
19 static void WriteLcf(
const rpg::MoveCommand& ref, LcfWriter& stream);
20 static int LcfSize(
const rpg::MoveCommand& ref, LcfWriter& stream);
21 static void WriteXml(
const rpg::MoveCommand& ref, XmlWriter& stream);
22 static void BeginXml(rpg::MoveCommand& ref, XmlReader& stream);
27 static void ReadLcf(std::vector<rpg::MoveCommand>& ref, LcfReader& stream, uint32_t length);
28 static void WriteLcf(
const std::vector<rpg::MoveCommand>& ref, LcfWriter& stream);
29 static int LcfSize(
const std::vector<rpg::MoveCommand>& ref, LcfWriter& stream);
30 static void WriteXml(
const std::vector<rpg::MoveCommand>& ref, XmlWriter& stream);
31 static void BeginXml(std::vector<rpg::MoveCommand>& ref, XmlReader& stream);
38 ref.command_id = stream.ReadInt();
39 const auto cmd =
static_cast<rpg::MoveCommand::Code
>(ref.command_id);
41 case rpg::MoveCommand::Code::switch_on:
42 stream.Read(ref.parameter_a);
44 case rpg::MoveCommand::Code::switch_off:
45 stream.Read(ref.parameter_a);
47 case rpg::MoveCommand::Code::change_graphic:
48 stream.ReadString(ref.parameter_string, stream.ReadInt());
49 stream.Read(ref.parameter_a);
51 case rpg::MoveCommand::Code::play_sound_effect:
52 stream.ReadString(ref.parameter_string, stream.ReadInt());
53 stream.Read(ref.parameter_a);
54 stream.Read(ref.parameter_b);
55 stream.Read(ref.parameter_c);
62 stream.WriteInt(ref.command_id);
63 const auto cmd =
static_cast<rpg::MoveCommand::Code
>(ref.command_id);
65 case rpg::MoveCommand::Code::switch_on:
66 stream.Write(ref.parameter_a);
68 case rpg::MoveCommand::Code::switch_off:
69 stream.Write(ref.parameter_a);
71 case rpg::MoveCommand::Code::change_graphic:
72 stream.WriteInt(stream.Decode(ref.parameter_string).size());
73 stream.Write(ref.parameter_string);
74 stream.Write(ref.parameter_a);
76 case rpg::MoveCommand::Code::play_sound_effect:
77 stream.WriteInt(stream.Decode(ref.parameter_string).size());
78 stream.Write(ref.parameter_string);
79 stream.Write(ref.parameter_a);
80 stream.Write(ref.parameter_b);
81 stream.Write(ref.parameter_c);
89 result += LcfReader::IntSize(ref.command_id);
90 const auto cmd =
static_cast<rpg::MoveCommand::Code
>(ref.command_id);
92 case rpg::MoveCommand::Code::switch_on:
93 result += LcfReader::IntSize(ref.parameter_a);
95 case rpg::MoveCommand::Code::switch_off:
96 result += LcfReader::IntSize(ref.parameter_a);
98 case rpg::MoveCommand::Code::change_graphic:
99 result += LcfReader::IntSize(stream.Decode(ref.parameter_string).size());
100 result += stream.Decode(ref.parameter_string).size();
101 result += LcfReader::IntSize(ref.parameter_a);
103 case rpg::MoveCommand::Code::play_sound_effect:
104 result += LcfReader::IntSize(stream.Decode(ref.parameter_string).size());
105 result += stream.Decode(ref.parameter_string).size();
106 result += LcfReader::IntSize(ref.parameter_a);
107 result += LcfReader::IntSize(ref.parameter_b);
108 result += LcfReader::IntSize(ref.parameter_c);
116 stream.BeginElement(
"MoveCommand");
117 stream.WriteNode(
"command_id", ref.command_id);
118 const auto cmd =
static_cast<rpg::MoveCommand::Code
>(ref.command_id);
120 case rpg::MoveCommand::Code::switch_on:
121 stream.WriteNode(
"parameter_a", ref.parameter_a);
123 case rpg::MoveCommand::Code::switch_off:
124 stream.WriteNode(
"parameter_a", ref.parameter_a);
126 case rpg::MoveCommand::Code::change_graphic:
127 stream.WriteNode(
"parameter_string", ref.parameter_string);
128 stream.WriteNode(
"parameter_a", ref.parameter_a);
130 case rpg::MoveCommand::Code::play_sound_effect:
131 stream.WriteNode(
"parameter_string", ref.parameter_string);
132 stream.WriteNode(
"parameter_a", ref.parameter_a);
133 stream.WriteNode(
"parameter_b", ref.parameter_b);
134 stream.WriteNode(
"parameter_c", ref.parameter_c);
138 stream.EndElement(
"MoveCommand");
149 void StartElement(XmlReader& stream,
const char* name,
const char** ) {
150 if (strcmp(name,
"command_id") == 0)
152 else if (strcmp(name,
"parameter_a") == 0)
154 else if (strcmp(name,
"parameter_b") == 0)
156 else if (strcmp(name,
"parameter_c") == 0)
158 else if (strcmp(name,
"parameter_string") == 0)
161 stream.Error(
"Unrecognized field '%s'", name);
172 XmlReader::Read(*
field, data);
174 XmlReader::Read(
ref.parameter_string, data);
186 unsigned long startpos = stream.Tell();
187 unsigned long endpos = startpos + length;
188 while (stream.Tell() != endpos) {
189 rpg::MoveCommand command;
191 ref.push_back(command);
196 std::vector<rpg::MoveCommand>::const_iterator it;
197 for (it = ref.begin(); it != ref.end(); it++)
203 std::vector<rpg::MoveCommand>::const_iterator it;
204 for (it = ref.begin(); it != ref.end(); it++)
210 std::vector<rpg::MoveCommand>::const_iterator it;
211 for (it = ref.begin(); it != ref.end(); it++)
219 void StartElement(XmlReader& stream,
const char* name,
const char** ) {
220 if (strcmp(name,
"MoveCommand") != 0)
221 stream.Error(
"Expecting %s but got %s",
"MoveCommand", name);
222 ref.resize(
ref.size() + 1);
223 rpg::MoveCommand& obj =
ref.back();
227 std::vector<rpg::MoveCommand>&
ref;
std::vector< rpg::MoveCommand > & ref
void StartElement(XmlReader &stream, const char *name, const char **)
MoveCommandVectorXmlHandler(std::vector< rpg::MoveCommand > &ref)
void CharacterData(XmlReader &, const std::string &data)
void EndElement(XmlReader &, const char *)
MoveCommandXmlHandler(rpg::MoveCommand &ref)
void StartElement(XmlReader &stream, const char *name, const char **)
static void ReadLcf(rpg::MoveCommand &ref, LcfReader &stream, uint32_t length)
static void ReadLcf(std::vector< rpg::MoveCommand > &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)