Norbert's Game Engine v200
Loading...
Searching...
No Matches
ePackage Class Reference

#include <Package.hpp>

Inheritance diagram for ePackage:
eBase

Public Member Functions

void Initialize (eString path, eString name, eString extension)
 
void Release ()
 
eMap< eAsset > & GetCollection ()
 
eAsset & GetAsset (eString name)
 
bool FindAsset (eString name)
 
void Load ()
 
void LoadAsset (eString name)
 
void ReleaseAsset (eString name)
 
void InsertAsset (eString originalFilePath, eString destName, eString infoFileContent, eString assetType)
 
void RemoveAsset (eString name)
 
eString & GetName ()
 
- Public Member Functions inherited from eBase
template<typename T >
T * Cast (eBase *obj)
 Cast class to base.
 

Static Public Member Functions

static void AddFnc (eString assetType, eAssetFncs &func)
 
static void ClearAllFnc ()
 

Detailed Description

Package class for loading and managing assets

Definition at line 26 of file Package.hpp.

Member Function Documentation

◆ AddFnc()

void ePackage::AddFnc ( eString assetType,
eAssetFncs & func )
static

Definition at line 163 of file Package.cpp.

164{
165 mFncs[assetType.GetStrg()] = func;
166}
const strg & GetStrg() const
Return text as std::string.
Definition String.cpp:70

◆ ClearAllFnc()

void ePackage::ClearAllFnc ( )
static

Definition at line 168 of file Package.cpp.

169{
170 mFncs.clear();
171}

◆ FindAsset()

bool ePackage::FindAsset ( eString name)

Definition at line 200 of file Package.cpp.

201{
202 return mAssets.Find(name);
203}
bool Find(eString name)
Returns true if item with such a name exists!
Definition Map.hpp:129

◆ GetAsset()

eAsset & ePackage::GetAsset ( eString name)

Definition at line 52 of file Package.cpp.

53{
54 return mAssets.Get(name);
55}
T & Get(eString id)
Returns item from collection.
Definition Map.hpp:71

◆ GetCollection()

eMap< eAsset > & ePackage::GetCollection ( )

Definition at line 47 of file Package.cpp.

48{
49 return mAssets;
50}

◆ GetName()

eString & ePackage::GetName ( )

Definition at line 195 of file Package.cpp.

196{
197 return mName;
198}

◆ Initialize()

void ePackage::Initialize ( eString path,
eString name,
eString extension )

Definition at line 11 of file Package.cpp.

12{
13 mPath = path;
14 mName = name;
15 mExt = "." + extension.GetStrg();
16
17 strg tolDir = strg(mPath.GetStrg() + mName.GetStrg() + mExt.GetStrg());
18 if (!EDR::FileExists(tolDir.c_str()))
19 {
20 EDR::Archive* archive = EDR::CreateArchive(tolDir.c_str());
21 strg infFile = "<" + name.GetStrg() + ">\n";
22 infFile += "</" + name.GetStrg() + ">\n";
23 EDR::AddFileToArchive(archive, "info.rd", infFile.c_str());
24 archive = EDR::CloseArchive(archive);
25 }
26 mTotPath = tolDir;
27}
void AddFileToArchive(Archive *z, const char *filename, const char *content)
Adds file to archive.
Definition EDR.cpp:490
Archive * CreateArchive(const char *directory)
Creates ZIP archive.
Definition EDR.cpp:476
Archive * CloseArchive(Archive *z)
Closes archive. Changes to archive only take effect once this is called. Memory of written files must...
Definition EDR.cpp:604

◆ InsertAsset()

void ePackage::InsertAsset ( eString originalFilePath,
eString destName,
eString infoFileContent,
eString assetType )

Definition at line 115 of file Package.cpp.

116{
117 EDR::Archive* archive = EDR::OpenArchive(mTotPath.Get());
118
119 strg newName = destName.GetStrg() + ".src";
120 EDR::CopyFileToArchive(archive, newName.c_str(), originalFilePath.Get());
121
122 eString assType = assetType;
123 assType.Replace(' ', '|');
124
125 strg infoCont = "type=" + assType.GetStrg() + "\n";
126 infoCont += infoFileContent.GetStrg();
127
128 EDR::AddFileToArchive(archive, strg(destName.GetStrg() + ".rd").c_str(), infoCont.c_str());
129
130 strg out_inf = "<" + mName.GetStrg() + ">\n";
131 for(auto& it : mAssets.Geta())
132 out_inf += "<" + it.first.GetStrg() + ">\n";
133 out_inf += "<" + destName.GetStrg() + ">\n";
134 out_inf += "</" + mName.GetStrg() + ">\n";
135 EDR::RemoveFileFromArchive(archive, "info.rd");
136 EDR::AddFileToArchive(archive, "info.rd", out_inf.c_str());
137
138 archive = EDR::CloseArchive(archive);
139 LoadAsset(destName);
140}
std::vector< std::pair< eString, T > > & Geta()
Returns collection.
Definition Map.hpp:96
void Replace(char th, char withMe)
Replaces a character with another one.
Definition String.cpp:132
const char * Get()
Return text as c-string.
Definition String.cpp:64
Archive * OpenArchive(const char *directory)
Open ZIP archive.
Definition EDR.cpp:462
void CopyFileToArchive(Archive *z, const char *filename, const char *filepath)
Copies existing file to archive.
Definition EDR.cpp:512
void RemoveFileFromArchive(Archive *z, const char *filename)
Removes a file from the archive.
Definition EDR.cpp:519

◆ Load()

void ePackage::Load ( )

Definition at line 57 of file Package.cpp.

58{
59 EDR::Archive* archive = EDR::OpenArchive(mTotPath.Get());
60
61 if (archive == nullptr)
62 {
63 eConsole::PrintLog("WARNING::ePackage::Load", "Package '" + mName.GetStrg() + "' could not be found!");
65 return;
66 }
67
68 strg info = EDR::CopyArchiveFileContents(archive, "info.rd");
69 int amount = EDR::GroupItemAmountI(info, mName.GetStrg());
70
71 for (int i = 0; i < amount; i++)
72 {
73 strg group = EDR::GroupItemNameI(info, mName.GetStrg(), i);
74 LoadAsset(archive, group);
75 }
76 archive = EDR::CloseArchive(archive);
77}
static void WriteToDisk()
Write the console text to a crash file called 'CRASH.log'.
Definition Console.cpp:40
static void PrintLog(eString head, eString msg)
Print a log.
Definition Console.cpp:22
uint GroupItemAmountI(strg file, strg group, const bool binary=false)
From memory.
Definition EDR.cpp:1005
strg GroupItemNameI(strg file, strg group, uint place, const bool binary=false)
From memory.
Definition EDR.cpp:1069
void CopyArchiveFileContents(Archive *z, const char *name, const char *newPath, const bool isBinary=false)
Copies archive file contents.
Definition EDR.cpp:557

◆ LoadAsset()

void ePackage::LoadAsset ( eString name)

Definition at line 79 of file Package.cpp.

80{
81 EDR::Archive* archive = EDR::OpenArchive(mTotPath.Get());
82 NGE_ASSERT(archive != nullptr);
83 LoadAsset(archive, name.GetStrg());
84 archive = EDR::CloseArchive(archive);
85}

◆ Release()

void ePackage::Release ( )

Definition at line 29 of file Package.cpp.

30{
31 for (auto& it : mAssets.Geta())
32 {
33 for (auto& it2 : mFncs)
34 {
35 if (it.second.mType.Compare(it2.first))
36 {
37 it2.second.mDeconstr(it.second.mValue);
38 it.first.Clear();
39 it.second.mType.Clear();
40 }
41 }
42 }
43 mAssets.Popa();
44 mPath.Clear();
45}
void Popa()
Clear the collection.
Definition Map.hpp:65
void Clear()
Clear text.
Definition String.cpp:58

◆ ReleaseAsset()

void ePackage::ReleaseAsset ( eString name)

Definition at line 87 of file Package.cpp.

88{
89 bool isValid = false;
90 for (uint i = 0; i < mAssets.Size(); i++)
91 {
92 auto& asset = mAssets[i];
93 eString& assName = mAssets.IdAt(i);
94
95 if (!assName.Compare(name))
96 continue;
97
98 for (auto& it : mFncs)
99 {
100 if (asset.mType.Compare(it.first))
101 {
102 it.second.mDeconstr(asset.mValue);
103 asset.mType.Clear();
104 isValid = true;
105 break;
106 }
107 }
108 if (isValid) break;
109 }
110
111 if (isValid)
112 mAssets.Pop(name);
113}
uint64 Size()
Returns collection size.
Definition Map.hpp:112
void Pop(eString id)
Pop an item from the collection.
Definition Map.hpp:39
eString & IdAt(uint i)
Returns item name from number index.
Definition Map.hpp:118
bool Compare(eString s1)
Compare to string.
Definition String.cpp:76

◆ RemoveAsset()

void ePackage::RemoveAsset ( eString name)

Definition at line 142 of file Package.cpp.

143{
144 ReleaseAsset(name);
145 EDR::Archive* archive = EDR::OpenArchive(mTotPath.Get());
146
147 strg infFile = name.GetStrg() + ".rd";
148 EDR::RemoveFileFromArchive(archive, infFile.c_str());
149
150 strg srcFile = name.GetStrg() + ".src";
151 EDR::RemoveFileFromArchive(archive, srcFile.c_str());
152
153 strg out_inf = "<" + mName.GetStrg() + ">\n";
154 for (uint i = 0; i < mAssets.Size(); i++)
155 out_inf += "<" + mAssets.IdAt(i).GetStrg() + ">\n";
156 out_inf += "</" + mName.GetStrg() + ">\n";
157 EDR::RemoveFileFromArchive(archive, "info.rd");
158 EDR::AddFileToArchive(archive, "info.rd", out_inf.c_str());
159
160 archive = EDR::CloseArchive(archive);
161}

The documentation for this class was generated from the following files: