2014-11-21 15:15:38 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014 cocos2d-x.org
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "WidgetReader/ProjectNodeReader/ProjectNodeReader.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CSParseBinary_generated.h"
|
|
|
|
#include "WidgetReader/NodeReader/NodeReader.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
#include "flatbuffers/flatbuffers.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace flatbuffers;
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ProjectNodeReader::ProjectNodeReader() {}
|
|
|
|
|
|
|
|
ProjectNodeReader::~ProjectNodeReader() {}
|
|
|
|
|
|
|
|
static ProjectNodeReader* _instanceProjectNodeReader = nullptr;
|
|
|
|
|
|
|
|
ProjectNodeReader* ProjectNodeReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!_instanceProjectNodeReader)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_instanceProjectNodeReader = new ProjectNodeReader();
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
return _instanceProjectNodeReader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectNodeReader::purge()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_instanceProjectNodeReader);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectNodeReader::destroyInstance()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_instanceProjectNodeReader);
|
|
|
|
}
|
|
|
|
|
|
|
|
Offset<Table> ProjectNodeReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
|
|
|
|
flatbuffers::FlatBufferBuilder* builder)
|
|
|
|
{
|
|
|
|
auto temp = NodeReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
|
|
|
|
auto nodeOptions = *(Offset<WidgetOptions>*)(&temp);
|
|
|
|
|
|
|
|
std::string filename;
|
|
|
|
float innerspeed = 1.0f;
|
|
|
|
|
|
|
|
pugi::xml_attribute objattri = objectData.first_attribute();
|
|
|
|
// inneraction speed
|
|
|
|
while (objattri)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string name = objattri.name();
|
|
|
|
std::string value = objattri.value();
|
|
|
|
if (name == "InnerActionSpeed")
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
innerspeed = atof(objattri.value());
|
|
|
|
break;
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
objattri = objattri.next_attribute();
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
// FileData
|
|
|
|
auto child = objectData.first_child();
|
|
|
|
while (child)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string name = child.name();
|
2014-12-22 17:35:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (name == "FileData")
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto attribute = child.first_attribute();
|
|
|
|
|
|
|
|
while (attribute)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
|
|
|
std::string value = attribute.value();
|
|
|
|
|
|
|
|
if (name == "Path")
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
size_t pos = value.find_last_of('.');
|
|
|
|
std::string convert = value.substr(0, pos).append(".csb");
|
|
|
|
filename = convert;
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
child = child.next_sibling();
|
2016-11-16 09:48:37 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
auto options = CreateProjectNodeOptions(*builder, nodeOptions, builder->CreateString(filename), innerspeed);
|
|
|
|
|
|
|
|
return *(Offset<Table>*)(&options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectNodeReader::setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* projectNodeOptions)
|
|
|
|
{
|
|
|
|
auto options = (ProjectNodeOptions*)projectNodeOptions;
|
|
|
|
|
|
|
|
auto nodeReader = NodeReader::getInstance();
|
|
|
|
|
|
|
|
nodeReader->setPropsWithFlatBuffers(node, (Table*)options->nodeOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* ProjectNodeReader::createNodeWithFlatBuffers(const flatbuffers::Table* /*nodeOptions*/)
|
|
|
|
{
|
|
|
|
return nullptr;
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|