Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarWorldStructure.hpp
blob: 476400e8864f7bd5f3d41c380cae42ca24db05be (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once

#include "StarJson.hpp"
#include "StarRect.hpp"
#include "StarGameTypes.hpp"

namespace Star {

STAR_EXCEPTION(WorldStructureException, StarException);

STAR_CLASS(WorldStructure);

class WorldStructure {
public:
  struct Overlay {
    Vec2F min;
    String image;
    bool fullbright;
  };

  struct Block {
    Vec2I position;
    MaterialId materialId;
    // If the material here should not be removed on upgrade, this flag will be
    // set to true.
    bool residual;
  };

  struct Object {
    Vec2I position;
    String name;
    Direction direction;
    Json parameters;
    // If an object is not designed to be removed on upgrade, this flag will be
    // set to true.
    bool residual;
  };

  WorldStructure();
  WorldStructure(String const& configPath);
  WorldStructure(Json const& store);

  Json configValue(String const& name) const;

  List<Overlay> const& backgroundOverlays() const;
  List<Overlay> const& foregroundOverlays() const;

  List<Block> const& backgroundBlocks() const;
  List<Block> const& foregroundBlocks() const;

  List<Object> const& objects() const;

  List<Vec2I> flaggedBlocks(String const& flag) const;

  RectI region() const;
  Vec2I anchorPosition() const;

  void setAnchorPosition(Vec2I const& anchorPosition);
  void translate(Vec2I const& distance);

  Json store() const;

private:
  struct BlockKey {
    bool anchor;
    bool foregroundBlock;
    MaterialId foregroundMat;
    bool foregroundResidual;
    bool backgroundBlock;
    MaterialId backgroundMat;
    bool backgroundResidual;
    String object;
    Direction objectDirection;
    Json objectParameters;
    bool objectResidual;
    StringList flags;
  };

  RectI m_region;
  Vec2I m_anchorPosition;
  Json m_config;

  List<Overlay> m_backgroundOverlays;
  List<Overlay> m_foregroundOverlays;

  List<Block> m_backgroundBlocks;
  List<Block> m_foregroundBlocks;

  List<Object> m_objects;
  StringMap<List<Vec2I>> m_flaggedBlocks;
};

}