Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Durtur committed Apr 21, 2021
1 parent 2f0e867 commit fe95d2c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 47 deletions.
14 changes: 7 additions & 7 deletions app/database.html
Original file line number Diff line number Diff line change
Expand Up @@ -448,20 +448,20 @@ <h2 class="edit_header_name">New item</h2>
<div class="column">
<input type="text" class="jsonAttributeI brown monster_attribute_chapter_label" value="Name"
readonly tabindex="-1">
<input type="text" tabindex=1 class="jsonValueI db_name_field object_nameI">
<input type="text" tabindex=1 class="jsonValueI db_name_field object_nameI additem_name">
</div>

<div class="row monster_stat_row">
<div class="column">
<input type="text" class="jsonAttributeI readonly_monster_attr" value="Rarity" readonly
<input type="text" class="jsonAttributeI readonly_monster_attr " value="Rarity" readonly
tabindex="-1">
<input type="text" tabindex=1 class="jsonValueI" id="item_rarity_input">
<input type="text" tabindex=1 class="jsonValueI additem_rarity" id="item_rarity_input">
</div>

<div class="column">
<input type="text" class="jsonAttributeI readonly_monster_attr" title="Attribute"
placeholder="Attribute name" value="Type" readonly tabindex="-1">
<input type="text" tabindex=1 class="jsonValueI" id="item_type_input">
<input type="text" tabindex=1 class="jsonValueI additem_type" id="item_type_input">
</div>


Expand All @@ -470,17 +470,17 @@ <h2 class="edit_header_name">New item</h2>
<input type="text" class=" readonly_monster_attr" value="Requires attunement" readonly tabindex="-1">
<div class="row attunement_row">
<label class="container_for_checkbox">
<input type="checkbox" tabindex=1 class="center " id="additem_requires_attunement"
<input type="checkbox" tabindex=1 class="center additem_requires_attunement" id="additem_requires_attunement"
title="Item requires attunement">
<span class="checkmark"></span>
</label>
<input type ="text" class = "" id ="additem_requires_attunement_by" placeholder="Anyone can attune">
<input type ="text" class = "additem_requires_attunement_by" id ="additem_requires_attunement_by" placeholder="Anyone can attune">
</div>
</div>
<div class="column">
<input type="text" class="jsonAttributeI brown monster_attribute_chapter_label"
value="Description" readonly tabindex="-1">
<textarea tabindex=1 class="jsonValueI" style="min-height: 140px;"> </textarea>
<textarea tabindex=1 class="jsonValueI additem_description" style="min-height: 140px;"> </textarea>
</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion app/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function generateHTMLTable(jsonObj) {
var jsonObjValues = Object.values(jsonObj);
//filter out empty arrays

console.log(jsonObjValues)

var expectedLength = jsonObjValues[0].length;
for (var i = 1; i < jsonObjValues.length; i++) {
if (jsonObjValues[i].length != expectedLength) {
Expand Down
49 changes: 29 additions & 20 deletions app/js/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ipcRenderer.on('update-autofill-complete', function () {

});

var selectedConditionImagePath;

$(document).ready(function () {
dataAccess.getSettings(sett => {
settings = sett;
Expand Down Expand Up @@ -92,14 +92,15 @@ $(document).ready(function () {
document.querySelector("#encounter_table_header_row").addEventListener("click", sortEncounterMasterList);

document.getElementById("condition_image_picker").onclick = function (e) {
selectedConditionImagePath = dialog.showOpenDialogSync(
var selectedConditionImagePath = dialog.showOpenDialogSync(
remote.getCurrentWindow(), {
properties: ['openFile'],
message: "Choose picture location",
filters: [{ name: 'Images', extensions: ['jpg', 'png', 'gif'] }]
});
if (selectedConditionImagePath == null)
return;
selectedConditionImagePath = selectedConditionImagePath[0];
var imgEle = document.getElementById("condition_image_picker");
imgEle.setAttribute("src", selectedConditionImagePath);
}
Expand Down Expand Up @@ -235,9 +236,9 @@ function populateDropdowns() {
classList.add(`by ${prefix} ${classStr}`);
});
new Awesomplete(document.getElementById("additem_requires_attunement_by"), { list: [...classList], autoFirst: true, minChars: 0, sort: false });
document.getElementById("additem_requires_attunement_by").addEventListener("awesomplete-selectcomplete", function(e){
document.getElementById("additem_requires_attunement_by").addEventListener("awesomplete-selectcomplete", function (e) {
var checkbox = document.getElementById("additem_requires_attunement");
if(!checkbox.checked)checkbox.checked = true;
if (!checkbox.checked) checkbox.checked = true;
});
populateAddableFieldDropdowns();
var sizeList = [];
Expand Down Expand Up @@ -1558,7 +1559,7 @@ function editCopyHelper(entryId, isEdit) {
entry = loadedData.find(x => {
return x.id == entryId
});
if(!entry.description)entry.description = "";
if (!entry.description) entry.description = "";
}

if (isEdit) {
Expand Down Expand Up @@ -1616,6 +1617,8 @@ function editObject(dataObject, letter) {
} else if (letter === "") {
addTags(dataObject);
addACSource(dataObject);
} else if (letter == "I") {
return editItem(dataObject);
}

var valuesElements = [...document.querySelectorAll(".jsonValue" + letter)];
Expand Down Expand Up @@ -1766,8 +1769,18 @@ function editObject(dataObject, letter) {
valueElement.value = val ? val : "";
}

function editItem(dataObject) {
["name", "description", "type", "rarity"].forEach(prop => {
document.querySelector(`.additem_${prop}`).value = dataObject[prop];
});
document.querySelector(".additem_requires_attunement").checked = dataObject.requires_attunement;
document.querySelector(".additem_requires_attunement_by").value = dataObject.requires_attunement_by || "";
if (dataObject.table)
populateTable(dataObject.table);
}

function editEncounter(dataObject) {
console.log(dataObject)

var nameField = document.querySelector(".object_nameE");
nameField.value = dataObject.name;
document.querySelector(".add_encounter_description").value = dataObject.description;
Expand Down Expand Up @@ -2365,6 +2378,10 @@ function saveHomebrew() {
} else if (tab == "encounters") {
thingyToSave.encounter_xp_value = parseInt(document.querySelector("#encounter_challenge_calculator_value").value);
}
else if (tab == "items") {
thingyToSave.requires_attunement = document.querySelector(".additem_requires_attunement").checked;
thingyToSave.requires_attunement_by = document.querySelector(".additem_requires_attunement_by").value || "";
}
//Populate normal attributes

for (var i = 0; i < valueBoxes.length; i++) {
Expand Down Expand Up @@ -2437,7 +2454,7 @@ function saveHomebrew() {

if (Object.keys(tableObject).length != 0) thingyToSave.table = tableObject;
} else if (tab == "conditions") {
thingyToSave.condition_background_location = selectedConditionImagePath;
thingyToSave.condition_background_location = document.querySelector("#condition_image_picker").getAttribute("src");
}

//Search for existing entry
Expand All @@ -2455,19 +2472,11 @@ function saveHomebrew() {

function handleDataSave(thingyToSave, getFunction, setFunction) {
getFunction(function (data) {
console.log(data.length);
if (currentEntry) {
data = data.filter(d => d.name != currentEntry.name)
}
console.log(thingyToSave.name)
var collisionIndex = indexOfName(data, thingyToSave.name);

if (collisionIndex != -1) {
if (window.confirm(thingyToSave.name + " already found in database. Do you wish to overwrite?")) {
data.splice(collisionIndex, 1);
} else {
return false;
}
data = data.filter(d => d.id != currentEntry.id)
}
console.log(data.length);

data.push(thingyToSave);
data = data.sort(function (a, b) {
Expand All @@ -2494,7 +2503,7 @@ function saveHomebrew() {
}

tokenRemoveQueue = [];

window.setTimeout(function () {
dataAccess.getTags(function (tags) {
monsterTags.list = tags;
Expand All @@ -2505,7 +2514,7 @@ function saveHomebrew() {

let window2 = remote.getGlobal('mainWindow');
if (window2) window2.webContents.send('update-autofill');

});

})
Expand Down
36 changes: 18 additions & 18 deletions app/js/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,13 @@ document.addEventListener("DOMContentLoaded", function () {
});

function rerollNpc(key) {
console.log(key)

var dropDownGender = document.querySelector("#choose_gender");
var dropDownType = document.querySelector("#choose_type_generated_creature");
var type = dropDownType.options[dropDownType.selectedIndex].value;
var gender = dropDownGender.options[dropDownGender.selectedIndex].value;
var dropDownSet = document.querySelector("#choose_nameset");
gender = gender == "any" ? pickOne(["male", "female"]) : gender;
var set = dropDownSet.options[dropDownSet.selectedIndex].value;
dataAccess.getGeneratorData(function (data) {
var foundNameSet = null;
Expand All @@ -387,14 +388,13 @@ function rerollNpc(key) {
}
var generatedNameTextField = document.querySelector("#generated_npc_name");
if (key == "name") {
gender = gender == "any" ? pickOne(["male", "female"]) : gender;

var values = generateNPC(data, gender, foundNameSet, type)
replaceName(values);
} else if (key == "creature") {
console.log(generatedNameTextField.innerHTML)
var names = generatedNameTextField.innerHTML.split(" ");
if (names[1] == null) names[1] = "";
var values = generateNPC(data, "male", { male: [names[0]], lastnames: [names[1]] }, type)
var values = generateNPC(data,gender, { male: [names[0]], lastnames: [names[1]], female: [names[0]], lastnames: [names[1]] }, type)
if (values.age)
values.profession += ` (${values.age})`;
replaceDescription(values);
Expand Down Expand Up @@ -515,7 +515,7 @@ function createCreatureTreeList(object) {
} else if (evt.keyCode == 13) {
if (evt.target.value != "") {
var parentList = input.closest(".treeview_nested");
console.log("Want to add")

window.setTimeout(() => {
editingListAttribute = false;

Expand All @@ -539,7 +539,7 @@ function createCreatureTreeList(object) {
function doStopEditing(evt) {
editingListAttribute = false;
var oldText = evt.target.getAttribute("data-old_value");
console.log(evt)

var text = evt.target.value;
var parent = evt.target.parentNode;
if (parent.contains(evt.target)) parent.removeChild(evt.target);
Expand Down Expand Up @@ -863,7 +863,7 @@ function refreshMonsterListInputs() {
if (allInputValues.indexOf(awes.input.value) < 0)
allInputValues.push(awes.input.value)
});
console.log(allInputValues)

encounterSetAwesompletes.forEach(awes => {
allInputValues.forEach(value => {
if (awes._list.indexOf(value) >= 0) {
Expand Down Expand Up @@ -896,7 +896,7 @@ function deleteEncounterSet() {
dataAccess.getRandomTables(function (data) {
var obj = data;
data = obj.encounter_sets;
console.log(data, data[encounterSetName], encounterSetName)

if (data[encounterSetName] == null) return;
var response = dialog.showMessageBox(
remote.getCurrentWindow(),
Expand All @@ -913,7 +913,7 @@ function deleteEncounterSet() {
encounterSetName = unSerialize(encounterSetName);
obj.encounter_sets = data;
dataAccess.setRandomTables(obj, function (data) {
console.log(encounterSetAwesomplete._list)

if (encounterSetAwesomplete._list.indexOf(encounterSetName) > 0)
encounterSetAwesomplete._list.splice(encounterSetAwesomplete._list.indexOf(encounterSetName), 1)
clearRandomTableContainer();
Expand Down Expand Up @@ -961,7 +961,7 @@ function saveEncounterSet() {
return;
}
document.getElementById("delete_encounter_set_button").classList.remove("hidden");
console.log("saved")

$('#save_success').finish().fadeIn("fast").delay(2500).fadeOut("slow");
document.getElementById("encounter_set_name_input").value = "";
clearRandomTableContainer();
Expand Down Expand Up @@ -1016,11 +1016,11 @@ function dumpCreateTable(evt) {
function createProbabilityFromTableString(probString, fallback) {
var values = probString.split(/[+|-]+/);
var finalValue;
console.log(values)

if (values.length > 1) {
var higherNumber = Math.max(parseInt(values[0]), parseInt(values[1]));
var lowerNumber = Math.min(parseInt(values[0]), parseInt(values[1]));
console.log(higherNumber, lowerNumber)

finalValue = higherNumber - lowerNumber;
if (isNaN(finalValue))
return fallback;
Expand Down Expand Up @@ -1116,7 +1116,7 @@ function deleteRandomTable() {
dataAccess.getRandomTables(function (data) {
var obj = data;
data = obj.tables;
console.log(data);

if (!data || data[tblName] == null) return;
var response = dialog.showMessageBoxSync(
remote.getCurrentWindow(),
Expand All @@ -1127,15 +1127,15 @@ function deleteRandomTable() {
message: "Do you wish to delete table " + input.value + " ?"
}
);
console.log(response);

if (response != 0)
return;
console.log(data[tblName])

delete data[tblName];

obj.tables = data;
dataAccess.setRandomTables(obj, function (data) {
console.log(input.value)

if (randomTableNames.indexOf(input.value) < 0) {
randomTableNames.splice(randomTableNames.indexOf(input.value), 1);
}
Expand Down Expand Up @@ -1182,15 +1182,15 @@ function saveRandomTable() {
obj.followup_table = children[3].getElementsByTagName("input")[0].value ? serialize(children[3].getElementsByTagName("input")[0].value) : "";
arr.push(obj);
}
console.log(rows)

var tblName = serialize(input.value);
dataAccess.getRandomTables(function (data) {
var obj = data;
data = obj.tables;
if (data == null) data = {};
data[tblName] = arr;
obj.tables = data;
console.log(obj);

dataAccess.setRandomTables(obj, function (data, err) {
if (err) {
$('#save_failed').fadeIn("fast").delay(2500).fadeOut("slow");
Expand Down
4 changes: 3 additions & 1 deletion app/js/statblockpresenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ var statblockPresenter = function () {

function addTable() {
if (!statblock_table) return;
statblock.append(generateHTMLTable(statblock_table));
var table = generateHTMLTable(statblock_table);
[... table.querySelectorAll("td")].forEach(x=> x.innerHTML = marked(x.innerHTML));
statblock.append(table);
}

function addSpeed() {
Expand Down
1 change: 1 addition & 0 deletions app/mappingTool/mappingTool.css
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ li {
.condition_effect {
height: 50%;
width: 50%;
max-height: 2em;
max-width: 2em;
position: relative;
margin-left: -30%;
Expand Down
1 change: 1 addition & 0 deletions data/generators/names.json
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,7 @@
"sees ghostly silhouettes at the edge of _hisher vision. Who can say if they are real..",
"sells herbal \"remedies\" on the black market",
"speaks quite fast; sometimes it's hard to follow what _heshe is saying",
"smokes a particular brand of cheap cigars",
"spends most of _hisher nights at the local tavern",
"spies on the local populace for the ruling powers",
"stole a horse as a teenager, and that's enough excitement for a lifetime",
Expand Down

0 comments on commit fe95d2c

Please sign in to comment.