2014-11-21 15:15:38 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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-08-03 17:51:40 +08:00
|
|
|
#include "cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
|
2020-08-03 17:51:40 +08:00
|
|
|
#include "cocostudio/CSParseBinary_generated.h"
|
|
|
|
#include "cocostudio/WidgetReader/NodeReader/NodeReader.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
#include "flatbuffers/flatbuffers.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace flatbuffers;
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
ProjectNodeReader::ProjectNodeReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectNodeReader::~ProjectNodeReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static ProjectNodeReader* _instanceProjectNodeReader = nullptr;
|
|
|
|
|
|
|
|
ProjectNodeReader* ProjectNodeReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!_instanceProjectNodeReader)
|
|
|
|
{
|
2015-12-16 14:02:55 +08:00
|
|
|
_instanceProjectNodeReader = new (std::nothrow) ProjectNodeReader();
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return _instanceProjectNodeReader;
|
|
|
|
}
|
|
|
|
|
2015-03-31 14:56:24 +08:00
|
|
|
void ProjectNodeReader::purge()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_instanceProjectNodeReader);
|
|
|
|
}
|
|
|
|
|
2015-03-30 16:46:33 +08:00
|
|
|
void ProjectNodeReader::destroyInstance()
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_instanceProjectNodeReader);
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
Offset<Table> ProjectNodeReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
|
2014-11-21 15:15:38 +08:00
|
|
|
flatbuffers::FlatBufferBuilder *builder)
|
|
|
|
{
|
|
|
|
auto temp = NodeReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
|
|
|
|
auto nodeOptions = *(Offset<WidgetOptions>*)(&temp);
|
|
|
|
|
2020-08-04 10:55:30 +08:00
|
|
|
std::string filename;
|
2015-03-05 15:48:17 +08:00
|
|
|
float innerspeed = 1.0f;
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_attribute objattri = objectData.first_attribute();
|
2015-03-05 15:48:17 +08:00
|
|
|
// inneraction speed
|
|
|
|
while (objattri)
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
std::string name = objattri.name();
|
|
|
|
std::string value = objattri.value();
|
2015-03-05 15:48:17 +08:00
|
|
|
if (name == "InnerActionSpeed")
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
innerspeed = atof(objattri.value());
|
2015-03-05 15:48:17 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
objattri = objattri.next_attribute();
|
2015-03-05 15:48:17 +08:00
|
|
|
}
|
2014-12-22 17:35:39 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
// FileData
|
2019-11-24 23:15:56 +08:00
|
|
|
auto child = objectData.first_child();
|
2014-11-21 15:15:38 +08:00
|
|
|
while (child)
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
std::string name = child.name();
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
if (name == "FileData")
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
auto attribute = child.first_attribute();
|
2014-11-21 15:15:38 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
while (attribute)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
name = attribute.name();
|
|
|
|
std::string value = attribute.value();
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
if (name == "Path")
|
|
|
|
{
|
2014-12-22 17:35:39 +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
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
attribute = attribute.next_attribute();
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
child = child.next_sibling();
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto options = CreateProjectNodeOptions(*builder,
|
|
|
|
nodeOptions,
|
2015-03-05 15:48:17 +08:00
|
|
|
builder->CreateString(filename),
|
|
|
|
innerspeed);
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2016-11-16 09:48:37 +08:00
|
|
|
|
|
|
|
Node* ProjectNodeReader::createNodeWithFlatBuffers(const flatbuffers::Table* /*nodeOptions*/)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|