First pass parser testing
This commit is contained in:
parent
9f21b0bd3b
commit
d9a36437b6
4 changed files with 204 additions and 1 deletions
7
.idea/dictionaries/Tom.xml
generated
Normal file
7
.idea/dictionaries/Tom.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="Tom">
|
||||||
|
<words>
|
||||||
|
<w>deparse</w>
|
||||||
|
</words>
|
||||||
|
</dictionary>
|
||||||
|
</component>
|
||||||
|
|
@ -19,7 +19,7 @@ ko.bindingHandlers.numericValue = {
|
||||||
|
|
||||||
var editor = ace.edit("config-editor");
|
var editor = ace.edit("config-editor");
|
||||||
editor.setTheme("ace/theme/monokai");
|
editor.setTheme("ace/theme/monokai");
|
||||||
editor.session.setMode("ace/mode/javascript");
|
editor.session.setMode("ace/mode/json");
|
||||||
|
|
||||||
var parser;
|
var parser;
|
||||||
|
|
||||||
|
|
|
||||||
128
js/parser_test.js
Normal file
128
js/parser_test.js
Normal file
|
|
@ -0,0 +1,128 @@
|
||||||
|
var atlasEditor = ace.edit("atlas-config-editor");
|
||||||
|
atlasEditor.setTheme("ace/theme/monokai");
|
||||||
|
atlasEditor.session.setMode("ace/mode/text");
|
||||||
|
atlasEditor.session.setUseWrapMode(true);
|
||||||
|
|
||||||
|
var jsonEditor = ace.edit("json-config-editor");
|
||||||
|
jsonEditor.setTheme("ace/theme/monokai");
|
||||||
|
jsonEditor.session.setMode("ace/mode/json");
|
||||||
|
|
||||||
|
var parser;
|
||||||
|
|
||||||
|
$.get('js/atlas.pegjs', function (data) {
|
||||||
|
parser = PEG.buildParser(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
ko.applyBindings({});
|
||||||
|
|
||||||
|
function fromAtlasToJson() {
|
||||||
|
var input = atlasEditor.getValue();
|
||||||
|
var output = parser.parse(input);
|
||||||
|
jsonEditor.setValue(ko.toJSON(output, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromJsonToAtlas() {
|
||||||
|
var input = JSON.parse(jsonEditor.getValue());
|
||||||
|
|
||||||
|
console.log(input);
|
||||||
|
|
||||||
|
var output = deparseJson(input);
|
||||||
|
|
||||||
|
console.log(output);
|
||||||
|
atlasEditor.setValue(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deparseJson(input) {
|
||||||
|
switch (typeof input) {
|
||||||
|
case "object":
|
||||||
|
return deparseObject(input);
|
||||||
|
case "number":
|
||||||
|
return deparseNumber(input);
|
||||||
|
case "string":
|
||||||
|
return deparseString(input);
|
||||||
|
case "undefined":
|
||||||
|
return "";
|
||||||
|
case "boolean":
|
||||||
|
return deparseBoolean(input);
|
||||||
|
default:
|
||||||
|
console.log("Unknown type for input", input);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deparseObject(input) {
|
||||||
|
if (Array.isArray(input)) {
|
||||||
|
return deparseArray(input);
|
||||||
|
}
|
||||||
|
if (input === null) {
|
||||||
|
return "None";
|
||||||
|
}
|
||||||
|
|
||||||
|
var beginObject = '(';
|
||||||
|
var endObject = ')';
|
||||||
|
var nameSeparator = '=';
|
||||||
|
var valueSeparator = ',';
|
||||||
|
|
||||||
|
var output = '';
|
||||||
|
output += beginObject;
|
||||||
|
|
||||||
|
Object.keys(input).forEach(function (key, idx, array) {
|
||||||
|
output += key;
|
||||||
|
output += nameSeparator;
|
||||||
|
output += deparseJson(input[key]);
|
||||||
|
|
||||||
|
if (idx !== array.length - 1) {
|
||||||
|
// Not the last item
|
||||||
|
output += valueSeparator
|
||||||
|
}
|
||||||
|
});
|
||||||
|
output += endObject;
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deparseArray(input) {
|
||||||
|
// We have one funky array option, where its 2 values and one of them is a recognised class.
|
||||||
|
if (input[0] === "BlueprintGeneratedClass") {
|
||||||
|
return "BlueprintGeneratedClass" + "'" + input[1] + "'";
|
||||||
|
}
|
||||||
|
if (input[0] === "SoundWave") {
|
||||||
|
return "SoundWave" + "'" + input[1] + "'"
|
||||||
|
}
|
||||||
|
|
||||||
|
var beginObject = '(';
|
||||||
|
var endObject = ')';
|
||||||
|
var valueSeparator = ',';
|
||||||
|
|
||||||
|
var output = '';
|
||||||
|
output += beginObject;
|
||||||
|
|
||||||
|
input.forEach(function (data, idx, array) {
|
||||||
|
output += deparseJson(data);
|
||||||
|
|
||||||
|
if (idx !== array.length - 1) {
|
||||||
|
output += valueSeparator;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
output += endObject;
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deparseNumber(input) {
|
||||||
|
// All numbers seem to be a string to 6 decimal places
|
||||||
|
return Number(input).toFixed(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deparseString(input) {
|
||||||
|
// We need to re-encode the strings properly
|
||||||
|
return JSON.stringify(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deparseBoolean(input) {
|
||||||
|
if ( input ) {
|
||||||
|
return 'True';
|
||||||
|
} else {
|
||||||
|
return 'False';
|
||||||
|
}
|
||||||
|
}
|
||||||
68
parser_test.html
Normal file
68
parser_test.html
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Parser Testing</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
|
||||||
|
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
|
||||||
|
crossorigin="anonymous">
|
||||||
|
<style>
|
||||||
|
#atlas-config-editor, #json-config-editor {
|
||||||
|
width: 100%;
|
||||||
|
height: 40vh;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar bg-light">
|
||||||
|
<a class="navbar-brand" href="#">Atlas Config Parser Test</a>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<span>Atlas Crazy Config</span>
|
||||||
|
<div id="atlas-config-editor">(SoundOverrides=(NavalCombatMusicDay=SoundWave'/Game/Atlas/Music/ATL_SeaCombatArcticDay_v1.ATL_SeaCombatArcticDay_v1',NavalCombatMusicNight=SoundWave'/Game/Atlas/Music/ATL_SeaCombatArcticNight_v1.ATL_SeaCombatArcticNight_v1',CombatMusicDay=SoundWave'/Game/Atlas/Music/ATL_LandCombatArcticDay_v2.ATL_LandCombatArcticDay_v2',CombatMusicNight=SoundWave'/Game/Atlas/Music/ATL_LandCombatArcticNight_v1.ATL_LandCombatArcticNight_v1',CombatMusicDay_Heavy=SoundWave'/Game/Atlas/Music/ATL_LandCombatArcticDay_v2.ATL_LandCombatArcticDay_v2',CombatMusicNight_Heavy=SoundWave'/Game/Atlas/Music/ATL_LandCombatArcticNight_v1.ATL_LandCombatArcticNight_v1',Sound_TransitionToMorning=SoundWave'/Game/Atlas/Stingers/ATL_Sting_ArcticMorning.ATL_Sting_ArcticMorning',Sound_TransitionToMidDay=SoundWave'/Game/Atlas/Stingers/ATL_Sting_ArcticNoon.ATL_Sting_ArcticNoon',Sound_TransitionToNight=SoundWave'/Game/Atlas/Stingers/ATL_Sting_ArcticNight.ATL_Sting_ArcticNight',Sound_SetSail=SoundWave'/Game/Atlas/Stingers/ATL_Sting_ArcticSetSail.ATL_Sting_ArcticSetSail',Sound_Respawn=None,Sound_CreateNewCharacter=None),OceanHarvestEntriesOverrides=((RenderComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/Render_Components/OceanHarvestable_Seaweed_Tall_35.OceanHarvestable_Seaweed_Tall_35_C',HarvestComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/HarvestComponents/00_OceanFloor/HerbHarvestComponent_RedAlgae.HerbHarvestComponent_RedAlgae_C',Weight=0.100000,RandomOffsetPercentageOfPlacementInterval=3.000000),(RenderComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/Render_Components/OceanHarvestable_Seaweed_Tall_36.OceanHarvestable_Seaweed_Tall_36_C',HarvestComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/HarvestComponents/00_OceanFloor/HerbHarvestComponent_RedAlgae.HerbHarvestComponent_RedAlgae_C',Weight=0.010000,RandomOffsetPercentageOfPlacementInterval=5.400000),(RenderComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/Render_Components/OceanHarvestable_Seaweed_Tall_37.OceanHarvestable_Seaweed_Tall_37_C',HarvestComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/HarvestComponents/00_OceanFloor/FiberHarvestComponent_Seaweed.FiberHarvestComponent_Seaweed_C',Weight=0.200000,RandomOffsetPercentageOfPlacementInterval=2.100000),(RenderComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/Render_Components/OceanHarvestable_Seaweed_Short_16.OceanHarvestable_Seaweed_Short_16_C',HarvestComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/HarvestComponents/00_OceanFloor/FiberHarvestComponent_Seaweed.FiberHarvestComponent_Seaweed_C',Weight=0.010000,RandomOffsetPercentageOfPlacementInterval=1.400000),(RenderComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/Render_Components/OceanHarvestable_Seaweed_Short_40.OceanHarvestable_Seaweed_Short_40_C',HarvestComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/HarvestComponents/00_OceanFloor/FiberHarvestComponent_Seaweed.FiberHarvestComponent_Seaweed_C',Weight=0.050000,RandomOffsetPercentageOfPlacementInterval=4.000000),(RenderComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/Render_Components/OceanHarvestable_Seaweed_Short_41.OceanHarvestable_Seaweed_Short_41_C',HarvestComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/HarvestComponents/00_OceanFloor/FiberHarvestComponent_Seaweed.FiberHarvestComponent_Seaweed_C',Weight=0.400000,RandomOffsetPercentageOfPlacementInterval=0.600000),(RenderComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/Render_Components/OceanHarvestable_Seaweed_Short_42.OceanHarvestable_Seaweed_Short_42_C',HarvestComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/HarvestComponents/00_OceanFloor/FiberHarvestComponent_Seaweed.FiberHarvestComponent_Seaweed_C',Weight=0.800000,RandomOffsetPercentageOfPlacementInterval=0.800000),(RenderComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/Render_Components/OceanHarvestable_Seaweed_Short_43.OceanHarvestable_Seaweed_Short_43_C',HarvestComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/HarvestComponents/00_OceanFloor/FiberHarvestComponent_Seaweed.FiberHarvestComponent_Seaweed_C',Weight=0.400000,RandomOffsetPercentageOfPlacementInterval=0.500000),(RenderComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/Render_Components/OceanHarvestable_Coral_Brain.OceanHarvestable_Coral_Brain_C',HarvestComponent=BlueprintGeneratedClass'/Game/Atlas/AtlasCoreBP/HarvestComponents/00_OceanFloor/CoralHarvestComponent_Brain.CoralHarvestComponent_Brain_C',Weight=0.500000,RandomOffsetPercentageOfPlacementInterval=10.000000)),bDisableClaimFlags=False)</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<button class="btn btn-primary" data-bind="click: fromAtlasToJson">From Atlas to JSON</button>
|
||||||
|
<button class="btn btn-primary" data-bind="click: fromJsonToAtlas">From JSON to Atlas</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<span>JSON Interpretation</span>
|
||||||
|
<div id="json-config-editor"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
|
||||||
|
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
|
||||||
|
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
|
||||||
|
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.5/ace.js"
|
||||||
|
integrity="sha256-5Xkhn3k/1rbXB+Q/DX/2RuAtaB4dRRyQvMs83prFjpM="
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.5.0/knockout-min.js"
|
||||||
|
integrity="sha256-Tjl7WVgF1hgGMgUKZZfzmxOrtoSf8qltZ9wMujjGNQk="
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout.mapping/2.4.1/knockout.mapping.min.js"
|
||||||
|
integrity="sha256-gaGobNk1cPaj0abcVmyZxUYgCPsueCJwN5i4DjC4BS0="
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/pegjs/0.9.0/peg.js"
|
||||||
|
integrity="sha256-cwfR02g6XnRmRxZLIwyChnsn4ODrS2uSl6eODJkjrnY="
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="js/parser_test.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue