summaryrefslogtreecommitdiff
path: root/include/file/world.hpp
blob: 300a3e0cb05ffee04afab3eeb6352a61c64a13f9 (plain)
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
#pragma once

#include <array>
#include <cstdint>
#include <cstdio>
#include <fcntl.h>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

#include "file/metadata.hpp"
#include "util/bitset.hpp"
#include "util/io.hpp"
#include "version.hpp"

namespace file {

class world {
	int32_t version;
	// metadata meta;

	std::vector<uint32_t> positions;
	bitset<0> importance;

	int32_t seed;
	std::array<uint8_t, 16> guid;
	int32_t worldID;
	int32_t world_left;
	int32_t world_right;
	int32_t world_top;
	int32_t world_botton;
	int32_t height;
	int32_t width;

public:
	void load_header(std::ifstream& f)
	{
	}

	world(std::string filename)
	{
		if (!std::filesystem::exists(filename)) {
			throw std::runtime_error("file not found");
		}
		auto rw = io::serialized_io(io::file_io { filename });

		rw.read(version);
		if (version <= 88 || version > terraria_version) {
			throw std::runtime_error("invalid world file version");
		}
		std::cout << version << std::endl;
		metadata meta;

		rw.read(meta);

		if (meta.ftype != filetype::World) {
			throw std::runtime_error("expected world file");
		}
	}
};

}