-
Notifications
You must be signed in to change notification settings - Fork 3
/
render_site.cpp
74 lines (65 loc) · 1.72 KB
/
render_site.cpp
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
#include "weblegends.h"
#include "helpers.h"
#include "df/entity_site_link.h"
#include "df/historical_entity.h"
#include "df/world.h"
#include "df/world_data.h"
#include "df/world_site.h"
REQUIRE_GLOBAL(world);
bool WebLegends::render_site(Layout & l, int32_t id, int32_t page)
{
CoreSuspender suspend;
auto site = df::world_site::find(id);
if (site == nullptr)
{
return false;
}
simple_header(l, site);
auto & s = l.content;
df::coord2d_path coords;
for (int32_t x = site->global_min_x; x <= site->global_max_x; x++)
{
for (int32_t y = site->global_min_y; y <= site->global_max_y; y++)
{
coords.push_back(df::coord2d(uint16_t(x), uint16_t(y)));
}
}
render_map_coords(s, coords, 16);
s << "<p>";
categorize(s, site);
s << "</p>";
if (!site->entity_links.empty())
{
s << "<h2 id=\"related-entities\">Related Entities</h2><ul>";
for (auto l : site->entity_links)
{
auto entity = df::historical_entity::find(l->entity_id);
s << "<li>";
link(s, entity);
s << ",";
categorize(s, entity);
s << "</li>";
}
s << "</ul>";
}
if (!site->buildings.empty())
{
s << "<h2 id=\"structures\">Structures</h2><ul>";
for (auto b : site->buildings)
{
s << "<li>";
link(s, b);
s << ",";
categorize(s, b);
s << "</li>";
}
s << "</ul>";
}
int32_t last_page;
if (!history(s, site, page, last_page))
{
return false;
}
pagination(s, stl_sprintf("site-%d", id), "", "?page=", page, last_page);
return true;
}