-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.h
More file actions
89 lines (68 loc) · 2.02 KB
/
Copy pathSprite.h
File metadata and controls
89 lines (68 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Copyright (c) 2024-2025 Toksisitee. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, refer to license.md or https://opensource.org/licenses/MIT
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.
*/
#pragma once
#include <vector>
#include "AssetTypes.h"
class CTexture2D;
class CPalette;
typedef struct IDirect3DDevice9* LPDIRECT3DDEVICE9, * PDIRECT3DDEVICE9;
extern inline void SafeDestroyTexture( CTexture2D*& pTexture );
namespace Assets
{
namespace Sprite
{
using PixelMap = std::vector<std::vector<uint8_t>>; // Must be uint8_t
struct SpriteInfo
{
uint16_t Width;
uint16_t Height;
uint32_t Offset;
};
struct Frame
{
SpriteInfo Sprite;
int8_t* Data;
PixelMap Map;
};
struct BankHeader
{
char Magic[4];
uint32_t Count;
};
struct Bank
{
BankHeader Header;
std::vector<Frame> Frames;
};
}
class CSprite
{
public:
explicit CSprite() = default;
~CSprite() = default;
Sprite::Bank m_Bank;
Result LoadBin( const std::string& file );
void ExportImg( uint16_t index );
void Map( uint16_t index );
void Reset();
void SetPalette( CPalette* pPalette ) { m_pPalette = pPalette; }
void SetHFX( bool b ) { m_bIsHFX = b; }
void CreateTextures( LPDIRECT3DDEVICE9 pD3DDevice );
[[nodiscard]] inline CTexture2D* GetTexture( uint32_t uSlot ) { return (uSlot < m_pTextures.size()) ? m_pTextures.at( uSlot ) : nullptr; }
private:
[[nodiscard]] inline bool IsAlphaSprite( uint32_t uIndex ) const { return m_bIsHFX && ((uIndex >= 1090 && uIndex <= 1499) || (uIndex >= 1538 && uIndex <= 1592)); }
[[nodiscard]] inline bool IsValid( Sprite::SpriteInfo& sprInfo ) { return sprInfo.Width > 0 && sprInfo.Height > 0; }
private:
char* m_pBuffer = nullptr;
uint32_t m_nBufferLength = 0;
bool m_bIsHFX = false;;
CPalette* m_pPalette;
std::vector<CTexture2D*> m_pTextures;
};
}