Peoplemon  0.1.0
Peoplemon 3 game source documentation
MapChangeContext.cpp
Go to the documentation of this file.
2 
5 
6 namespace core
7 {
8 namespace script
9 {
10 namespace
11 {
12 using bl::script::Function;
13 using bl::script::SymbolTable;
14 using bl::script::Value;
15 
16 typedef void (*Builtin)(const std::string&, const std::string&, std::uint16_t, Value&);
17 
18 void mapName(const std::string& prevMap, const std::string& newMap, std::uint16_t spawn,
19  Value& result);
20 void previousMap(const std::string& prevMap, const std::string& newMap, std::uint16_t spawn,
21  Value& result);
22 void spawnId(const std::string& prevMap, const std::string& newMap, std::uint16_t spawn,
23  Value& result);
24 
25 Value bind(const std::string& prevMap, const std::string& newMap, std::uint16_t spawn,
26  Builtin func) {
27  return Value(Function(std::bind(func, prevMap, newMap, spawn, std::placeholders::_3)));
28 }
29 
30 } // namespace
31 
32 MapChangeContext::MapChangeContext(system::Systems& systems, const std::string& prevMap,
33  const std::string& newMap, std::uint16_t spawn)
34 : systems(systems)
35 , prevMap(prevMap)
36 , newMap(newMap)
37 , spawn(spawn) {}
38 
39 void MapChangeContext::addCustomSymbols(SymbolTable& table) const {
40  BaseFunctions::addDefaults(table, systems);
41 
42  table.set("mapName", bind(prevMap, newMap, spawn, &mapName));
43  table.set("previousMap", bind(prevMap, newMap, spawn, &previousMap));
44  table.set("spawnId", bind(prevMap, newMap, spawn, &spawnId));
45 }
46 
47 namespace
48 {
49 void mapName(const std::string&, const std::string& newMap, std::uint16_t, Value& result) {
50  result = newMap;
51 }
52 
53 void previousMap(const std::string& prevMap, const std::string&, std::uint16_t, Value& result) {
54  result = prevMap;
55 }
56 
57 void spawnId(const std::string&, const std::string&, std::uint16_t spawn, Value& result) {
58  result = static_cast<float>(spawn);
59 }
60 
61 } // namespace
62 
63 } // namespace script
64 } // namespace core
Core classes and functionality for both the editor and game.
static void addDefaults(bl::script::SymbolTable &table, system::Systems &systems)
Adds the universal built-in functions to the given symbol table.
MapChangeContext(system::Systems &systems, const std::string &prevMap, const std::string &newMap, std::uint16_t spawn)
Construct a new Map ChangeContext.
virtual void addCustomSymbols(bl::script::SymbolTable &table) const override
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47