Atlas-Config-Generator/js/main.js
2019-08-24 21:23:39 +01:00

207 lines
No EOL
4.9 KiB
JavaScript

// True numeric value binding
ko.bindingHandlers.numericValue = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var underlyingObservable = valueAccessor();
var interceptor = ko.dependentObservable({
read: underlyingObservable,
write: function (value) {
if (!isNaN(value)) {
underlyingObservable(parseFloat(value));
}
}
});
ko.bindingHandlers.value.init(element, function () {
return interceptor
}, allBindingsAccessor, viewModel, bindingContext);
},
update: ko.bindingHandlers.value.update
};
var editor = ace.edit("config-editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");
var viewmodel = ko.mapping.fromJS({
// Server Argument Section
"BaseServerArgs": "",
"AdditionalCmdLineParams": "",
// World Options
"WorldFriendlyName": "New Server",
"WorldAtlasId": "",
"WorldAtlasPassword": "",
"ModIDs": "",
// Grid Options
"gridSize": 1000,
"totalGridsX": 1,
"totalGridsY": 1,
"coordsScaling": 0.000000000001,
"globalTransitionMinZ": 0.0,
// Image Paths
"backgroundImgPath": "image.png",
"discoZonesImagePath": "image.png",
// URL Options
"MetaWorldURL": "",
"AuthListURL": "",
"MapImageURL": "",
// Time Options
"Day0": "2019-01-09 20:28:56",
"bUseUTCTime": false,
"columnUTCOffset": 0.0,
"lastImageOverride": "0001-01-01T00:00:00",
// Info Options
"showServerInfo": false,
"showDiscoZoneInfo": false,
"showShipPathsInfo": false,
"showIslandNames": false,
"showLines": false,
"showBackground": false,
// S3 Options
"LocalS3URL": "",
"LocalS3AccessKeyId": "",
"LocalS3SecretKey": "",
"LocalS3BucketName": "",
"LocalS3Region": "",
// Unsorted...
"globalGameplaySetup": "",
"shipPathsIdGenerator": 1,
"idGenerator": 127,
"regionsIdGenerator": 0,
// Tribe Log Tab
"TribeLogConfig": {
// Main Options
"MaxRedisEntries": 1000,
"BackupMode": "off",
"MaxFileHistory": 10,
"HttpBackupURL": "",
"HttpAPIKey": "",
//S3 Options
"S3URL": "",
"S3AccessKeyId": "",
"S3SecretKey": "",
"S3BucketName": "",
"S3KeyPrefix": ""
},
// Travel Data Tab
"TravelDataConfig": {
// Main Options
"BackupMode": "off",
"MaxFileHistory": 10,
"HttpBackupURL": "",
"HttpAPIKey": "",
//S3 Options
"S3URL": "",
"S3AccessKeyId": "",
"S3SecretKey": "",
"S3BucketName": "",
"S3KeyPrefix": ""
},
// Shared Log Tab
"SharedLogConfig": {
// Main Options
"FetchRateSec": 60,
"SnapshotCleanupSec": 900,
"SnapshotRateSec": 1800,
"SnapshotExpirationHours": 48,
"BackupMode": "off",
"MaxFileHistory": 10,
"HttpBackupURL": "",
"HttpAPIKey": "",
//S3 Options
"S3URL": "",
"S3AccessKeyId": "",
"S3SecretKey": "",
"S3BucketName": "",
"S3KeyPrefix": ""
},
// Databases Tab
"DatabaseConnections": [
{
"Name": "Default",
"URL": "127.0.0.1",
"Port": 6390,
"Password": ""
},
{
"Name": "TribeDB",
"URL": "127.0.0.1",
"Port": 6390,
"Password": ""
},
{
"Name": "TravelDataDB",
"URL": "127.0.0.1",
"Port": 6390,
"Password": ""
},
{
"Name": "TerritoryDB",
"URL": "127.0.0.1",
"Port": 6390,
"Password": ""
},
{
"Name": "LogDB",
"URL": "127.0.0.1",
"Port": 6390,
"Password": ""
}
],
"servers": [],
"spawnerOverrideTemplates": [],
"shipPaths": [],
"serverTemplates": [],
// ?!?!
"OverrideShooterGameModeDefaultGameIni": {}
});
ko.applyBindings(viewmodel);
updateEditor();
ko.computed(function () {
return ko.toJSON(viewmodel);
}).subscribe(function () {
updateEditor();
});
editor.on("change", function () {
setTimeout(function () {
ko.mapping.fromJSON(editor.getValue(), viewmodel);
}, 100);
});
function updateEditor() {
var interim = ko.mapping.toJS(viewmodel);
interim.coordsScaling = Number(interim.coordsScaling).toFixed(12);
editor.setValue(ko.toJSON(interim, null, 2));
}
function addDatabase() {
var newDB = {
"Name": ko.observable("NewDB"),
"URL": ko.observable("127.0.0.1"),
"Port": ko.observable(6390),
"Password": ko.observable("")
}
viewmodel.DatabaseConnections.push(newDB);
}
function removeDatabase(obj) {
viewmodel.DatabaseConnections.remove(obj);
}