inital commit
This commit is contained in:
commit
bf96eb69ae
23 changed files with 10205 additions and 0 deletions
96
Crafter.Asset-Asset.cpp
Normal file
96
Crafter.Asset-Asset.cpp
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
module;
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
module Crafter.Asset;
|
||||
using namespace Crafter;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
||||
AssetEntry::AssetEntry() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Asset::Asset() {}
|
||||
Asset::Asset(std::vector<AssetEntry> entries): entries(entries) {}
|
||||
|
||||
struct HeaderData {
|
||||
std::uint32_t nameLenght;
|
||||
std::uint32_t typeLenght;
|
||||
std::uint32_t offset;
|
||||
std::uint32_t lenght;
|
||||
};
|
||||
|
||||
void Asset::LoadFull(fs::path path) {
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
if(!f) {
|
||||
throw std::runtime_error(std::format("File {} not found", path.generic_string()));
|
||||
}
|
||||
|
||||
std::uint32_t version;
|
||||
f.read(reinterpret_cast<char*>(&version), sizeof(std::uint32_t));
|
||||
std::uint32_t entryCount;
|
||||
f.read(reinterpret_cast<char*>(&entryCount), sizeof(std::uint32_t));
|
||||
entries.resize(entryCount);
|
||||
std::vector<std::uint32_t> lenghts(entryCount);
|
||||
for(std::uint32_t i = 0; i < entryCount; i++) {
|
||||
HeaderData header;
|
||||
f.read(reinterpret_cast<char*>(&header), sizeof(std::uint32_t)*4);
|
||||
entries[i].name.resize(header.nameLenght);
|
||||
f.read(reinterpret_cast<char*>(&entries[i].name[0]), header.nameLenght);
|
||||
entries[i].type.resize(header.typeLenght);
|
||||
f.read(reinterpret_cast<char*>(&entries[i].type[0]), header.typeLenght);
|
||||
lenghts[i] = header.lenght;
|
||||
}
|
||||
for(std::uint32_t i = 0; i < entryCount; i++) {
|
||||
entries[i].data.resize(lenghts[i]);
|
||||
f.read(reinterpret_cast<char*>(entries[i].data.data()), lenghts[i]);
|
||||
}
|
||||
}
|
||||
void Asset::LoadHeaders(fs::path path) {
|
||||
|
||||
}
|
||||
void Asset::LoadSpecific(fs::path path, std::string entry) {
|
||||
|
||||
}
|
||||
void Asset::LoadSpecific(fs::path path, std::vector<std::string> entries) {
|
||||
|
||||
}
|
||||
void Asset::LoadSpecific(fs::path path, std::uint32_t entry) {
|
||||
|
||||
}
|
||||
void Asset::LoadSpecific(fs::path path, std::vector<std::uint32_t> entries) {
|
||||
|
||||
}
|
||||
void Asset::Save(fs::path path) {
|
||||
std::ofstream f(path, std::ios::binary);
|
||||
std::uint32_t version = 0;
|
||||
f.write(reinterpret_cast<const char*>(&version), sizeof(std::uint32_t));
|
||||
std::uint32_t entriesCount = entries.size();
|
||||
f.write(reinterpret_cast<const char*>(&entriesCount), sizeof(std::uint32_t));
|
||||
std::uint32_t offset = 0;
|
||||
for(const AssetEntry& entry : entries) {
|
||||
std::uint32_t nameSize = entry.name.size();
|
||||
f.write(reinterpret_cast<const char*>(&nameSize), sizeof(std::uint32_t));
|
||||
std::uint32_t typeSize = entry.type.size();
|
||||
f.write(reinterpret_cast<const char*>(&typeSize), sizeof(std::uint32_t));
|
||||
f.write(reinterpret_cast<const char*>(&offset), sizeof(std::uint32_t));
|
||||
std::uint32_t dataSize = entry.data.size();
|
||||
f.write(reinterpret_cast<const char*>(&dataSize), sizeof(std::uint32_t));
|
||||
offset+=dataSize;
|
||||
f.write(reinterpret_cast<const char*>(&entry.name[0]), entry.name.size());
|
||||
f.write(reinterpret_cast<const char*>(&entry.type[0]), entry.type.size());
|
||||
}
|
||||
for(const AssetEntry& entry : entries) {
|
||||
f.write(reinterpret_cast<const char*>(entry.data.data()), entry.data.size());
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue