-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
150 lines (134 loc) · 5.37 KB
/
index.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
var eejs = require('ep_etherpad-lite/node/eejs/');
var settings = require('ep_etherpad-lite/node/utils/Settings');
//var clientIO = require('socket.io-client');
var mythicManager = require('./mythicManager');
var mythic = require('./mythic');
exports.eejsBlock_body = function(hook_name, args, cb) {
args.content =
eejs.require('ep_mythic/templates/styles.html', {settings : false, content: args.content })
+ eejs.require('ep_mythic/templates/toolbar.ejs', {settings : false, content: args.content })
+ args.content
+ eejs.require('ep_mythic/templates/sidebar.ejs', {settings : false })
return cb();
}
exports.eejsBlock_scripts = function(hook_name, args, cb) {
//args.content = args.content + eejs.require('ep_mythic/templates/ui-js.ejs', { settings: false });
return cb();
}
exports.eejsBlock_globalSettings = function (hook_name, args, cb) {
args.content = args.content + eejs.require("ep_mythic/templates/settings.ejs");
return cb();
};
exports.socketio = function (hook_name, args, cb){
var app = args.app;
var io = args.io;
var pushComment;
var padComment = io;
var commentSocket = io
.of('/mythic')
.on('connection', function (socket) {
// Load engine
socket.on('getMythic', function (data, callback) {
var padId = data.padId;
// Join to room
socket.join(padId);
mythicManager.getEngine(padId, function (err, engine){
callback(engine);
});
});
// Set engine
socket.on('setMythic', function (data, callback) {
var padId = data.padId;
var engine = data.engine;
mythicManager.setEngine(padId, engine, function (err){
socket.broadcast.to(padId).emit('engineUpdate', engine);
callback(err);
});
});
// Save settings
socket.on('saveSettings', function (data, callback) {
var padId = data.padId;
var settings = data.settings;
mythicManager.setSettings(padId, settings, function (sett){
socket.broadcast.to(padId).emit('settingsUpdate', sett);
callback(sett);
});
});
socket.on('addNpc', function(data, callback) {
var padId = data.padId;
var npc = { title: data.npc.title };
mythicManager.addNpc(padId, npc, function(npcId, npc) {
socket.broadcast.to(padId).emit("npcAdd", { npcId: npcId, npc: npc });
socket.emit("npcAdd", { npcId: npcId, npc: npc });
callback(npcId, npc);
});
});
socket.on('deleteNpc', function(data, callback) {
var padId = data.padId;
var npcId = data.npcId;
mythicManager.deleteNpc(padId, npcId, function(npcId) {
socket.broadcast.to(padId).emit("npcDelete", { npcId: npcId });
socket.emit("npcDelete", { npcId: npcId });
callback(npcId);
});
});
socket.on('titleNpc', function(data, callback) {
var padId = data.padId;
var npcId = data.npcId;
var npc = { title: data.title };
mythicManager.editNpc(padId, npcId, npc, function(npcId, npc) {
socket.broadcast.to(padId).emit("npcUpdate", { npcId: npcId, npc: npc });
socket.emit("npcUpdate", { npcId: npcId, npc: npc });
callback(npcId, npc);
});
});
socket.on('addThread', function(data, callback) {
var padId = data.padId;
var thread = { title: data.thread.title };
mythicManager.addThread(padId, thread, function(threadId, thread) {
socket.broadcast.to(padId).emit("threadAdd", { threadId: threadId, thread: thread });
socket.emit("threadAdd", { threadId: threadId, thread: thread });
callback(threadId, thread);
});
});
socket.on('deleteThread', function(data, callback) {
var padId = data.padId;
var threadId = data.threadId;
mythicManager.deleteThread(padId, threadId, function(threadId) {
socket.broadcast.to(padId).emit("threadDelete", { threadId: threadId });
socket.emit("threadDelete", { threadId: threadId });
callback(threadId);
});
});
socket.on('stopThread', function(data, callback) {
var padId = data.padId;
var threadId = data.threadId;
var thread = { status: "passive" };
mythicManager.editThread(padId, threadId, thread, function(threadId, thread) {
socket.broadcast.to(padId).emit("threadUpdate", { threadId: threadId, thread: thread });
socket.emit("threadUpdate", { threadId: threadId, thread: thread });
callback(threadId, thread);
});
});
socket.on('playThread', function(data, callback) {
var padId = data.padId;
var threadId = data.threadId;
var thread = { status: "active" };
mythicManager.editThread(padId, threadId, thread, function(threadId, thread) {
socket.broadcast.to(padId).emit("threadUpdate", { threadId: threadId, thread: thread });
socket.emit("threadUpdate", { threadId: threadId, thread: thread });
callback(threadId, thread);
});
});
socket.on('titleThread', function(data, callback) {
var padId = data.padId;
var threadId = data.threadId;
var thread = { title: data.title };
mythicManager.editThread(padId, threadId, thread, function(threadId, thread) {
socket.broadcast.to(padId).emit("threadUpdate", { threadId: threadId, thread: thread });
socket.emit("threadUpdate", { threadId: threadId, thread: thread });
callback(threadId, thread);
});
});
});
};