Fixed: prepend charname before for= and id=. One problem remains, sometimes q_all and wp_all don't check when all quests or wps are checked

This commit is contained in:
Hash Borgir 2023-06-12 02:23:35 -06:00
parent 46a7bbd378
commit e9fdeede11
2 changed files with 47 additions and 110 deletions

View File

@ -1,29 +1,29 @@
/* /*
Copyright (C) 2021 Hash Borgir Copyright (C) 2021 Hash Borgir
This file is part of D2Modder This file is part of D2Modder
Redistribution and use in source and binary forms, with Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above * Redistributions of source code must retain the above
copyright notice, this list of conditions and the copyright notice, this list of conditions and the
following disclaimer. following disclaimer.
* Redistributions in binary form must reproduce the above * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other following disclaimer in the documentation and/or other
materials provided with the distribution. materials provided with the distribution.
* This software must not be used for commercial purposes * This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited * without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent. * without my express knowledge and consent.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY! but WITHOUT ANY WARRANTY!
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@ -37,7 +37,7 @@
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
// highlight json dump for item debugger // highlight json dump for item debugger
function syntaxHighlight(json) { function syntaxHighlight(json) {
@ -400,11 +400,11 @@ $(document).ready(function () {
return "/saveCharacter.php?cmd=" + cmd + "&name=" + name + "&value=" + value + "&filePath=" + filePath; return "/saveCharacter.php?cmd=" + cmd + "&name=" + name + "&value=" + value + "&filePath=" + filePath;
} }
$(".charform input[name='Difficulty'], .charform .skill, #CharacterName, #CharacterClass, #CharacterLevel, #CharacterClass, .stats input, .form-check-input, #statsdiv input,#setallskills,.wp_all,.q_all").change(function () { $(".charform input[name='Difficulty'], .charform .skill, .CharacterName, .CharacterClass, .CharacterLevel, .stats input, .form-check-input, .statsdiv input,.setallskills").change(function () {
var name = $(this).attr("name"); var name = $(this).attr("name");
var newValue = $(this).val(); var newValue = $(this).val();
var cmd = $(this).attr("cmd") || $(this).attr("id") || name; var cmd = $(this).attr("cmd") || name;
var parentFormId = $(this).closest("form").attr("id"); var parentFormId = $(this).closest("form").attr("id");
var parentFormClass = $(this).closest("form").attr("class"); var parentFormClass = $(this).closest("form").attr("class");
@ -424,41 +424,31 @@ $(document).ready(function () {
}); });
$('.q_all, .wp_all').click(function () { $('.q_all, .wp_all').click(function () {
var parentFormId = $(this).closest("form").attr("id"); var parentForm = $(this).closest('form');
var targetClass = $(this).attr('class') === 'q_all' ? `#${parentFormId} .qcheck` : `#${parentFormId} .wpcheck`; var targetClass = $(this).hasClass('q_all') ? '.qcheck' : '.wpcheck';
var isChecked = $(this).prop('checked'); var isChecked = $(this).prop('checked');
$(targetClass).prop('checked', isChecked); parentForm.find(targetClass).prop('checked', isChecked);
}); });
$('.qcheck').change(function () {
var parentFormId = $(this).closest("form").attr("id");
var qallChecked = $(`#${parentFormId} .qcheck:checked`).length === $(`#${parentFormId} .qcheck`).length;
if (qallChecked == true) {
var qchecked = 'checked';
var val = 1;
} else {
qchecked = '';
var val = 0;
}
$(`#${parentFormId} .q_all`).prop('checked', qchecked).val(val);
});
$('.wpcheck').change(function () { $('.wpcheck').change(function () {
var parentFormId = $(this).closest("form").attr("id"); var parentFormId = $(this).closest("form").attr("id");
var wpallChecked = $(`#${parentFormId} .wpcheck:checked`).length === $(`#${parentFormId} .wpcheck`).length; var wpallChecked = $(`#${parentFormId} .wpcheck:checked`).length === $(`#${parentFormId} .wpcheck`).length;
if (wpallChecked == true) { var wpchecked = wpallChecked ? 'checked' : '';
var wpchecked = 'checked'; var val = wpallChecked ? 1 : 0;
var val = 1;
} else {
wpchecked = '';
var val = 0;
}
$(`#${parentFormId} .wp_all`).prop('checked', wpchecked).val(val); $(`#${parentFormId} .wp_all`).prop('checked', wpchecked).val(val);
}); });
$('#setallskills').change(function () { $('.qcheck').change(function () {
var parentFormId = $(this).closest("form").attr("id");
var qallChecked = $(`#${parentFormId} .qcheck:checked`).length === $(`#${parentFormId} .qcheck`).length;
var qchecked = qallChecked ? 'checked' : '';
var val = qallChecked ? 1 : 0;
$(`#${parentFormId} .q_all`).prop('checked', qchecked).val(val);
});
$('.setallskills').change(function () {
var value = $(this).val(); var value = $(this).val();
var parentFormId = $(this).closest("form").attr("id"); var parentFormId = $(this).closest("form").attr("id");
$(`#${parentFormId} .skill`).attr('value', value); $(`#${parentFormId} .skill`).attr('value', value);

View File

@ -67,8 +67,8 @@ EOT;
$checked = ($v == 1) ? 'checked' : ''; $checked = ($v == 1) ? 'checked' : '';
$quests .= "<div class='qcheckgroup'>"; $quests .= "<div class='qcheckgroup'>";
$quests .= "<input class='qcheck' diff='{$difficulty}' type='checkbox' value='1' name='{$k}' id='{$k}' {$checked}>"; $quests .= "<input class='qcheck' diff='{$difficulty}' type='checkbox' value='1' name='{$k}' id='{$c->cData['CharacterName']}-{$k}' {$checked}>";
$quests .= "<label for='{$k}'>{$kD}</label><br>"; $quests .= "<label for='{$c->cData['CharacterName']}-{$k}'>{$kD}</label><br>";
$quests .= "</div>"; $quests .= "</div>";
} }
@ -112,8 +112,8 @@ EOT;
$checked = ($v == 1 && $k != '') ? 'checked ' : ''; $checked = ($v == 1 && $k != '') ? 'checked ' : '';
$wps .= "<div class='wcheckgroup'>"; $wps .= "<div class='wcheckgroup'>";
$wps .= "<input diff='{$diff}' class='wpcheck' type='checkbox' value='1' name='{$wp_count}' id='{$k}' {$checked}>"; $wps .= "<input diff='{$diff}' class='wpcheck' type='checkbox' value='1' name='{$wp_count}' id='{$c->cData['CharacterName']}-{$k}' {$checked}>";
$wps .= "<label for='{$k}'>{$kD}</label><br>"; $wps .= "<label for='{$c->cData['CharacterName']}-{$k}'>{$kD}</label><br>";
$wps .= "</div>"; $wps .= "</div>";
$wp_count++; $wp_count++;
} }
@ -146,8 +146,8 @@ EOT;
foreach ($difficulties as $difficulty => $id) { foreach ($difficulties as $difficulty => $id) {
$checked = ($c->cData['Difficulty'][$difficulty] == 1) ? 'checked' : ''; $checked = ($c->cData['Difficulty'][$difficulty] == 1) ? 'checked' : '';
$radio .= "<input $checked type='radio' id='$difficulty' name='Difficulty' value='$id'>"; $radio .= "<input $checked type='radio' id='{$c->cData['CharacterName']}-$difficulty' name='Difficulty' value='$id' class='$difficulty'>";
$radio .= "<label for='$difficulty'>$difficulty</label><br>"; $radio .= "<label for='{$c->cData['CharacterName']}-$difficulty'>$difficulty</label><br>";
} }
$skills = ''; $skills = '';
@ -221,8 +221,8 @@ EOT;
$checkboxes .= <<<HTML $checkboxes .= <<<HTML
<div class="col"> <div class="col">
<div class="form-check"> <div class="form-check">
<label class="form-check-label" for="{$status}">{$status}: </label><br> <label class="form-check-label" for="{$c->cData['CharacterName']}-{$status}">{$status}: </label><br>
<input class="form-check-input" {$checked} type="checkbox" id="{$status}" name="CharacterStatus[{$status}]" value="{$c->cData[$dataKey]}"> <input class="form-check-input" {$checked} type="checkbox" id="{$c->cData['CharacterName']}-{$status}" name="CharacterStatus[{$status}]" value="{$c->cData[$dataKey]}">
</div> </div>
</div> </div>
HTML; HTML;
@ -253,10 +253,10 @@ HTML;
$defaultValue = isset($c->cData['stats'][$stat]) ? $c->cData['stats'][$stat] : 0; $defaultValue = isset($c->cData['stats'][$stat]) ? $c->cData['stats'][$stat] : 0;
// Create an HTML input for the stat // Create an HTML input for the stat
$stats .= '<div class="stats" id="statsdiv" style="border:1px solid #ccc;"><input cmd="stats" type="number" id="' . $stat . '" name="' . $stat . '" max="' . $maxValue . '" value="' . $defaultValue . '">'; $stats .= '<div class="stats" id="statsdiv" class="statsdiv" style="border:1px solid #ccc;"><input cmd="stats" type="number" id="'. "{$c->cData['CharacterName']}-" . $stat . '" name="' . $stat . '" max="' . $maxValue . '" value="' . $defaultValue . '" class="' . $stat . '">';
// Create an HTML label for the stat // Create an HTML label for the stat
$stats .= '<label for="' . $stat . '">' . ucfirst($stat) . ':<br> Max Value - ' . $maxValue . '</label><br></div>'; $stats .= '<label for="' . "{$c->cData['CharacterName']}-" . $stat . '">' . ucfirst($stat) . ':<br> Max Value - ' . $maxValue . '</label><br></div>';
} }
@ -377,14 +377,13 @@ HTML;
<div class="container" style="font-size: 14px;"> <div class="container" style="font-size: 14px;">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<!--<input class="btn btn-danger" style="" type="submit" value="Save Character">
<img src="/img/chars/{$c->cData['CharacterClass']}.gif" style='height: 64px; width: 64px;'><br>--> Name: <input type="text" class="CharacterName" id="CharacterName" name="CharacterName" maxlength="16" value="{$c->cData['CharacterName']}" pattern="[A-Za-z0-9_-]+" title="Character name can only contain alphabets, numbers, underscore, and dash." data-oldvalue="{$c->cData['CharacterName']}">
Name: <input type="text" id="CharacterName" name="CharacterName" maxlength="16" value="{$c->cData['CharacterName']}" pattern="[A-Za-z0-9_-]+" title="Character name can only contain alphabets, numbers, underscore, and dash." data-oldvalue="{$c->cData['CharacterName']}">
<br> <br>
<select id='CharacterClass' name='CharacterClass'> <select id='CharacterClass' class='CharacterClass' name='CharacterClass'>
$option $option
</select><br> </select><br>
Character Level: <input style="border: 1px solid black;width: 54px;" type="number" name="CharacterLevel" id="CharacterLevel" value="{$c->cData['CharacterLevel']}"> Character Level: <input style="border: 1px solid black;width: 54px;" type="number" name="CharacterLevel" class="CharacterLevel" id="CharacterLevel" value="{$c->cData['CharacterLevel']}">
<hr> <hr>
<div style="background: #efe;"> <div style="background: #efe;">
Difficulty:<br> Difficulty:<br>
@ -398,66 +397,14 @@ $checkboxes
<br><br> <br><br>
</div> </div>
<hr>
<!-- STATS
<div class="stats">
<div class="form-row" style="background: #eed;">
<div class="form-group col-md-3">
<label for="strength">Strength:</label>
<input type="number" class="form-control" id="strength" name="strength" min="1" max="511" value="{$c->cData['stats']['strength']}" required>
</div>
<div class="form-group col-md-3">
<label for="dexterity">Dexterity:</label>
<input type="number" class="form-control" id="dexterity" name="dexterity" min="1" max="511" value="{$c->cData['stats']['dexterity']}" required>
</div>
<div class="form-group col-md-3">
<label for="vitality">Vitality:</label>
<input type="number" class="form-control" id="vitality" name="vitality" min="1" max="511" value="{$c->cData['stats']['vitality']}" required>
</div>
<div class="form-group col-md-3">
<label for="energy">Energy:</label>
<input type="number" class="form-control" id="energy" name="energy" min="1" max="511" value="{$c->cData['stats']['energy']}" required>
</div>
</div>
<div class="form-row" style="background: #eee;">
<div class="form-group col-md-3">
<label for="hitpoints">Hitpoints:</label>
<input type="number" class="form-control" id="hitpoints" name="hitpoints" min="1" max="2097151" value="{$c->cData['stats']['hitpoints']}" required>
</div>
<div class="form-group col-md-3">
<label for="maxhp">Max HP:</label>
<input type="number" class="form-control" id="maxhp" name="maxhp" min="1" max="2097151" value="{$c->cData['stats']['maxhp']}" required>
</div>
<div class="form-group col-md-3">
<label for="mana">Mana:</label>
<input type="number" class="form-control" id="mana" name="mana" min="1" max="2097151" value="{$c->cData['stats']['mana']}" required>
</div>
<div class="form-group col-md-3">
<label for="maxmana">Max Mana:</label>
<input type="number" class="form-control" id="maxmana" name="maxmana" min="1" max="" value="{$c->cData['stats']['maxmana']}" required>
</div>
</div>
<div class="form-row" style="background: #eed;">
<div class="form-group col-md-6">
<label for="stamina">Stamina:</label>
<input type="number" class="form-control" id="stamina" name="stamina" min="1" max="2097151" value="{$c->cData['stats']['stamina']}" required>
</div>
<div class="form-group col-md-6">
<label for="maxstamina">Max Stamina:</label>
<input type="number" class="form-control" id="maxstamina" name="maxstamina" min="1" max="2097151" value="{$c->cData['stats']['maxstamina']}" required>
</div>
</div>
</div>-->
<hr> <hr>
$stats $stats
<div style="background:;"> <div style="background:;">
<h3 style="text-align: center">Skills</h3> <h3 style="text-align: center">Skills</h3>
<div class="form-group"> <div class="form-group">
<label for="setallskills">Set all skills:</label> <label for="{$c->cData['CharacterName']}-setallskills">Set all skills:</label>
<input type="number" id="setallskills" class="form-control setallskills" max="99"> <input type="number" class="setallskills" id="{$c->cData['CharacterName']}-setallskills" class="form-control setallskills" max="99">
</div> </div>
<div class="accordion" id="accordionExample"> <div class="accordion" id="accordionExample">
@ -469,8 +416,8 @@ $checkboxes
<h3 style="text-align: center">Quests</h3> <h3 style="text-align: center">Quests</h3>
<div class="form-group"> <div class="form-group">
<div class="form-check"> <div class="form-check">
<label for="q_all" class="form-check-label">Enable/Disable All Quests</label> <label for="{$c->cData['CharacterName']}-q_all" class="form-check-label">Enable/Disable All Quests</label>
<input $qchecked type="checkbox" id="q_all" name="q_all" value="$qallOnes" class="form-check-input q_all"> <input $qchecked type="checkbox" id="{$c->cData['CharacterName']}-q_all" name="q_all" value="$qallOnes" class="form-check-input q_all">
</div> </div>
</div> </div>
$quests $quests
@ -479,8 +426,8 @@ $checkboxes
<h3 style="text-align: center">Waypoints</h3> <h3 style="text-align: center">Waypoints</h3>
<div class="form-group"> <div class="form-group">
<div class="form-check"> <div class="form-check">
<label for="wp_all" class="form-check-label">Enable/Disable All Waypoints</label> <label for="{$c->cData['CharacterName']}-wp_all" class="form-check-label">Enable/Disable All Waypoints</label>
<input $wpchecked type="checkbox" id="wp_all" name="wp_all" value="$wpallOnes" class="form-check-input wp_all"> <input $wpchecked type="checkbox" id="{$c->cData['CharacterName']}-wp_all" name="wp_all" value="$wpallOnes" class="form-check-input wp_all">
</div> </div>
</div> </div>