Peoplemon  0.1.0
Peoplemon 3 game source documentation
ConversationContext.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)(SymbolTable&, bl::ecs::Entity, const ConversationContext::StatusCb&,
17  Value&);
18 
19 void talkingEntity(SymbolTable& table, bl::ecs::Entity entity,
20  const ConversationContext::StatusCb& cb, Value& result);
21 void conversationOver(SymbolTable& table, bl::ecs::Entity entity,
22  const ConversationContext::StatusCb& cb, Value& result);
23 void waitConversationOver(SymbolTable& table, bl::ecs::Entity entity,
24  const ConversationContext::StatusCb& cb, Value& result);
25 
26 Value bind(bl::ecs::Entity entity, const ConversationContext::StatusCb& cb, Builtin func) {
27  return Value(
28  Function(std::bind(func, std::placeholders::_1, entity, cb, std::placeholders::_3)));
29 }
30 
31 } // namespace
32 
34  const StatusCb& cb)
35 : systems(sys)
36 , cb(cb)
37 , owner(owner) {}
38 
39 void ConversationContext::addCustomSymbols(SymbolTable& table) const {
40  BaseFunctions::addDefaults(table, systems);
41  table.set("talkingEntity", bind(owner, cb, &talkingEntity));
42  table.set("conversationOver", bind(owner, cb, &conversationOver));
43  table.set("waitConversationOver", bind(owner, cb, &waitConversationOver));
44 }
45 
46 namespace
47 {
48 void talkingEntity(SymbolTable&, bl::ecs::Entity entity, const ConversationContext::StatusCb&,
49  Value& res) {
50  res = static_cast<float>(entity);
51 }
52 
53 void conversationOver(SymbolTable&, bl::ecs::Entity entity, const ConversationContext::StatusCb& cb,
54  Value& res) {
55  res = cb(entity);
56 }
57 
58 void waitConversationOver(SymbolTable& table, bl::ecs::Entity entity,
59  const ConversationContext::StatusCb& cb, Value&) {
60  while (!cb(entity)) { table.waitFor(100); }
61 }
62 
63 } // namespace
64 
65 } // namespace script
66 } // 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.
virtual void addCustomSymbols(bl::script::SymbolTable &table) const override
std::function< bool(bl::ecs::Entity)> StatusCb
Special callback type for reporting conversation state.
ConversationContext(system::Systems &systems, bl::ecs::Entity entity, const StatusCb &cb)
Construct a new ConversationContext.
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47