cleanup and fix sonarqube findings
All checks were successful
Sonarqube Scanner / Build and analyze (push) Successful in 51s
All checks were successful
Sonarqube Scanner / Build and analyze (push) Successful in 51s
This commit is contained in:
parent
d7ce563925
commit
dd1b08ee21
@ -236,7 +236,6 @@ export class ConfigurableReactionsConfigApp extends HandlebarsApplicationMixin(A
|
|||||||
|
|
||||||
if (dropZone.dataset.crDrop === "action-spell" && isSpellItem(droppedItem)) {
|
if (dropZone.dataset.crDrop === "action-spell" && isSpellItem(droppedItem)) {
|
||||||
await this.#setActionSpell(Number(dropZone.dataset.actionIndex), droppedItem);
|
await this.#setActionSpell(Number(dropZone.dataset.actionIndex), droppedItem);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -409,6 +408,7 @@ export class ConfigurableReactionsConfigApp extends HandlebarsApplicationMixin(A
|
|||||||
try {
|
try {
|
||||||
reaction = JSON.parse(textarea.value);
|
reaction = JSON.parse(textarea.value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.warn(`${MODULE_ID} | Invalid reaction JSON`, error);
|
||||||
ui.notifications.error(game.i18n.localize("CONFIGURABLE_REACTIONS.Errors.InvalidJson"));
|
ui.notifications.error(game.i18n.localize("CONFIGURABLE_REACTIONS.Errors.InvalidJson"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,21 +10,30 @@ export async function handleTrigger(triggerType, context) {
|
|||||||
const assignedReactions = await getAssignedReactionsForContext(context);
|
const assignedReactions = await getAssignedReactionsForContext(context);
|
||||||
|
|
||||||
for (const reaction of assignedReactions) {
|
for (const reaction of assignedReactions) {
|
||||||
try {
|
await handleAssignedReaction(triggerType, context, reaction);
|
||||||
if (!reaction?.enabled) continue;
|
|
||||||
if (reaction.trigger?.type !== triggerType) continue;
|
|
||||||
if (!matchesTriggerSpellFilter(reaction.trigger, context)) continue;
|
|
||||||
if (!await checkConsumptionAvailable(reaction, context)) continue;
|
|
||||||
if (!await checkConditions(reaction, context)) continue;
|
|
||||||
|
|
||||||
const result = await executeReactionActions(reaction, context);
|
|
||||||
if (result.shouldConsume) await consumeReactionUse(reaction, context);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`${MODULE_ID} | Failed to handle reaction`, reaction, error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleAssignedReaction(triggerType, context, reaction) {
|
||||||
|
try {
|
||||||
|
if (!await shouldExecuteReaction(triggerType, context, reaction)) return;
|
||||||
|
|
||||||
|
const result = await executeReactionActions(reaction, context);
|
||||||
|
if (result.shouldConsume) await consumeReactionUse(reaction, context);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`${MODULE_ID} | Failed to handle reaction`, reaction, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function shouldExecuteReaction(triggerType, context, reaction) {
|
||||||
|
if (!reaction?.enabled) return false;
|
||||||
|
if (reaction.trigger?.type !== triggerType) return false;
|
||||||
|
if (!matchesTriggerSpellFilter(reaction.trigger, context)) return false;
|
||||||
|
if (!await checkConsumptionAvailable(reaction, context)) return false;
|
||||||
|
|
||||||
|
return checkConditions(reaction, context);
|
||||||
|
}
|
||||||
|
|
||||||
function matchesTriggerSpellFilter(trigger, context) {
|
function matchesTriggerSpellFilter(trigger, context) {
|
||||||
const expectedName = trigger?.spell?.itemName;
|
const expectedName = trigger?.spell?.itemName;
|
||||||
if (!expectedName) return true;
|
if (!expectedName) return true;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
export function randomPointInCircle(origin, radiusPx) {
|
export function randomPointInCircle(origin, radiusPx) {
|
||||||
const angle = Math.random() * Math.PI * 2;
|
const angle = randomUnitFloat() * Math.PI * 2;
|
||||||
const distance = Math.sqrt(Math.random()) * radiusPx;
|
const distance = Math.sqrt(randomUnitFloat()) * radiusPx;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x: origin.x + Math.cos(angle) * distance,
|
x: origin.x + Math.cos(angle) * distance,
|
||||||
@ -19,3 +19,14 @@ export function sceneDistanceToPixels(distance) {
|
|||||||
const distancePerGrid = canvas.scene.grid.distance || 5;
|
const distancePerGrid = canvas.scene.grid.distance || 5;
|
||||||
return distance / distancePerGrid * gridSize;
|
return distance / distancePerGrid * gridSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function randomUnitFloat() {
|
||||||
|
const cryptoApi = globalThis.crypto;
|
||||||
|
if (!cryptoApi?.getRandomValues) {
|
||||||
|
throw new Error("A cryptographically secure random generator is not available.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const values = new Uint32Array(1);
|
||||||
|
cryptoApi.getRandomValues(values);
|
||||||
|
return values[0] / 0x100000000;
|
||||||
|
}
|
||||||
|
|||||||
@ -167,11 +167,24 @@
|
|||||||
|
|
||||||
.configurable-reactions .cr-json-editor {
|
.configurable-reactions .cr-json-editor {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.35rem;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.configurable-reactions .cr-json-editor-heading,
|
||||||
|
.configurable-reactions .cr-json-editor-heading label {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.configurable-reactions .cr-json-editor-heading {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
.configurable-reactions .cr-main textarea[name="reactionJson"] {
|
.configurable-reactions .cr-main textarea[name="reactionJson"] {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
flex: 1 1 auto;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
min-height: 180px;
|
min-height: 180px;
|
||||||
font-family: var(--font-monospace, monospace);
|
font-family: var(--font-monospace, monospace);
|
||||||
@ -239,7 +252,7 @@
|
|||||||
gap: 0.3rem;
|
gap: 0.3rem;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
padding: 0.12rem 0.2rem 0.12rem 0.35rem;
|
padding: 0.12rem 0.2rem 0.12rem 0.35rem;
|
||||||
border: 1px solid var(--color-border-light-secondary, #777);
|
border: none;
|
||||||
border-radius: 999px;
|
border-radius: 999px;
|
||||||
background: rgb(0 0 0 / 0.16);
|
background: rgb(0 0 0 / 0.16);
|
||||||
font-size: 70%;
|
font-size: 70%;
|
||||||
|
|||||||
@ -199,9 +199,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div class="form-group stacked cr-json-editor">
|
<div class="cr-json-editor">
|
||||||
<label>{{localize "CONFIGURABLE_REACTIONS.Reactions.JsonEditor"}}</label>
|
<div class="cr-json-editor-heading">
|
||||||
<textarea name="reactionJson" spellcheck="false">{{selectedReactionJson}}</textarea>
|
<label for="cr-reaction-json">{{localize "CONFIGURABLE_REACTIONS.Reactions.JsonEditor"}}</label>
|
||||||
|
</div>
|
||||||
|
<textarea id="cr-reaction-json" name="reactionJson" spellcheck="false">{{selectedReactionJson}}</textarea>
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<p>{{localize "CONFIGURABLE_REACTIONS.Reactions.None"}}</p>
|
<p>{{localize "CONFIGURABLE_REACTIONS.Reactions.None"}}</p>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user