Skip to content

Commit b343821

Browse files
committed
Cleanups in display and scripting
1 parent dbbf3ce commit b343821

File tree

7 files changed

+168
-105
lines changed

7 files changed

+168
-105
lines changed

sample_game/resources/Maps/fairview.json

+20-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
{
4242
"gid":7,
4343
"height":16,
44-
"id":1,
4544
"name":"ExitSquare",
4645
"properties":
4746
{
@@ -55,9 +54,8 @@
5554
"y":96
5655
},
5756
{
58-
"gid":101,
59-
"height":26,
60-
"id":2,
57+
"gid":103,
58+
"height":24,
6159
"name":"Deborah",
6260
"properties":
6361
{
@@ -66,9 +64,9 @@
6664
"rotation":0,
6765
"type":"",
6866
"visible":true,
69-
"width":26,
70-
"x":77,
71-
"y":88
67+
"width":16,
68+
"x":96,
69+
"y":92
7270
}],
7371
"opacity":1,
7472
"type":"objectgroup",
@@ -92,7 +90,6 @@
9290
"x":0,
9391
"y":0
9492
}],
95-
"nextobjectid":3,
9693
"orientation":"orthogonal",
9794
"properties":
9895
{
@@ -152,6 +149,21 @@
152149
"spacing":0,
153150
"tileheight":26,
154151
"tilewidth":26
152+
},
153+
{
154+
"firstgid":102,
155+
"image":"..\/TileSets\/Deborah.png",
156+
"imageheight":96,
157+
"imagewidth":48,
158+
"margin":0,
159+
"name":"Deborah",
160+
"properties":
161+
{
162+
163+
},
164+
"spacing":0,
165+
"tileheight":24,
166+
"tilewidth":16
155167
}],
156168
"tilewidth":16,
157169
"version":1,

sample_game/spiced.chai

+31-52
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
dump_system();
2+
13
class Travel_To {
24
def Travel_To(string t_name, int t_cost, int t_x, int t_y, bool t_requires_offroad_tires, bool t_requires_chains) {
35
this.name = t_name;
@@ -250,30 +252,22 @@ var game_creator = fun(game) {
250252
var Joshua_conversation_tree =
251253
Conversation([
252254
Question("Hello",
253-
[Answer("Joshua", "Hi! Welcome to Glenn Haven.\nI've just opened up shop here.\nI think you'll like our prices on bread!")],
254-
fun(t_game_time, t_simulation_time, t_game, t_obj){ true },
255-
fun(t_game_time, t_simulation_time, t_game, t_obj){ }
255+
[Answer("Joshua", "Hi! Welcome to Glenn Haven.\nI've just opened up shop here.\nI think you'll like our prices on bread!")]
256256
),
257257
Question("<spread rumors about competitor>",
258258
[Answer("Joshua", "That's not a very nice thing to say...")],
259-
fun(t_game_time, t_simulation_time, t_game, t_obj){
260-
t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Joshua"); },
261-
fun(t_game_time, t_simulation_time, t_game, t_obj){
262-
t_game.set_flag("have_talked_to_Joshua", true); t_game.set_flag("have_spread_rumors", true); }
259+
fun(t_game){ t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Joshua"); },
260+
fun(t_game){ t_game.set_flag("have_talked_to_Joshua", true); t_game.set_flag("have_spread_rumors", true); }
263261
),
264262
Question("<say something nice about competitor>",
265263
[Answer("Joshua", "That's good to hear.")],
266-
fun(t_game_time, t_simulation_time, t_game, t_obj){
267-
t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Joshua"); },
268-
fun(t_game_time, t_simulation_time, t_game, t_obj){
269-
t_game.set_flag("have_talked_to_Joshua", true); t_game.set_flag("have_said_something_nice", true); }
264+
fun(t_game){ t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Joshua"); },
265+
fun(t_game){ t_game.set_flag("have_talked_to_Joshua", true); t_game.set_flag("have_said_something_nice", true); }
270266
),
271267
Question("<say nothing about competitor>",
272268
[],
273-
fun(t_game_time, t_simulation_time, t_game, t_obj){
274-
t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Joshua"); },
275-
fun(t_game_time, t_simulation_time, t_game, t_obj){
276-
t_game.set_flag("have_talked_to_Joshua", true); t_game.set_flag("did_not_respond", true); }
269+
fun(t_game){ t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Joshua"); },
270+
fun(t_game){ t_game.set_flag("have_talked_to_Joshua", true); t_game.set_flag("did_not_respond", true); }
277271
)
278272

279273

@@ -338,34 +332,31 @@ var game_creator = fun(game) {
338332
var Deborah_conversation_tree =
339333
Conversation([
340334
Question("Hello",
341-
[Answer("Deborah", "Hi! Welcome to Fairview.")],
342-
fun(t_game_time, t_simulation_time, t_game, t_obj){ true },
343-
fun(t_game_time, t_simulation_time, t_game, t_obj){ }
335+
[Answer("Deborah", "Hi! Welcome to Fairview.")]
344336
),
345337
Question("Rumors",
346338
[Answer("Deborah", "Yes, I've heard the rumors too."),
347339
Answer("Deborah", "It's an unfortunate way to do business.")],
348-
fun(t_game_time, t_simulation_time, t_game, t_obj){ t_game.get_flag("have_been_notified_of_rumors"); },
349-
fun(t_game_time, t_simulation_time, t_game, t_obj){ }
340+
fun(t_game){ t_game.get_flag("have_been_notified_of_rumors"); }
350341
),
351342
Question("What should I do?",
352343
[Answer("Deborah", "Don't retaliate. Rumor mongering is not the best way to do business.")],
353-
fun(t_game_time, t_simulation_time, t_game, t_obj){ t_game.get_flag("have_been_notified_of_rumors"); },
354-
fun(t_game_time, t_simulation_time, t_game, t_obj){ t_game.set_flag("have_talked_to_deborah_about_rumors", true); }
344+
fun(t_game){ t_game.get_flag("have_been_notified_of_rumors"); },
345+
fun(t_game){ t_game.set_flag("have_talked_to_deborah_about_rumors", true); }
355346
),
356347
Question("What now?",
357348
[Answer("Deborah", "Romans 12:19 says, 'Friends, do not avenge yourselves;\ninstead, leave room for His wrath.\nFor it is written: Vengeance belongs to Me;\nI will repay, says the Lord.'"),
358349
Answer("Deborah", "I hope you didn't decide to take matters into your own hands.\nThat rarely works out well.")],
359-
fun(t_game_time, t_simulation_time, t_game, t_obj){ did_make_all_responses(t_game); },
360-
fun(t_game_time, t_simulation_time, t_game, t_obj){ t_game.set_flag("deborah_shared_verse", true); }
350+
fun(t_game){ did_make_all_responses(t_game); },
351+
fun(t_game){ t_game.set_flag("deborah_shared_verse", true); }
361352
),
362353
Question("Note",
363354
[Answer("Deborah", "Romans 12:19 says, 'Friends, do not avenge yourselves;\ninstead, leave room for His wrath.\nFor it is written: Vengeance belongs to Me;\nI will repay, says the Lord.'"),
364355
Answer("Deborah", "This you already know."),
365356
Answer("Deborah", "Romans 12:20 goes on to say 'But If your enemy is hungry,\nfeed him. If he is thirsty, give him something to drink.\nFor in so doing\nyou will be heaping fiery coals on his head.'"),
366357
Answer("Deborah", "This is the lesson you've learned today.")],
367-
fun(t_game_time, t_simulation_time, t_game, t_obj){ t_game.get_flag("saw_note") },
368-
fun(t_game_time, t_simulation_time, t_game, t_obj){ t_game.set_flag("deborah_shared_second_verse", true); }
358+
fun(t_game){ t_game.get_flag("saw_note") },
359+
fun(t_game){ t_game.set_flag("deborah_shared_second_verse", true); }
369360
)
370361
]);
371362

@@ -416,24 +407,22 @@ var game_creator = fun(game) {
416407
Question("Rumors",
417408
[Answer("William", "You must be the new trader in town.\nYour competitor has been saying unflattering things about you."),
418409
Answer("William", "But you seem like a nice person... I'm not sure I believe them.")],
419-
fun(t_game_time, t_simulation_time, t_game, t_obj){ true },
420-
fun(t_game_time, t_simulation_time, t_game, t_obj){ t_game.set_flag("have_been_notified_of_rumors", true); }
410+
fun(t_game){ !t_game.get_flag("have_been_notified_of_rumors"); },
411+
fun(t_game){ t_game.set_flag("have_been_notified_of_rumors", true); }
421412
),
422413
Question("What should I do?",
423414
[Answer("William", "Well, if it were me, I'd start spreading rumors of my own about them!\nYou have to fight for what you get.")],
424-
fun(t_game_time, t_simulation_time, t_game, t_obj){ true },
425-
fun(t_game_time, t_simulation_time, t_game, t_obj){ }
415+
fun(t_game){ t_game.get_flag("have_been_notified_of_rumors"); }
426416
),
427417
Question("Note?",
428418
[Answer("William", "There's a note here from your competitor."),
429419
Answer("William", "It says he's sorry for starting those rumors about you,\nand promises to set things right")],
430-
fun(t_game_time, t_simulation_time, t_game, t_obj) { !t_game.get_flag("saw_note") && did_make_all_responses(t_game) && have_said_something_nice(t_game) && t_game.get_flag("deborah_shared_verse"); },
431-
fun(t_game_time, t_simulation_time, t_game, t_obj) { t_game.set_flag("saw_note", true); }
420+
fun(t_game) { !t_game.get_flag("saw_note") && did_make_all_responses(t_game) && have_said_something_nice(t_game) && t_game.get_flag("deborah_shared_verse"); },
421+
fun(t_game) { t_game.set_flag("saw_note", true); }
432422
),
433423
Question("Share bible verses you've learned.",
434424
[Answer("William", "Well that is interesting...")],
435-
fun(t_game_time, t_simulation_time, t_game, t_obj) { t_game.get_flag("deborah_shared_second_verse") },
436-
fun(t_game_time, t_simulation_time, t_game, t_obj) { }
425+
fun(t_game) { t_game.get_flag("deborah_shared_second_verse") }
437426
)
438427
]);
439428

@@ -523,35 +512,25 @@ var game_creator = fun(game) {
523512
Question("Hello",
524513
[Answer("Dana", "Hi! Welcome to the archaeological camp here."),
525514
Answer("Diane", "The two of us are scientists evaluating the finds from the dig here."),
526-
Answer("Diane", "We welcome any supplies you manage to get up here.")],
527-
fun(t_game_time, t_simulation_time, t_game, t_obj){ true; },
528-
fun(t_game_time, t_simulation_time, t_game, t_obj){ }
515+
Answer("Diane", "We welcome any supplies you manage to get up here.")]
529516
),
530517
Question("You look a lot a like",
531-
[Answer("Diane", "Yes, we are twins")],
532-
fun(t_game_time, t_simulation_time, t_game, t_obj){ true; },
533-
fun(t_game_time, t_simulation_time, t_game, t_obj){ }
518+
[Answer("Diane", "Yes, we are twins")]
534519
),
535520
Question("<spread rumors about competitor>",
536521
[Answer("Diane", "That's not a very nice thing to say...")],
537-
fun(t_game_time, t_simulation_time, t_game, t_obj){
538-
t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Diane"); },
539-
fun(t_game_time, t_simulation_time, t_game, t_obj){
540-
t_game.set_flag("have_talked_to_Diane", true); t_game.set_flag("have_spread_rumors", true); }
522+
fun(t_game){ t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Diane"); },
523+
fun(t_game){ t_game.set_flag("have_talked_to_Diane", true); t_game.set_flag("have_spread_rumors", true); }
541524
),
542525
Question("<say something nice about competitor>",
543526
[Answer("Diane", "That's good to hear.")],
544-
fun(t_game_time, t_simulation_time, t_game, t_obj){
545-
t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Diane"); },
546-
fun(t_game_time, t_simulation_time, t_game, t_obj){
547-
t_game.set_flag("have_talked_to_Diane", true); t_game.set_flag("have_said_something_nice", true); }
527+
fun(t_game){ t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Diane"); },
528+
fun(t_game){ t_game.set_flag("have_talked_to_Diane", true); t_game.set_flag("have_said_something_nice", true); }
548529
),
549530
Question("<say nothing about competitor>",
550531
[],
551-
fun(t_game_time, t_simulation_time, t_game, t_obj){
552-
t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Diane"); },
553-
fun(t_game_time, t_simulation_time, t_game, t_obj){
554-
t_game.set_flag("have_talked_to_Diane", true); t_game.set_flag("did_not_respond", true); }
532+
fun(t_game){ t_game.get_flag("have_talked_to_deborah_about_rumors") && !t_game.get_flag("have_talked_to_Diane"); },
533+
fun(t_game){ t_game.set_flag("have_talked_to_Diane", true); t_game.set_flag("did_not_respond", true); }
555534
)
556535

557536
]);

src/chaiscript_bindings.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,20 @@ namespace spiced {
6262
module->add(chaiscript::constructor<Answer(std::string, std::string)>(), "Answer");
6363

6464
module->add(chaiscript::user_type<Question>(), "Question");
65+
6566
module->add(chaiscript::constructor<
6667
Question(std::string, std::vector<Answer>,
6768
std::function<bool(const float, const float, Game &, Object &)>,
6869
std::function<void(const float, const float, Game &, Object &)>)>(), "Question");
70+
module->add(chaiscript::constructor<
71+
Question(std::string, std::vector<Answer>,
72+
std::function<bool(Game &)>,
73+
std::function<void(Game &)>)>(), "Question");
74+
module->add(chaiscript::constructor<
75+
Question(std::string, std::vector<Answer>,
76+
std::function<bool(Game &)>)>(), "Question");
77+
module->add(chaiscript::constructor<
78+
Question(std::string, std::vector<Answer>)>(), "Question");
6979

7080
module->add(chaiscript::user_type<Conversation>(), "Conversation");
7181
module->add(chaiscript::constructor<Conversation(std::vector<Question>)>(), "Conversation");
@@ -119,4 +129,4 @@ namespace spiced {
119129
return module;
120130
}
121131

122-
}
132+
}

src/game.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace spiced {
9696

9797
void Game::show_message_box(const sf::String &t_msg)
9898
{
99-
m_game_events.emplace_back(new Message_Box(t_msg, get_font("resources/FreeMonoBold.ttf"), 17, sf::Color(255, 255, 255, 255), sf::Color(0, 0, 0, 128), sf::Color(255, 255, 255, 200), 3));
99+
m_game_events.emplace_back(new Message_Box(t_msg, get_font("resources/FreeMonoBold.ttf"), 17, sf::Color(255, 255, 255, 255), sf::Color(0, 0, 0, 128), sf::Color(255, 255, 255, 200), 3, Location::Bottom));
100100
}
101101

102102
void Game::show_conversation(const float t_game_time, const float t_simulation_time, Object &t_obj, const Conversation &t_conversation)
@@ -107,10 +107,10 @@ namespace spiced {
107107
if (!q.is_available || q.is_available(t_game_time, t_simulation_time, *this, t_obj))
108108
{
109109
actions.emplace_back(q.question,
110-
[q](const float, const float, Game &t_game, Object &obj)
110+
[q, t_game_time, t_simulation_time, &t_obj, t_conversation](const float, const float, Game &t_game, Object &obj)
111111
{
112112
for (const auto &answer : q.answers) {
113-
t_game.show_message_box(answer.speaker + " says:\n\n" + answer.answer);
113+
t_game.show_message_box(answer.speaker + ":\n\n" + answer.answer);
114114
}
115115
if (q.action) {
116116
using namespace std::placeholders;
@@ -130,17 +130,17 @@ namespace spiced {
130130
}
131131

132132

133-
m_game_events.emplace_back(new Object_Interaction_Menu(t_obj, get_font("resources/FreeMonoBold.ttf"), 17, sf::Color(255, 255, 255, 255), sf::Color(0, 200, 200, 255), sf::Color(0, 0, 0, 128), sf::Color(255, 255, 255, 200), 3, actions));
133+
m_game_events.emplace_back(new Object_Interaction_Menu(t_obj, get_font("resources/FreeMonoBold.ttf"), 17, sf::Color(255, 255, 255, 255), sf::Color(0, 200, 200, 255), sf::Color(0, 0, 0, 128), sf::Color(255, 255, 255, 200), 3, actions, Location::Bottom));
134134
}
135135

136136
void Game::show_object_interaction_menu(const float t_game_time, const float t_simulation_time, Object &t_obj)
137137
{
138-
m_game_events.emplace_back(new Object_Interaction_Menu(t_obj, get_font("resources/FreeMonoBold.ttf"), 17, sf::Color(255, 255, 255, 255), sf::Color(0, 200, 200, 255), sf::Color(0, 0, 0, 128), sf::Color(255, 255, 255, 200), 3, t_obj.get_actions(t_game_time, t_simulation_time, *this)));
138+
m_game_events.emplace_back(new Object_Interaction_Menu(t_obj, get_font("resources/FreeMonoBold.ttf"), 17, sf::Color(255, 255, 255, 255), sf::Color(0, 200, 200, 255), sf::Color(0, 0, 0, 128), sf::Color(255, 255, 255, 200), 3, t_obj.get_actions(t_game_time, t_simulation_time, *this), Location::Right));
139139
}
140140

141141
void Game::show_selection_menu(const float /*t_game_time*/, const float /*t_simulation_time*/, const std::vector<Game_Action> &t_selections, const size_t t_selection)
142142
{
143-
m_game_events.emplace_back(new Selection_Menu(get_font("resources/FreeMonoBold.ttf"), 17, sf::Color(255, 255, 255, 255), sf::Color(0, 200, 200, 255), sf::Color(0, 0, 0, 128), sf::Color(255, 255, 255, 200), 3, t_selections, t_selection));
143+
m_game_events.emplace_back(new Selection_Menu(get_font("resources/FreeMonoBold.ttf"), 17, sf::Color(255, 255, 255, 255), sf::Color(0, 200, 200, 255), sf::Color(0, 0, 0, 128), sf::Color(255, 255, 255, 200), 3, t_selections, t_selection, Location::Right));
144144
}
145145

146146
bool Game::has_pending_events() const

0 commit comments

Comments
 (0)