mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 08:15:59 -10:00
The largest new feature is that it is now possible to include other files into the RML by using the "include" tag. This is useful for making markup files more modular. Also added some more options for existing things (e.g. built-in detail options).
60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
//
|
|
//
|
|
|
|
#include "IncludeNodeHandler.h"
|
|
|
|
#include "globalincs/pstypes.h"
|
|
|
|
// Our Assert conflicts with the definitions inside libRocket
|
|
#pragma push_macro("Assert")
|
|
#undef Assert
|
|
|
|
#include <Rocket/Core/Element.h>
|
|
#include <Rocket/Core/ElementDocument.h>
|
|
#include <Rocket/Core/Log.h>
|
|
#include <Rocket/Core/StreamFile.h>
|
|
#include <Rocket/Core/XMLParseTools.h>
|
|
|
|
#pragma pop_macro("Assert")
|
|
|
|
using namespace Rocket;
|
|
using namespace Rocket::Core;
|
|
|
|
namespace scpui {
|
|
|
|
Element* IncludeNodeHandler::ElementStart(XMLParser* parser, const String& name, const XMLAttributes& attributes)
|
|
{
|
|
Assertion(name == "include", "IncludeNodeHandler used with invalid tag '%s'!", name.CString());
|
|
|
|
String include_src;
|
|
if (!attributes.GetInto("src", include_src)) {
|
|
Log::ParseError(parser->GetParseFrame()->element->GetOwnerDocument()->GetSourceURL(), parser->GetLineNumber(),
|
|
"'include' requires a 'src' attribute!");
|
|
return parser->GetParseFrame()->element;
|
|
}
|
|
|
|
auto stream = new StreamFile();
|
|
|
|
if (!stream->Open(include_src)) {
|
|
Log::ParseError(parser->GetParseFrame()->element->GetOwnerDocument()->GetSourceURL(), parser->GetLineNumber(),
|
|
"Failed to open file '%s'!", include_src.CString());
|
|
stream->RemoveReference();
|
|
return parser->GetParseFrame()->element;
|
|
}
|
|
|
|
XMLParser include_parser(parser->GetParseFrame()->element);
|
|
include_parser.Parse(stream);
|
|
|
|
stream->RemoveReference();
|
|
|
|
// Tell the parser to use the element handler for all child nodes
|
|
parser->PushDefaultHandler();
|
|
|
|
return parser->GetParseFrame()->element;
|
|
}
|
|
bool IncludeNodeHandler::ElementEnd(XMLParser* /*parser*/, const String& /*name*/) { return true; }
|
|
bool IncludeNodeHandler::ElementData(XMLParser* /*parser*/, const String& /*data*/) { return true; }
|
|
void IncludeNodeHandler::Release() { delete this; }
|
|
|
|
} // namespace scpui
|