A lot of work has been done on Messages and Malfunction reporting. Messages, in particular, are done in the backend.
This commit is contained in:
parent
8194fd0f8b
commit
2582c4c4ee
|
@ -130,7 +130,7 @@ def setFitness():
|
|||
|
||||
# Cyberware management
|
||||
cyberware = []
|
||||
newCyberwareTemplate = { "uuid": None, "name": None, "hotpluggable": False, "lastMalfunction": None, "canSet": [], "battery": None, "messages": [] }
|
||||
newCyberwareTemplate = { "uuid": None, "name": None, "hotpluggable": False, "lastMalfunction": None, "canSet": None, "battery": None, "messages": None }
|
||||
newMessageTemplate = { "title": None, "message": None, "progress": None }
|
||||
# Messages: { Title, Message, Progress }
|
||||
# Title, Message, and Progress are all technically optional. It's up to the frontend to make heads or tails of what's happening.
|
||||
|
@ -169,6 +169,7 @@ def addCyberware():
|
|||
tempNewCyberware['name'] = tempName
|
||||
tempNewCyberware['hotpluggable'] = tempHotpluggable
|
||||
|
||||
|
||||
cyberware.append(tempNewCyberware)
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { name: STRING, hotpluggable: BOOL, canSet: ARRAY }\n', 400
|
||||
|
@ -226,8 +227,35 @@ def getCyberwareMessages():
|
|||
if c['messages'] != None:
|
||||
returnArr.append({ 'name': c['name'], 'messages': c['messages'] })
|
||||
resetMessages()
|
||||
print(returnArr)
|
||||
return jsonify(returnArr), 200
|
||||
|
||||
# Arguments { uuid: STRING, message:{ title: STRING, message: STRING, progress: INT } }
|
||||
@app.route('/api/cyberware/messages', methods=['POST'])
|
||||
def setCyberwareMessages():
|
||||
global cyberware
|
||||
json = request.get_json()
|
||||
|
||||
try:
|
||||
desiredId = json['uuid']
|
||||
message = json['message']
|
||||
|
||||
# Test message validity
|
||||
testTitle = message["title"]
|
||||
testMessage = message["message"]
|
||||
testProgress = message["progress"]
|
||||
|
||||
requestedCyberware = getCyberwareHelper(desiredId)
|
||||
|
||||
if (requestedCyberware != None):
|
||||
if (requestedCyberware["messages"] == None):
|
||||
requestedCyberware["messages"] = []
|
||||
requestedCyberware["messages"].append(message)
|
||||
return '', 204
|
||||
except:
|
||||
return "Incorrect usage.\nUsage: { uuid: STRING, message:{ title: STRING, message: STRING, progress: INT } }\n", 400
|
||||
return "UUID Invalid\n", 400
|
||||
|
||||
@app.route('/api/cyberware/get', methods=['POST'])
|
||||
def getCyberwareSpecific():
|
||||
json = request.get_json()
|
||||
|
@ -243,7 +271,7 @@ def getCyberwareSpecific():
|
|||
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
||||
return 'UUID Invalid\n', 400
|
||||
|
||||
# Arguments { uuid: INT }
|
||||
# Arguments { uuid: STRING }
|
||||
@app.route('/api/cyberware/battery')
|
||||
def getCyberwareBattery():
|
||||
json = request.get_json()
|
||||
|
@ -262,6 +290,7 @@ def getCyberwareBattery():
|
|||
# Arguments { uuid: STRING, battery: INT }
|
||||
@app.route('/api/cyberware/battery', methods=['POST'])
|
||||
def setCyberwareBattery():
|
||||
global cyberware
|
||||
json = request.get_json()
|
||||
|
||||
try:
|
||||
|
@ -284,6 +313,7 @@ def resetAllCyberwareMalfunction():
|
|||
# Arguments { uuid: STRING }
|
||||
@app.route('/api/cyberware/reset_malfunction', methods=['POST'])
|
||||
def resetCyberwareMalfunction():
|
||||
global cyberware
|
||||
json = request.get_json()
|
||||
|
||||
try:
|
||||
|
@ -299,22 +329,29 @@ def resetCyberwareMalfunction():
|
|||
return 'UUID Invalid\n', 400
|
||||
|
||||
def resetMalfunctions():
|
||||
global cyberware
|
||||
for c in cyberware:
|
||||
c['lastMalfunction'] = None
|
||||
|
||||
def resetMessages():
|
||||
global cyberware
|
||||
for c in cyberware:
|
||||
if c['messages'] != None:
|
||||
newMessageList = []
|
||||
for m in c['messages']:
|
||||
if(m['progress'] == None): # Unless we're FULLY resetting messages, we want to keep messages with a progress bar attached.
|
||||
if(m['progress'] != None): # Unless we're FULLY resetting messages, we want to keep messages with a progress bar attached.
|
||||
newMessageList.append(m)
|
||||
if newMessageList == []:
|
||||
c['messages'] = None
|
||||
else:
|
||||
c['messages'] = newMessageList
|
||||
|
||||
def resetMessagesFull():
|
||||
global cyberware
|
||||
for c in cyberware:
|
||||
c['messages'] = None
|
||||
|
||||
def getCyberwareHelper(uuid):
|
||||
def getCyberwareHelper(desiredId):
|
||||
i = 0
|
||||
for c in cyberware:
|
||||
if c['uuid'] == desiredId:
|
||||
|
|
|
@ -220,14 +220,30 @@
|
|||
var baseUrl = "http://localhost:5000";
|
||||
var vitalsUrl = baseUrl + "/api/vitals";
|
||||
var environmentUrl = baseUrl + "/api/environment";
|
||||
var malfunctionUrl = baseUrl + "/api/cyberware/malfunctions";
|
||||
var messageUrl = baseUrl + "/api/cyberware/messages";
|
||||
|
||||
// Malfunction Messages (human-friendly)
|
||||
malfunctionMessage = [ "API Malfunction" ]
|
||||
malfunctionOrigin = [ "API Malfunction" ];
|
||||
malfunctionMessage = [ "API Malfunction" ];
|
||||
|
||||
apiMalfunctionI = 0
|
||||
// O - Origin
|
||||
// I - Index
|
||||
apiMalfunctionOI = 0;
|
||||
apiMalfunctionI = 0;
|
||||
|
||||
function displayMalfunction(malfunction) {
|
||||
console.log(malfunction);
|
||||
function displayMalfunction(malfunctionOrigin, malfunctionMessage) {
|
||||
console.log("MALFUNCTION [ " + malfunctionOrigin + "] " + malfunctionMessage);
|
||||
}
|
||||
|
||||
function displayMessage(title, message, progress) {
|
||||
console.log("Message [" + title + "] " + message + " | " + progress);
|
||||
}
|
||||
|
||||
function displayMessageList(name, messages) {
|
||||
for(var message in messages) {
|
||||
displayMessage(messages[0]["title"], messages[0]["message"], messages[0]["progress"]);
|
||||
}
|
||||
}
|
||||
|
||||
function setVitals(vitalsData) {
|
||||
|
@ -265,8 +281,8 @@
|
|||
}
|
||||
|
||||
function setEnvironment(environmentData) {
|
||||
temperature = environmentData["0"]["temperature"];
|
||||
humidity = environmentData["0"]["humidity"];
|
||||
temperature = environmentData[0]["temperature"];
|
||||
humidity = environmentData[0]["humidity"];
|
||||
|
||||
setEnvironmentTemperature(temperature);
|
||||
setEnvironmentHumidity(humidity);
|
||||
|
@ -284,12 +300,26 @@
|
|||
|
||||
}
|
||||
|
||||
// Malfunction handling
|
||||
function handleMalfunctions(malfunctions) {
|
||||
for (var cyberware in malfunctions) {
|
||||
displayMalfunction(messages[cyberware]["name"], messages[cyberware]["lastMalfunction"]);
|
||||
}
|
||||
}
|
||||
|
||||
// Message handling
|
||||
function handleMessages(messages) {
|
||||
for (var cyberware in messages) {
|
||||
displayMessageList(messages[cyberware]["name"], messages[cyberware]["messages"]);
|
||||
}
|
||||
}
|
||||
|
||||
function updateAll() {
|
||||
$.get(vitalsUrl, (data, status) => {
|
||||
if(status == "success") {
|
||||
setVitals(data);
|
||||
} else {
|
||||
displayMalfunction(malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||
displayMalfunction(malfunctionOrigin[apiMalfunctionOI], malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -297,7 +327,23 @@
|
|||
if(status == "success") {
|
||||
setEnvironment(data);
|
||||
} else {
|
||||
displayMalfunction(malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||
displayMalfunction(malfunctionOrigin[apiMalfunctionOI], malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||
}
|
||||
});
|
||||
|
||||
$.get(malfunctionUrl, (data, status) => {
|
||||
if(status == "success") {
|
||||
handleMalfunctions(data)
|
||||
} else {
|
||||
displayMalfunction(malfunctionOrigin[apiMalfunctionOI], malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||
}
|
||||
});
|
||||
|
||||
$.get(messageUrl, (data, status) => {
|
||||
if(status == "success") {
|
||||
handleMessages(data)
|
||||
} else {
|
||||
displayMalfunction(malfunctionOrigin[apiMalfunctionOI], malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||
}
|
||||
});
|
||||
//stopInterval(t)
|
||||
|
|
Loading…
Reference in a new issue