liblcf
Toggle main menu visibility
Loading...
Searching...
No Matches
ldb_equipment.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of liblcf. Copyright (c) liblcf authors.
3
* https://github.com/EasyRPG/liblcf - https://easyrpg.org
4
*
5
* liblcf is Free/Libre Open Source Software, released under the MIT License.
6
* For the full copyright and license information, please view the COPYING
7
* file that was distributed with this source code.
8
*/
9
10
#include "lcf/ldb/reader.h"
11
#include "lcf/ldb/chunks.h"
12
#include "
log.h
"
13
#include "
reader_struct.h
"
14
15
namespace
lcf
{
16
17
template
<>
18
struct
RawStruct
<
rpg
::Equipment> {
19
static
void
ReadLcf
(rpg::Equipment& ref, LcfReader& stream, uint32_t length);
20
static
void
WriteLcf
(
const
rpg::Equipment& ref, LcfWriter& stream);
21
static
int
LcfSize
(
const
rpg::Equipment& ref, LcfWriter& stream);
22
static
void
WriteXml
(
const
rpg::Equipment& ref, XmlWriter& stream);
23
static
void
BeginXml
(rpg::Equipment& ref, XmlReader& stream);
24
};
25
29
void
RawStruct<rpg::Equipment>::ReadLcf
(rpg::Equipment& ref, LcfReader& stream, uint32_t length) {
30
if
(length != 10) {
31
Log::Warning
(
"Equipment has incorrect size %"
PRIu32
" (expected 10)"
, length);
32
33
LcfReader::Chunk chunk_info;
34
chunk_info.ID = 0x33;
35
chunk_info.length = length;
36
37
stream.Skip(chunk_info,
"Equipment"
);
38
39
return
;
40
}
41
42
stream.Read(ref.weapon_id);
43
stream.Read(ref.shield_id);
44
stream.Read(ref.armor_id);
45
stream.Read(ref.helmet_id);
46
stream.Read(ref.accessory_id);
47
}
48
49
void
RawStruct<rpg::Equipment>::WriteLcf
(
const
rpg::Equipment& ref, LcfWriter& stream) {
50
stream.Write(ref.weapon_id);
51
stream.Write(ref.shield_id);
52
stream.Write(ref.armor_id);
53
stream.Write(ref.helmet_id);
54
stream.Write(ref.accessory_id);
55
}
56
57
int
RawStruct<rpg::Equipment>::LcfSize
(
const
rpg::Equipment&
/* ref */
, LcfWriter&
/* stream */
) {
58
return
2 * 5;
59
}
60
61
void
RawStruct<rpg::Equipment>::WriteXml
(
const
rpg::Equipment& ref, XmlWriter& stream) {
62
stream.BeginElement(
"Equipment"
);
63
stream.WriteNode<int16_t>(
"weapon_id"
, ref.weapon_id);
64
stream.WriteNode<int16_t>(
"shield_id"
, ref.shield_id);
65
stream.WriteNode<int16_t>(
"armor_id"
, ref.armor_id);
66
stream.WriteNode<int16_t>(
"helmet_id"
, ref.helmet_id);
67
stream.WriteNode<int16_t>(
"accessory_id"
, ref.accessory_id);
68
stream.EndElement(
"Equipment"
);
69
}
70
71
class
EquipmentXmlHandler
:
public
XmlHandler {
72
private
:
73
rpg::Equipment&
ref
;
74
int16_t*
field
;
75
public
:
76
EquipmentXmlHandler
(rpg::Equipment&
ref
) :
ref
(
ref
),
field
(NULL) {}
77
void
StartElement
(XmlReader&
/* stream */
,
const
char
*
name
,
const
char
**
/* atts */
) {
78
if
(strcmp(
name
,
"weapon_id"
) == 0)
79
field
= &
ref
.weapon_id;
80
else
if
(strcmp(
name
,
"shield_id"
) == 0)
81
field
= &
ref
.shield_id;
82
else
if
(strcmp(
name
,
"armor_id"
) == 0)
83
field
= &
ref
.armor_id;
84
else
if
(strcmp(
name
,
"helmet_id"
) == 0)
85
field
= &
ref
.helmet_id;
86
else
if
(strcmp(
name
,
"accessory_id"
) == 0)
87
field
= &
ref
.accessory_id;
88
else
{
89
Log::Error
(
"XML: Unrecognized field '%s'"
,
name
);
90
field
= NULL;
91
}
92
}
93
void
EndElement
(XmlReader&
/* stream */
,
const
char
*
/* name */
) {
94
field
= NULL;
95
}
96
void
CharacterData
(XmlReader&
/* stream*/
,
const
std::string& data) {
97
if
(
field
!= NULL)
98
XmlReader::Read(*
field
, data);
99
}
100
};
101
102
void
RawStruct<rpg::Equipment>::BeginXml
(rpg::Equipment& ref, XmlReader& stream) {
103
stream.SetHandler(
new
WrapperXmlHandler
(
"Equipment"
,
new
EquipmentXmlHandler
(ref)));
104
}
105
106
}
//namespace lcf
lcf::EquipmentXmlHandler
Definition
ldb_equipment.cpp:71
lcf::EquipmentXmlHandler::CharacterData
void CharacterData(XmlReader &, const std::string &data)
Definition
ldb_equipment.cpp:96
lcf::EquipmentXmlHandler::field
int16_t * field
Definition
ldb_equipment.cpp:74
lcf::EquipmentXmlHandler::EquipmentXmlHandler
EquipmentXmlHandler(rpg::Equipment &ref)
Definition
ldb_equipment.cpp:76
lcf::EquipmentXmlHandler::StartElement
void StartElement(XmlReader &, const char *name, const char **)
Definition
ldb_equipment.cpp:77
lcf::EquipmentXmlHandler::EndElement
void EndElement(XmlReader &, const char *)
Definition
ldb_equipment.cpp:93
lcf::EquipmentXmlHandler::ref
rpg::Equipment & ref
Definition
ldb_equipment.cpp:73
lcf::WrapperXmlHandler
Definition
reader_struct.h:755
log.h
lcf::Log::Warning
void Warning(const char *fmt,...) LIKE_PRINTF
Definition
log_handler.cpp:80
lcf::Log::Error
void Error(const char *fmt,...) LIKE_PRINTF
Definition
log_handler.cpp:90
lcf::rpg
Definition
rpg_actor.cpp:16
lcf
Definition
dbarray.cpp:13
lcf::name
const char *const Struct< rpg::Actor >::name
Definition
fwd_struct_impl.h:16
reader_struct.h
lcf::RawStruct
Definition
reader_struct.h:117
lcf::RawStruct::WriteXml
static void WriteXml(const T &ref, XmlWriter &stream)
lcf::RawStruct::BeginXml
static void BeginXml(T &ref, XmlReader &stream)
lcf::RawStruct::ReadLcf
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
lcf::RawStruct::WriteLcf
static void WriteLcf(const T &ref, LcfWriter &stream)
lcf::RawStruct::LcfSize
static int LcfSize(const T &ref, LcfWriter &stream)
src
ldb_equipment.cpp
Generated on
for liblcf by
1.17.0