2021-08-13 14:52:58 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2009 Jason Booth
|
|
|
|
Copyright (c) 2009 Robert J Payne
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2021-08-13 14:52:58 +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:
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <string>
|
|
|
|
#include "2d/CCSpriteFrame.h"
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "base/CCValue.h"
|
|
|
|
#include "base/CCMap.h"
|
|
|
|
#include "base/CCData.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2021-08-13 14:52:58 +08:00
|
|
|
|
|
|
|
class Sprite;
|
|
|
|
class Texture2D;
|
|
|
|
class PolygonInfo;
|
|
|
|
class SpriteFrameCache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup _2d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
struct SpriteSheetFormat
|
|
|
|
{
|
|
|
|
enum : uint32_t
|
|
|
|
{
|
|
|
|
PLIST = 1,
|
2021-08-17 12:04:45 +08:00
|
|
|
CUSTOM = 1000
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-08-13 14:52:58 +08:00
|
|
|
class SpriteSheet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string path;
|
2021-08-17 12:04:45 +08:00
|
|
|
uint32_t format;
|
2021-12-26 23:26:34 +08:00
|
|
|
hlookup::string_set frames;
|
2021-08-13 14:52:58 +08:00
|
|
|
bool full = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ISpriteSheetLoader
|
|
|
|
{
|
|
|
|
public:
|
2021-12-28 11:00:34 +08:00
|
|
|
virtual ~ISpriteSheetLoader() = default;
|
|
|
|
virtual uint32_t getFormat() = 0;
|
|
|
|
virtual void load(std::string_view filePath, SpriteFrameCache& cache) = 0;
|
|
|
|
virtual void load(std::string_view filePath, Texture2D* texture, SpriteFrameCache& cache) = 0;
|
2021-12-26 23:26:34 +08:00
|
|
|
virtual void load(std::string_view filePath, std::string_view textureFileName, SpriteFrameCache& cache) = 0;
|
2021-12-28 11:00:34 +08:00
|
|
|
virtual void load(const Data& content, Texture2D* texture, SpriteFrameCache& cache) = 0;
|
|
|
|
virtual void reload(std::string_view filePath, SpriteFrameCache& cache) = 0;
|
2021-08-13 14:52:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class SpriteSheetLoader : public ISpriteSheetLoader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Configures PolygonInfo class with the passed sizes + triangles */
|
2021-10-23 23:27:14 +08:00
|
|
|
void initializePolygonInfo(const Vec2& textureSize,
|
2021-12-25 10:04:45 +08:00
|
|
|
const Vec2& spriteSize,
|
|
|
|
const std::vector<int>& vertices,
|
|
|
|
const std::vector<int>& verticesUV,
|
|
|
|
const std::vector<int>& triangleIndices,
|
|
|
|
PolygonInfo& polygonInfo);
|
|
|
|
|
2021-12-28 11:00:34 +08:00
|
|
|
uint32_t getFormat() override = 0;
|
|
|
|
void load(std::string_view filePath, SpriteFrameCache& cache) override = 0;
|
|
|
|
void load(std::string_view filePath, Texture2D* texture, SpriteFrameCache& cache) override = 0;
|
2021-12-26 23:26:34 +08:00
|
|
|
void load(std::string_view filePath, std::string_view textureFileName, SpriteFrameCache& cache) override = 0;
|
2021-12-28 11:00:34 +08:00
|
|
|
void load(const Data& content, Texture2D* texture, SpriteFrameCache& cache) override = 0;
|
|
|
|
void reload(std::string_view filePath, SpriteFrameCache& cache) override = 0;
|
2021-08-13 14:52:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// end of _2d group
|
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|