CDN fix, Account maangement fix
This commit is contained in:
@@ -176,54 +176,67 @@
|
||||
|
||||
<!-- Resistances -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Damage Resistances</h2>
|
||||
<p class="text-sm text-gray-400 mt-1">Negative = weakness (takes more damage), Positive = resistance, 1.0 = immune</p>
|
||||
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
|
||||
<div>
|
||||
<h2 class="text-lg font-semibold text-white">Damage Resistances</h2>
|
||||
<p class="text-sm text-gray-400 mt-1">Negative % = weakness, Positive % = resistance, 100% = immune</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
@foreach (var dt in Enum.GetValues<DamageType>())
|
||||
<!-- Current Resistances -->
|
||||
<div id="resistancesList" class="space-y-2 mb-4">
|
||||
@foreach (var resist in Model.Resistances)
|
||||
{
|
||||
var currentValue = Model.GetResistance(dt.ToString().ToLower());
|
||||
var bgColor = currentValue < 0 ? "bg-red-900/30 border-red-700" :
|
||||
currentValue > 0 ? "bg-green-900/30 border-green-700" :
|
||||
var bgColor = resist.Value < 0 ? "bg-red-900/30 border-red-700" :
|
||||
resist.Value > 0 ? "bg-green-900/30 border-green-700" :
|
||||
"bg-gray-800 border-gray-700";
|
||||
<div class="@bgColor border rounded-lg p-3">
|
||||
<label class="label text-sm mb-1">@dt</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="@bgColor border rounded-lg p-3 flex items-center gap-4 resistance-row">
|
||||
<input type="text" name="resist_name[]" value="@resist.Key" class="input w-40" placeholder="Type name" />
|
||||
<div class="flex items-center gap-2 flex-1">
|
||||
<input type="range"
|
||||
name="resistance_@dt.ToString().ToLower()"
|
||||
value="@currentValue"
|
||||
min="-1" max="1" step="0.1"
|
||||
name="resist_value[]"
|
||||
value="@resist.Value"
|
||||
min="-1" max="1" step="0.05"
|
||||
class="flex-1"
|
||||
oninput="this.nextElementSibling.value = this.value; updateResistColor(this.parentElement.parentElement, this.value)" />
|
||||
<input type="number"
|
||||
value="@currentValue"
|
||||
min="-1" max="1" step="0.1"
|
||||
class="input w-20 text-center text-sm"
|
||||
oninput="this.previousElementSibling.value = this.value; updateResistColor(this.parentElement.parentElement, this.value)" />
|
||||
oninput="this.nextElementSibling.value = Math.round(this.value * 100)" />
|
||||
<div class="flex items-center gap-1">
|
||||
<input type="number"
|
||||
value="@((resist.Value * 100).ToString("0"))"
|
||||
min="-100" max="100" step="5"
|
||||
class="input w-20 text-center text-sm"
|
||||
oninput="this.parentElement.previousElementSibling.value = this.value / 100" />
|
||||
<span class="text-gray-400">%</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
@if (currentValue < 0)
|
||||
{
|
||||
<span class="text-red-400">+@((-currentValue * 100).ToString("0"))% damage taken</span>
|
||||
}
|
||||
else if (currentValue > 0 && currentValue < 1)
|
||||
{
|
||||
<span class="text-green-400">-@((currentValue * 100).ToString("0"))% damage taken</span>
|
||||
}
|
||||
else if (currentValue >= 1)
|
||||
{
|
||||
<span class="text-blue-400">Immune</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Normal damage</span>
|
||||
}
|
||||
</p>
|
||||
<button type="button" onclick="this.closest('.resistance-row').remove()" class="p-2 text-red-400 hover:text-red-300">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (!Model.Resistances.Any())
|
||||
{
|
||||
<p class="text-gray-500 text-sm mb-4">No resistances configured. Add one below.</p>
|
||||
}
|
||||
|
||||
<!-- Add New Resistance -->
|
||||
<div class="flex items-center gap-4 pt-4 border-t border-gray-700">
|
||||
<select id="newResistType" class="input w-40" onchange="toggleCustomInput(this)">
|
||||
<option value="">Select type...</option>
|
||||
@foreach (var dt in Enum.GetValues<DamageType>())
|
||||
{
|
||||
<option value="@dt.ToString().ToLower()">@dt</option>
|
||||
}
|
||||
<option value="custom">Custom...</option>
|
||||
</select>
|
||||
<input type="text" id="newResistCustom" class="input w-40 hidden" placeholder="Custom name" />
|
||||
<input type="number" id="newResistValue" class="input w-24" value="50" min="-100" max="100" step="5" />
|
||||
<span class="text-gray-400">%</span>
|
||||
<button type="button" onclick="addResistance()" class="btn btn-secondary">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -383,5 +396,69 @@
|
||||
document.getElementById('addLootModal').classList.remove('flex');
|
||||
}
|
||||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeAddLootModal(); });
|
||||
|
||||
function toggleCustomInput(select) {
|
||||
const customInput = document.getElementById('newResistCustom');
|
||||
if (select.value === 'custom') {
|
||||
customInput.classList.remove('hidden');
|
||||
customInput.focus();
|
||||
} else {
|
||||
customInput.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
function addResistance() {
|
||||
const typeSelect = document.getElementById('newResistType');
|
||||
const customInput = document.getElementById('newResistCustom');
|
||||
const valueInput = document.getElementById('newResistValue');
|
||||
|
||||
let name = typeSelect.value === 'custom' ? customInput.value.trim().toLowerCase() : typeSelect.value;
|
||||
const percent = parseInt(valueInput.value) || 0;
|
||||
const value = percent / 100;
|
||||
|
||||
if (!name) {
|
||||
alert('Please select or enter a resistance type');
|
||||
return;
|
||||
}
|
||||
|
||||
const bgColor = value < 0 ? 'bg-red-900/30 border-red-700' :
|
||||
value > 0 ? 'bg-green-900/30 border-green-700' :
|
||||
'bg-gray-800 border-gray-700';
|
||||
|
||||
const html = `
|
||||
<div class="${bgColor} border rounded-lg p-3 flex items-center gap-4 resistance-row">
|
||||
<input type="text" name="resist_name[]" value="${name}" class="input w-40" placeholder="Type name" />
|
||||
<div class="flex items-center gap-2 flex-1">
|
||||
<input type="range"
|
||||
name="resist_value[]"
|
||||
value="${value}"
|
||||
min="-1" max="1" step="0.05"
|
||||
class="flex-1"
|
||||
oninput="this.nextElementSibling.value = Math.round(this.value * 100)" />
|
||||
<div class="flex items-center gap-1">
|
||||
<input type="number"
|
||||
value="${percent}"
|
||||
min="-100" max="100" step="5"
|
||||
class="input w-20 text-center text-sm"
|
||||
oninput="this.parentElement.previousElementSibling.value = this.value / 100" />
|
||||
<span class="text-gray-400">%</span>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onclick="this.closest('.resistance-row').remove()" class="p-2 text-red-400 hover:text-red-300">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.getElementById('resistancesList').insertAdjacentHTML('beforeend', html);
|
||||
|
||||
// Reset inputs
|
||||
typeSelect.value = '';
|
||||
customInput.value = '';
|
||||
customInput.classList.add('hidden');
|
||||
valueInput.value = '50';
|
||||
}
|
||||
</script>
|
||||
}
|
||||
|
||||
@@ -25,16 +25,24 @@ public class EditModel : AdminPageModel
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
// Helper to get resistance value for a damage type
|
||||
// Helper to get all resistances as dictionary
|
||||
public Dictionary<string, float> Resistances
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<Dictionary<string, float>>(Mob.ResistancesJson ?? "{}") ?? new();
|
||||
}
|
||||
catch { return new(); }
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to get single resistance value for a damage type
|
||||
public float GetResistance(string damageType)
|
||||
{
|
||||
try
|
||||
{
|
||||
var resistances = JsonSerializer.Deserialize<Dictionary<string, float>>(Mob.ResistancesJson ?? "{}");
|
||||
if (resistances != null && resistances.TryGetValue(damageType, out var value))
|
||||
return value;
|
||||
}
|
||||
catch { }
|
||||
if (Resistances.TryGetValue(damageType, out var value))
|
||||
return value;
|
||||
return 0f;
|
||||
}
|
||||
|
||||
@@ -94,14 +102,16 @@ public class EditModel : AdminPageModel
|
||||
Mob.Description ??= "";
|
||||
Mob.TintColor ??= "#ffffff";
|
||||
|
||||
// Parse resistances from form
|
||||
// Parse resistances from form (array format)
|
||||
var resistances = new Dictionary<string, float>();
|
||||
foreach (var key in Request.Form.Keys.Where(k => k.StartsWith("resistance_")))
|
||||
var names = Request.Form["resist_name[]"].ToArray();
|
||||
var values = Request.Form["resist_value[]"].ToArray();
|
||||
for (int i = 0; i < names.Length && i < values.Length; i++)
|
||||
{
|
||||
var damageType = key.Replace("resistance_", "");
|
||||
if (float.TryParse(Request.Form[key], out var value) && value != 0)
|
||||
var name = names[i]?.Trim().ToLower();
|
||||
if (!string.IsNullOrEmpty(name) && float.TryParse(values[i], out var value))
|
||||
{
|
||||
resistances[damageType] = value;
|
||||
resistances[name] = value;
|
||||
}
|
||||
}
|
||||
Mob.ResistancesJson = JsonSerializer.Serialize(resistances);
|
||||
|
||||
Reference in New Issue
Block a user