-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.pl
48 lines (40 loc) · 1.22 KB
/
ui.pl
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
% Module for communicating to UI.
:- module(ui, [make_ui_call/2]).
%% make_ui_call(+Cmds:list, -Js:string)
%
% Create a Javascript to triggering events in UI. Available commands:
% - say(Who, What)
% - wait(Time)
% - notify(Event)
% - mudAction(ActionName)
%
% @param Cmds a list of commands
% @param Js Javascript to be sent to frontend
%
make_ui_call(Cmds, Js) :-
make_message(Cmds, JsArgs),
format(string(Js), "processCommands([~w])", JsArgs).
% Create Javascript for a list of commands
%
make_message([H], Js) :-
!, make_message(H, Js).
make_message([H | T], Js) :-
make_message(H, Js1),
make_message(T, Js2),
format(string(Js), "~w, ~w", [Js1, Js2]).
% Create Javascript for chat event.
%
make_message(say(Who, What), Js) :-
format(string(Js), '{ func:"say", args:["~w", "~w"] }', [Who, What]).
% Create Javascript for wait event.
%
make_message(wait(T), Js) :-
format(string(Js), '{ func:"wait", args:["~w"] }', [T]).
% Create Javascript for generic notification event.
%
make_message(notify(Txt), Js) :-
format(string(Js), '{ func:"notify", args:["~w"] }', [Txt]).
% Create Javascript for event triggering MUD action.
%
make_message(mud(Act), Js) :-
format(string(Js), '{ func:"mudAction", args:["~w"] }', [Act]).