aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/interface/GFX.cpp
blob: 24f4b21b787ba95c0b60e14a9bcb8ad77c966366 (plain) (blame)
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
94
95
96
97
98
#include "GFX.hpp"

using namespace OpenVic;
using namespace OpenVic::GFX;
using namespace OpenVic::NodeTools;

Font::Font(std::string_view new_identifier, colour_t new_colour, std::string_view new_fontname)
   : HasIdentifierAndColour { new_identifier, new_colour, false, true }, fontname { new_fontname } {}

node_callback_t Sprite::expect_sprite(callback_t<std::unique_ptr<Sprite>&&> callback) {
   return expect_dictionary_keys(
      "spriteType", ZERO_OR_MORE, _expect_instance<Sprite, TextureSprite>(callback),
      "progressbartype", ZERO_OR_MORE, _expect_instance<Sprite, ProgressBar>(callback),
      "PieChartType", ZERO_OR_MORE, _expect_instance<Sprite, PieChart>(callback),
      "LineChartType", ZERO_OR_MORE, _expect_instance<Sprite, LineChart>(callback),
      "textSpriteType", ZERO_OR_MORE, _expect_instance<Sprite, TextureSprite>(callback),
      "maskedShieldType", ZERO_OR_MORE, _expect_instance<Sprite, MaskedFlag>(callback),
      "corneredTileSpriteType", ZERO_OR_MORE, success_callback,
      "tileSpriteType", ZERO_OR_MORE, success_callback,
      "BarChartType", ZERO_OR_MORE, success_callback,
      "scrollingSprite", ZERO_OR_MORE, success_callback
   );
}

TextureSprite::TextureSprite() : texture_file {}, no_of_frames { NO_FRAMES } {}

bool TextureSprite::_fill_key_map(key_map_t& key_map) {
   bool ret = Sprite::_fill_key_map(key_map);
   ret &= add_key_map_entries(key_map,
      "texturefile", ZERO_OR_ONE, expect_string(assign_variable_callback_string(texture_file)),
      "textureFile", ZERO_OR_ONE, expect_string(assign_variable_callback_string(texture_file)),
      "noOfFrames", ZERO_OR_ONE, expect_uint(assign_variable_callback(no_of_frames)),

      "norefcount", ZERO_OR_ONE, success_callback,
      "effectFile", ZERO_OR_ONE, success_callback,
      "allwaystransparent", ZERO_OR_ONE, success_callback,
      "transparencecheck", ZERO_OR_ONE, success_callback,
      "loadType", ZERO_OR_ONE, success_callback,
      "clicksound", ZERO_OR_ONE, success_callback
   );
   return ret;
}

ProgressBar::ProgressBar()
: back_colour {}, back_texture_file {},
  progress_colour {}, progress_texture_file {},
  size {} {}

bool ProgressBar::_fill_key_map(key_map_t& key_map) {
   bool ret = Sprite::_fill_key_map(key_map);
   ret &= add_key_map_entries(key_map,
      "color", ONE_EXACTLY, expect_colour(assign_variable_callback(back_colour)),
      "colortwo", ONE_EXACTLY, expect_colour(assign_variable_callback(progress_colour)),
      "textureFile1", ZERO_OR_ONE, expect_string(assign_variable_callback_string(back_texture_file)),
      "textureFile2", ZERO_OR_ONE, expect_string(assign_variable_callback_string(progress_texture_file)),
      "size", ONE_EXACTLY, expect_ivec2(assign_variable_callback(size)),

      "effectFile", ONE_EXACTLY, success_callback,
      "allwaystransparent", ZERO_OR_ONE, success_callback,
      "loadType", ZERO_OR_ONE, success_callback,
      "horizontal", ZERO_OR_ONE, success_callback
   );
   return ret;
}

PieChart::PieChart() : size {} {}

bool PieChart::_fill_key_map(key_map_t& key_map) {
   bool ret = Sprite::_fill_key_map(key_map);
   ret &= add_key_map_entries(key_map, "size", ONE_EXACTLY, expect_uint(assign_variable_callback(size)));
   return ret;
}

LineChart::LineChart() : size {}, linewidth {} {}

bool LineChart::_fill_key_map(key_map_t& key_map) {
   bool ret = Sprite::_fill_key_map(key_map);
   ret &= add_key_map_entries(key_map,
      "size", ONE_EXACTLY, expect_ivec2(assign_variable_callback(size)),
      "linewidth", ONE_EXACTLY, expect_uint(assign_variable_callback(linewidth)),
      "allwaystransparent", ZERO_OR_ONE, success_callback
   );
   return ret;
}

MaskedFlag::MaskedFlag() : texture_file {}, mask_file {} {}

bool MaskedFlag::_fill_key_map(key_map_t& key_map) {
   bool ret = Sprite::_fill_key_map(key_map);
   ret &= add_key_map_entries(key_map,
      "textureFile1", ONE_EXACTLY, expect_string(assign_variable_callback_string(texture_file)),
      "textureFile2", ONE_EXACTLY, expect_string(assign_variable_callback_string(mask_file)),
      "effectFile", ONE_EXACTLY, success_callback,
      "allwaystransparent", ZERO_OR_ONE, success_callback,
      "flipv", ZERO_OR_ONE, success_callback
   );
   return ret;
}