This commit is contained in:
2018-11-28 19:28:44 +01:00
parent 4ddd6147e9
commit 3a2bc2deff
5 changed files with 8279 additions and 18 deletions

2
dist/autoloader.js vendored
View File

@@ -1,4 +1,4 @@
/*Generated on:Tue Nov 27 2018 15:35:54 GMT+0100 (CET)*/ /*Generated on:Wed Nov 28 2018 19:28:43 GMT+0100 (CET)*/
var AutomaticDispose_Branch = "master"; var AutomaticDispose_Branch = "master";
var AutomaticDispose_URL = "https://jf.git.rest/Jomaar/automatic-dispose/raw/branch/"; var AutomaticDispose_URL = "https://jf.git.rest/Jomaar/automatic-dispose/raw/branch/";
var da_lss_adis_time = new Date().getTime(); var da_lss_adis_time = new Date().getTime();

7501
dist/autoloaderV2.js vendored Normal file

File diff suppressed because it is too large Load Diff

2
dist/standalone.js vendored
View File

@@ -1,4 +1,4 @@
/*Generated on:Tue Nov 27 2018 15:35:54 GMT+0100 (CET)*/ /*Generated on:Wed Nov 28 2018 13:35:31 GMT+0100 (CET)*/
function includesString(string1, string2) { function includesString(string1, string2) {
return string1.toLowerCase().includes(string2.toLowerCase()); return string1.toLowerCase().includes(string2.toLowerCase());
} }

View File

@@ -11,22 +11,39 @@ var gulp = require("gulp"),
headerComment = '/*Generated on:' + d + '*/\n'; headerComment = '/*Generated on:' + d + '*/\n';
gulp.task("scripts", function () { gulp.task("scripts3", function () {
console.log("-- gulp is running task 'scripts'"); console.log("-- gulp is running task 'scripts'");
var config = fs.readFileSync('./all_missions.json', ); var config = fs.readFileSync('./all_missions.json', );
gulp.src("src/*.js") gulp.src("src/autoloaderV2.js")
.pipe(include()) .pipe(include())
.on('error', console.log) .on('error', console.log)
.pipe(replace({ .pipe(replace({
global:{ global:{
ADis_AllMissions:config.toString() ADis_AllMissions:config.toString()
}, },
prefix:"/***", prefix:"/***",
suffix:"***/0" suffix:"***/0"
})) }))
.pipe(header(headerComment)) .pipe(header(headerComment))
.pipe(gulp.dest("dist")); .pipe(gulp.dest("dist"));
}); });
gulp.task("scripts", function () {
console.log("-- gulp is running task 'scripts'");
var config = fs.readFileSync('./all_missions.json', );
gulp.src("src/autoloader.js")
.pipe(include())
.on('error', console.log)
.pipe(replace({
global:{
ADis_AllMissions:config.toString()
},
prefix:"/***",
suffix:"***/0"
}))
.pipe(header(headerComment))
.pipe(gulp.dest("dist"));
});
gulp.task("minify", ["scripts"], function (cb) { gulp.task("minify", ["scripts"], function (cb) {
console.log("-- gulp is running task 'minify'"); console.log("-- gulp is running task 'minify'");

743
src/autoloaderV2.js Normal file
View File

@@ -0,0 +1,743 @@
//=require ../node_modules/dexie/dist/dexie.js
class AutomaticDispose {
// Variablen
get ADisSettings() {
return {
url: "https://jf.git.rest/Jomaar/automatic-dispose/raw/branch/",
branch: "master",
all_missions: /***ADis_AllMissions***/ 0,
name: this.name
}
}
constructor() {
this.ADis_MyHead = document.getElementsByTagName('head')[0];
this.ADis_MyBody = document.getElementsByTagName('body')[0];
// -
// - Sprechwunsch Variablen
// -
this.Jails = [];
this.JailRegEx = /\(Freie Zellen\:\s+(\d)\,\s+Entfernung\:\s+(\d+\,\d+)\s+km(?:\,\s+Abgabe an Besitzer\:\s+(\d+)%)?\)/g;
this.Hospitals = [];
this.RescueVehicleFrameWatchDog = null;
this.PoliceVehicleFrameWatchDog = null;
let that = this;
this.ADisDB = new Dexie('LSS_AutomaticDispo');
this.ADisDB.version(1).stores({
/**
* AvailabelMissions
* - missionID
* - type
* - name
* - jsondata
*/
ADisAvailabelMissions: "++missionID,type,name",
/**
* Sprechwunsch
* - vehicleID
* - done
*/
ADisSprechwunsch: "++vehicleID,done",
/**
* Sprechwunsch Police
* - missionID
* - done
*/
ADisSprechwunschPolice: "++missionID,last_check,next_check,done",
/**
* Krankentransport
* - missionID
* - done
*/
ADisKrankentransport: "++missionID,last_check,next_check,done",
/**
* Settings
* - id
* - name
* - done
*/
ADisSettings: "&name,value",
/**
* MissionsOwn
* MissionsVerband
* MissionsVerbandEvent
* - missionID
* - type
* - name
* - available
* - done
* - street
* - village
* - last_check
* - next_check
*/
ADisMissionsOwn: "++missionID,type,name,last_check,next_check,available,done",
ADisMissionsVerband: "++missionID,type,name,last_check,next_check,available,done",
ADisMissionsVerbandEvent: "++missionID,type,name,last_check,next_check,available,done",
});
this.ADisDB.on("populate", function () {
ADisDB.ADisSettings.add({
name: "Krankentransport-Automatic",
value: 'true'
});
ADisDB.ADisSettings.add({
name: "Sprechwunsch-Automatic",
value: 'true'
});
ADisDB.ADisSettings.add({
name: "MissionsOwn-Automatic",
value: 'true'
});
ADisDB.ADisSettings.add({
name: "Alliance-Automatic",
value: 'false'
});
ADisDB.ADisSettings.add({
name: "AllianceEvent-Automatic",
value: 'false'
});
});
this.ADisDB.open().catch(function (err) {
console.error(err.stack || err);
});
this.ADisDB.on("ready", () => {
if (window.location.pathname === "/" || window.location.pathname === "/#") {
that.IndexPage()
setInterval(that.CollectRescueSprechwuensche, 2500);
setInterval(that.OpenNextRescueSprechwunsch, 2500);
that.CollectRescueSprechwuensche();
setInterval(that.CollectPoliceSprechwuensche, 2500);
setInterval(that.OpenNextPoliceSprechwunsch, 2500);
that.CollectPoliceSprechwuensche();
}
//=require ../script/mission.js
//=require ../script/sprechwunsch.js
});
console.log('nonstatic', this.ADisSettings)
}
get Settings() {
console.log('static', this.ADisSettings);
console.log('static WindowName', this);
return this.ADisSettings;
}
includesString(string1, string2) {
return string1.toLowerCase().includes(string2.toLowerCase());
}
get ADSettings() {
return (async () => {
var res = {};
await this.ADisDB.ADisSettings.each((setting) => {
res[setting.name] = setting.value;
});
return res;
})()
}
get WindowName() {
return window.name
}
// -
// - Sprechwunsch Queue
// -
RemovePoliceSprechwunschFromQueue(WunschID) {
return this.ADisDB.ADisSprechwunschPolice.where({
missionID: WunschID
}).delete();
}
RemoveRescueSprechwunschFromQueue(WunschID) {
return this.ADisDB.ADisSprechwunsch.where({
vehicleID: WunschID
}).delete();
}
// - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// -
// - Assign & Unassign Missions to Dispatchers
// -
// - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
CollectRescueSprechwuensche() {
let that = this;
new Promise(async function (resolve, reject) {
await that.ADisDB.ADisSprechwunsch.where({
done: 'false'
}).each((myWunsch) => {
console.log('that.CollectRescueSprechwuensche: remove', myWunsch);
if ($("#vehicle_list_" + myWunsch.vehicleID).find(".building_list_fms").text() != "5") {
return that.RemoveRescueSprechwunschFromQueue(myWunsch.vehicleID);
}
})
return resolve();
}).then(() => {
$("#building_list").find(".building_list_vehicle_element").each(function () {
var VehicleStatus = $(this).find(".building_list_fms").text();
var VehicleType = Number(parseInt($(this).find("a").attr("vehicle_type_id")));
var VehicleID = $(this).attr("vehicle_id");
if (VehicleStatus == "5" && [32, 52].indexOf(VehicleType) === -1) {
that.AddRescueSprechwunschToQueue(VehicleID);
}
});
});
}
OpenNextRescueSprechwunsch() {
let that = this;
this.ADSettings().then((setting) => {
if (setting['Sprechwunsch-Automatic'] == 'true') {
return that.ADisDB.ADisSprechwunsch.where({
done: 'false'
}).limit(1)
}
}).then((Wunsch) => {
if (Wunsch !== undefined) {
Wunsch.each((myWunsch) => {
let VehicleID = myWunsch.vehicleID;
that.UpdateRescueSprechwunschToDone(VehicleID).then(() => {
if ($("#adis-sprechwunsch-rescue-frame").attr("vehicle_id") == "empty") {
$("#adis-sprechwunsch-rescue-frame").attr("src", "https://www.leitstellenspiel.de/vehicles/" + VehicleID);
$("#adis-sprechwunsch-rescue-frame").attr("vehicle_id", VehicleID);
that.RescueVehicleFrameWatchDog = setTimeout(async function () {
that.RemoveRescueSprechwunschFromQueue(VehicleID).then((deleteCount) => {
$("#adis-sprechwunsch-rescue-frame").attr("src", "");
$("#adis-sprechwunsch-rescue-frame").attr("vehicle_id", "empty");
});
}, 1500);
}
});
});
}
});
}
AddRescueSprechwunschToQueue(WunschID) {
return this.ADisDB.ADisSprechwunsch.put({
vehicleID: WunschID,
done: 'false'
}).catch((err) => {})
}
UpdateRescueSprechwunschToDone(WunschID) {
return this.ADisDB.ADisSprechwunsch.put({
vehicleID: WunschID,
done: 'true'
}).catch((err) => {})
}
// - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// -
// - Assign & Unassign Missions to Dispatchers
// -
// - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
CollectPoliceSprechwuensche() {
let that = this;
new Promise(async function (resolve, reject) {
await that.ADisDB.ADisSprechwunschPolice.where({
done: 'false'
}).each((myWunsch) => {
if (!$("#mission_" + myWunsch.missionID).text().match(/Gefangene sollen abtransportiert werden/g)) {
$("#mission_" + myWunsch.missionID).remove();
return that.RemovePoliceSprechwunschFromQueue(myWunsch.missionID);
}
})
return resolve();
}).then(() => {
var MOIODOS = $('div#mission_list div.missionSideBarEntry:visible');
return MOIODOS.each(function (index) {
if ($(this).text().match(/Gefangene sollen abtransportiert werden/g)) {
var MissionID = $(this).attr("mission_id");
that.AddPoliceSprechwunschToQueue(MissionID);
}
});
}).then(() => {
$("#building_list").find(".building_list_vehicle_element").each(function () {
var VehicleStatus = $(this).find(".building_list_fms").text();
var VehicleType = Number(parseInt($(this).find("a").attr("vehicle_type_id")));
var VehicleID = $(this).attr("vehicle_id");
if (VehicleStatus == "5" && [32, 52].indexOf(VehicleType) !== -1) {
var map2 = $('#radio_messages_important > li.radio_message_vehicle_' + VehicleID + ' a:contains("Zum Einsatz")');
if (map2.length > 0) {
var _meap = String(map2.attr('href'));
var MissionID = _meap.substr(_meap.lastIndexOf("/") + 1);
if (MissionID) {
that.AddPoliceSprechwunschToQueue(MissionID);
}
}
}
});
});
}
OpenNextPoliceSprechwunsch() {
let that = this;
this.ADSettings().then((setting) => {
if (setting['Sprechwunsch-Automatic'] == 'true') {
return that.ADisDB.ADisSprechwunschPolice.where({
done: 'false'
}).limit(1)
}
}).then((Wunsch) => {
if (Wunsch !== undefined) {
Wunsch.each((myWunsch) => {
let MissionID = myWunsch.missionID;
that.UpdatePoliceSprechwunschToDone(MissionID).then(() => {
if ($("#adis-sprechwunsch-police-frame").attr("mission_id") == "empty") {
$("#adis-sprechwunsch-police-frame").attr("src", "https://www.leitstellenspiel.de/missions/" + MissionID);
$("#adis-sprechwunsch-police-frame").attr("mission_id", MissionID);
that.PoliceVehicleFrameWatchDog = setTimeout(async function (MissionID) {
that.RemovePoliceSprechwunschFromQueue(MissionID).then((deleteCount) => {
$("#adis-sprechwunsch-police-frame").attr("src", "");
$("#adis-sprechwunsch-police-frame").attr("mission_id", "empty");
});
}, 2500, MissionID);
}
});
});
}
});
}
AddPoliceSprechwunschToQueue(WunschID) {
return this.ADisDB.ADisSprechwunschPolice.put({
missionID: WunschID,
done: 'false'
}).catch((err) => {})
}
UpdatePoliceSprechwunschToDone(WunschID) {
console.log(WunschID, typeof WunschID);
return this.ADisDB.ADisSprechwunschPolice.add({
missionID: WunschID,
done: 'true'
}).catch((err) => {})
}
// -
// - Index Page Loader
// -
IndexPage() {
// -
// - Google Font
// -
var styleElement = document.createElement("link");
styleElement.rel = "stylesheet";
styleElement.href = "https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700";
this.ADis_MyHead.appendChild(styleElement);
// -
// - FontAwesome 5
// -
var scriptElement = document.createElement("script");
scriptElement.type = "text/javascript";
scriptElement.src = "https://use.fontawesome.com/releases/v5.5.0/js/all.js";
this.ADis_MyHead.appendChild(scriptElement);
// -
// - Navbar Dashboard
// -
var styleElement = document.createElement("link");
styleElement.rel = "stylesheet";
styleElement.type = "text/css";
styleElement.media = "screen";
styleElement.href = this.ADisSettings.url + this.ADisSettings.branch + "/style/interface.css";
this.ADis_MyHead.appendChild(styleElement);
// Create Dashboard
$('#news_li').before('<li id="adis-nav-item"></li>');
$('#adis-nav-item').html(`<a id="adis-open-button" href="#">
<span class="glyphicon glyphicon-fire"></span>
</a>
<div id="adis-dashboard">
<header>
Autom. Disposition (ADis)
<a id="adis-dashboard-close-button">
<i class="fas fa-times"></i>
</a>
</header>
<section id="adis-dashboard-settings">
<div title="Arbeitet die ausgewählten Einsätze automatisch ab">
<a id="adis-setting-krankentransport-automatic" class="adis-setting-switch"></a>
Krankentransporte-Automatik
</div>
<div title="Arbeitet alle Einsätze automatisch ab">
<a id="adis-setting-full-automatic" class="adis-setting-switch"></a>
Eigene Einsätze-Automatik
</div>
<div title="Arbeitet die Sprechwünsche automatisch ab">
<a id="adis-setting-sprechwunsch-automatic" class="adis-setting-switch"></a>
Sprechwunsch-Automatik
</div>
<div title="Sendet automatisch Fahrzeuge zu Verbandseinsätzen, welche gerade abgearbeitet werden">
<a id="adis-setting-alliance-automatic" class="adis-setting-switch"></a>
Verbands-Automatik
</div>
<div title="Sendet automatisch Fahrzeuge zu Verband-Event Einsätzen, welche gerade abgearbeitet werden">
<a id="adis-setting-allianceevents-automatic" class="adis-setting-switch"></a>
VerbandsEvents-Automatik
</div>
</section>
</div>
<style>
#adis-nav-item {
position: relative;
}
#adis-dashboard {
width: 364px;
overflow: hidden;
position: absolute;
top: calc(100% + 16px);
left: 50%;
z-index: 1000;
transform: translateX(-50%);
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
font-family: "Open Sans";
font-size: 14px;
font-weight: 400;
background: rgba(250, 250, 250, 1);
border-radius: 4px;
box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.48);
}
#adis-dashboard>header {
width: 100%;
height: 48px;
padding: 8px 24px;
margin: 0px;
position: relative;
display: flex;
justify-content: flex-start;
align-items: center;
line-height: 1;
font-size: 18px;
font-weight: 400;
}
#adis-dashboard-close-button {
width: 48px;
height: 48px;
position: absolute;
top: 0px;
right: 0px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
#adis-dashboard-close-button img {
width: 12px;
height: 12px;
}
#adis-dashboard>section {
width: 100%;
padding: 16px 24px;
margin: 0px;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
}
#adis-dashboard-switch-mode-button,
#adis-dashboard-open-dispatcher-button {
width: 80%;
height: 40px;
margin: 4px 0px;
display: flex;
justify-content: center;
align-items: center;
text-decoration: none;
color: #fafafa;
cursor: pointer;
background: #43a047;
border-radius: 4px;
border-bottom: 3px solid rgba(0, 0, 0, 0.32);
}
#adis-dashboard-settings {
background: #e0e0e0;
border-top: 1px solid #757575;
}
#adis-dashboard-settings>div {
width: 100%;
height: 32px;
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
align-items: center;
}
.adis-setting-switch {
width: 40px;
height: 16px;
margin-right: 16px;
background: #9e9e9e;
border-radius: 12px;
box-shadow: inset 0px 0px 3px 0px rgba(0, 0, 0, 0.20);
}
.adis-setting-switch.active {
background: #8bc34a;
}
.adis-setting-switch::after {
width: 22px;
height: 22px;
margin-top: -3px;
margin-left: -3px;
content: "";
display: block;
background: #fafafa;
border-radius: 12px;
box-shadow: 0px 0px 3px 0px rgba(0, 0, 0, 0.24);
transition: all 200ms;
}
.adis-setting-switch.active::after {
margin-left: calc(100% - 22px + 3px);
background: #5a9216;
box-shadow: 0px 0px 3px 0px rgba(0, 0, 0, 0.32);
transition: all 200ms;
}
</style>
<script>
//
// Setting-Events
//
$(document).ready(function () {
//
// Click Events
//
$("#adis-setting-krankentransport-automatic").click(function () {
var tf = $(this).hasClass("active");
console.log(tf);
ADisDB.ADisSettings.put({
name: "Krankentransport-Automatic",
value: !tf ? 'true' : 'false'
}).then((res) => {
console.log(res);
ADis_UpdateSettings();
});
});
$("#adis-setting-full-automatic").click(function () {
var tf = $(this).hasClass("active");
console.log(tf);
ADisDB.ADisSettings.put({
name: "MissionsOwn-Automatic",
value: !tf ? 'true' : 'false'
}).then(() => {
ADis_UpdateSettings();
});
});
$("#adis-setting-sprechwunsch-automatic").click(function () {
var tf = $(this).hasClass("active");
console.log(tf);
ADisDB.ADisSettings.put({
name: "Sprechwunsch-Automatic",
value: !tf ? 'true' : 'false'
}).then(() => {
ADis_UpdateSettings();
});
});
$("#adis-setting-alliance-automatic").click(function () {
var tf = $(this).hasClass("active");
ADisDB.ADisSettings.put({
name: "Alliance-Automatic",
value: !tf ? 'true' : 'false'
}).then(() => {
ADis_UpdateSettings();
});
});
$("#adis-setting-alliance-automatic").click(function () {
var tf = $(this).hasClass("active");
ADisDB.ADisSettings.put({
name: "AllianceEvent-Automatic",
value: !tf ? 'true' : 'false'
}).then(() => {
ADis_UpdateSettings();
});
});
//
// Dashboard Functions
//
$("#adis-open-button").click(function () {
$("#adis-dashboard").css("display", "flex");
$("#adis-dashboard").animate({
opacity: 1
}, 200);
});
$("#adis-dashboard-close-button").click(function () {
$("#adis-dashboard").animate({
opacity: 0
}, 200, function () {
$(this).css("display", "none");
});
});
// initial call to load the current setting state
ADis_UpdateSettings();
});
//
// Display Settings
//
function ADis_UpdateSettings() {
ADisDB.ADisSettings.each((setting) => {
if (setting.name == "Krankentransport-Automatic") {
if (setting.value == "true") {
$("#adis-setting-krankentransport-automatic").addClass("active");
} else {
$("#adis-setting-krankentransport-automatic").removeClass("active");
}
} else if (setting.name == "Sprechwunsch-Automatic") {
if (setting.value == "true") {
$("#adis-setting-sprechwunsch-automatic").addClass("active");
} else {
$("#adis-setting-sprechwunsch-automatic").removeClass("active");
}
} else if (setting.name == "MissionsOwn-Automatic") {
if (setting.value == "true") {
$("#adis-setting-full-automatic").addClass("active");
} else {
$("#adis-setting-full-automatic").removeClass("active");
}
} else if (setting.name == "Alliance-Automatic") {
if (setting.value == "true") {
$("#adis-setting-alliance-automatic").addClass("active");
} else {
$("#adis-setting-alliance-automatic").removeClass("active");
}
} else if (setting.name == "AllianceEvents-Automatic") {
if (setting.value == "true") {
$("#adis-setting-allianceevents-automatic").addClass("active");
} else {
$("#adis-setting-allianceevents-automatic").removeClass("active");
}
}
});
}
</script>`)
$("#adis-dashboard").css({
display: "none",
opacity: "0"
});
// Create Iframes
$("body").append('<div id="adis-frame-container"></div>');
$("#adis-frame-container").html(`<div id="adis-frame-wrapper" style="display: none; opacity: 0">
<iframe id="adis-ownmissions-frame" name="adis-ownmissions" mission_id="empty" src=""></iframe>
<iframe id="adis-plannedevents-frame" name="adis-plannedevents" mission_id="empty" src=""></iframe>
<iframe id="adis-verbandmission-frame" name="adis-verbandmission" mission_id="empty" src=""></iframe>
<iframe id="adis-verbandmission-event-frame" name="adis-verbandmission-event" mission_id="empty" src=""></iframe>
<iframe id="adis-krankentransporte-frame" name="adis-krankentransporte" mission_id="empty" src=""></iframe>
<iframe id="adis-sprechwunsch-rescue-frame" name="adis-sprechwunsch-rescue" vehicle_id="empty" src=""></iframe>
<iframe id="adis-sprechwunsch-police-frame" name="adis-sprechwunsch-police" mission_id="empty" src=""></iframe>
</div>
<style>
#adis-frame-container {
width: 100%;
height: 100vh;
padding: 4% 10%;
position: fixed;
top: 0px;
left: 0px;
right: 0px;
z-index: 2010;
display: flex;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.48);
}
#adis-frame-wrapper {
width: 100%;
height: 100%;
padding: 32px;
position: relative;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
background: #eeeeee;
border-radius: 4px;
box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.32);
}
#adis-frame-wrapper>iframe {
width: 100%;
height: 50%;
border: 0px;
}
</style>`);
$("#adis-frame-container").css({
display: "none",
opacity: "0"
});
}
}
window.AutomaticDisposeCall = new AutomaticDispose();