Merge pull request #95 from FluffyJenkins/feature/communityModules

Add goto json support (defaults to darlings goto), etc
This commit is contained in:
kasenvr 2020-01-17 12:13:41 -05:00 committed by GitHub
commit 65dde00f6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 23 deletions

View file

@ -28,13 +28,18 @@ var appUUID = Uuid.generate();
var chatBar; var chatBar;
var chatHistory; var chatHistory;
var chatBarHistoryLimit = Settings.getValue(settingsRoot + "/chatBarHistoryLimit", 256);
var chatHistoryLimit = Settings.getValue(settingsRoot + "/chatHistoryLimit", 500);
var chatBarHistory = Settings.getValue(settingsRoot + "/chatBarHistory", ["Meow :3"]);
var historyLog = []; var historyLog = [];
var visible = false; var visible = false;
var historyVisible = false; var historyVisible = false;
var settingsRoot = "FloofChat"; var settingsRoot = "FloofChat";
var darlingGotoUrl = "http://metaverse.darlingvr.club:8081/goto.json";
var gotoJSONUrl = Settings.getValue(settingsRoot + "/gotoJSONUrl", darlingGotoUrl);
var muted = Settings.getValue(settingsRoot + "/muted", {"Local": false, "Domain": false, "Grid": false}); var muted = Settings.getValue(settingsRoot + "/muted", {"Local": false, "Domain": false, "Grid": false});
var ws; var ws;
@ -69,7 +74,7 @@ function init() {
button.clicked.connect(toggleChatHistory); button.clicked.connect(toggleChatHistory);
chatBar.fromQml.connect(fromQml); chatBar.fromQml.connect(fromQml);
chatBar.sendToQml(JSON.stringify({visible: false})); chatBar.sendToQml(JSON.stringify({visible: false, history: chatBarHistory}));
Controller.keyPressEvent.connect(keyPressEvent); Controller.keyPressEvent.connect(keyPressEvent);
Messages.messageReceived.connect(messageReceived); Messages.messageReceived.connect(messageReceived);
@ -172,42 +177,76 @@ function chatColour(tab) {
var chatBarChannel = "Local"; var chatBarChannel = "Local";
function go2(msg) {
var dest = false;
var domainsList = [];
try {
domainsList = Script.require("http://metaverse.darlingvr.club:8081/goto.json");
} catch (e) {
//
}
domainsList.forEach(function (domain) {
if (domain["Domain Name"].toLowerCase().indexOf(msg.toLowerCase()) !== -1 && !dest) {
dest = {"name": domain["Domain Name"], "url": domain["Visit"]};
}
});
return dest;
}
function gotoConfirm(url) { function gotoConfirm(url, name, confirm) {
var result = Window.confirm("Do you want to go to '" + ((url.indexOf("/") !== -1) ? url.split("/")[2] : url) + "'?"); confirm = confirm === undefined ? true : confirm;
name = name === undefined ? url : name;
var result = true;
if (confirm) {
result = Window.confirm("Do you want to go to '" + ((name.indexOf("/") !== -1) ? url.split("/")[2] : name) + "'?");
}
if (result) { if (result) {
location = url; location = url;
} }
} }
function processChat(cmd) { function processChat(cmd) {
function commandResult() {
msg = "";
setVisible(false);
}
var msg = cmd.message; var msg = cmd.message;
if (msg.indexOf("/") === 0) { if (msg.indexOf("/") === 0) {
msg = msg.substring(1); msg = msg.substring(1);
var commandList = msg.split(" "); var commandList = msg.split(" ");
var tempList = commandList.concat();
tempList.shift();
var restOfMsg = tempList.join(" ");
msg = "/" + msg;
var cmd1 = commandList[0].toLowerCase(); var cmd1 = commandList[0].toLowerCase();
if (cmd1 === "l") { if (cmd1 === "l") {
chatBarChannel = "Local"; chatBarChannel = "Local";
msg = ""; commandResult();
} }
if (cmd1 === "d") { if (cmd1 === "d") {
chatBarChannel = "Domain"; chatBarChannel = "Domain";
msg = ""; commandResult();
} }
if (cmd1 === "g") { if (cmd1 === "g") {
chatBarChannel = "Grid"; chatBarChannel = "Grid";
msg = ""; commandResult();
} }
if (cmd1 === "goto") { if (cmd1 === "goto" || cmd1 === "gotos") {
gotoConfirm(commandList[1]); var result = go2(restOfMsg);
msg = ""; if (result) {
gotoConfirm(result.url, result.name, (cmd1 === "goto"));
} else {
gotoConfirm(commandList[1], undefined, (cmd1 === "goto"));
}
commandResult();
} }
if (cmd1 === "me") { if (cmd1 === "me") {
var tempList = commandList; msg = cmd.avatarName + " " + restOfMsg;
tempList.shift();
msg = cmd.avatarName + " " + tempList.join(" ");
cmd.avatarName = ""; cmd.avatarName = "";
} }
} }
@ -415,12 +454,20 @@ function time() {
function addToLog(msg, dp, colour, tab) { function addToLog(msg, dp, colour, tab) {
historyLog.push([time(), msg, dp, colour, tab]); historyLog.push([time(), msg, dp, colour, tab]);
chatHistory.emitScriptEvent(JSON.stringify({type: "MSG", data: [[time(), msg, dp, colour, tab]]})); chatHistory.emitScriptEvent(JSON.stringify({type: "MSG", data: [[time(), msg, dp, colour, tab]]}));
while (historyLog.length > 500) { while (historyLog.length > chatHistoryLimit) {
historyLog.shift(); historyLog.shift();
} }
Settings.setValue(settingsRoot + "/HistoryLog", JSON.stringify(historyLog)) Settings.setValue(settingsRoot + "/HistoryLog", JSON.stringify(historyLog))
} }
function addToChatBarHistory(msg) {
chatBarHistory.unshift(msg);
while (chatBarHistory.length > chatBarHistoryLimit) {
chatBarHistory.pop();
}
Settings.setValue(settingsRoot + "/chatBarHistory", chatBarHistory);
}
function fromQml(message) { function fromQml(message) {
var cmd = {FAILED: true}; var cmd = {FAILED: true};
try { try {
@ -431,6 +478,7 @@ function fromQml(message) {
if (!cmd.FAILED) { if (!cmd.FAILED) {
if (cmd.type === "MSG") { if (cmd.type === "MSG") {
if (cmd.message !== "") { if (cmd.message !== "") {
addToChatBarHistory(cmd.message);
if (cmd.event.modifiers === CONTROL_KEY) { if (cmd.event.modifiers === CONTROL_KEY) {
cmd.avatarName = MyAvatar.displayName; cmd.avatarName = MyAvatar.displayName;
cmd = processChat(cmd); cmd = processChat(cmd);

View file

@ -11,6 +11,8 @@ Rectangle {
Binding { target: window; property: 'shown'; value: false; when: Boolean(window) } Binding { target: window; property: 'shown'; value: false; when: Boolean(window) }
Component.onDestruction: thing && thing.destroy() Component.onDestruction: thing && thing.destroy()
property var hist : -1;
property var history : [];
signal sendToScript(var message); signal sendToScript(var message);
color: "#00000000" color: "#00000000"
@ -28,18 +30,21 @@ Rectangle {
} catch(e){ } catch(e){
// //
} }
if(!data.failed){ if (!data.failed) {
if(data.cmd){ if (data.cmd) {
JSConsole.executeCommand(data.msg); JSConsole.executeCommand(data.msg);
} }
console.log(data.visible); console.log(data.visible);
if(data.visible){ if (data.visible) {
thing.visible = true; thing.visible = true;
textArea.focus = true; textArea.focus = true;
} else if(!data.visible){ } else if (!data.visible) {
thing.visible = false; thing.visible = false;
textArea.focus = false; textArea.focus = false;
} }
if (data.history) {
history = data.history;
}
} }
} }
@ -64,13 +69,36 @@ Rectangle {
clip: false clip: false
font.pointSize: 20 font.pointSize: 20
function _onEnterPressed(event) function _onEnterPressed(event) {
{ sendMessage(JSON.stringify({type:"MSG", message:text, event:event}));
sendMessage(JSON.stringify({type:"MSG",message:text,event:event})); history.unshift(text);
text = ""; text = "";
hist = -1;
} }
Keys.onReturnPressed: { _onEnterPressed(event) }
Keys.onEnterPressed: { _onEnterPressed(event) } function upPressed(event) {
hist++;
if (hist > history.length-1) {
hist = history.length-1;
}
text = history[hist];
}
function downPressed(event) {
hist--;
if (hist < -1) {
hist = -1;
}
if (hist === -1) {
text = "";
} else{
text = history[hist];
}
}
Keys.onReturnPressed: { _onEnterPressed(event); }
Keys.onEnterPressed: { _onEnterPressed(event); }
Keys.onUpPressed: { upPressed(event); }
Keys.onDownPressed: { downPressed(event); }
} }
MouseArea { MouseArea {