Skip to content

Commit

Permalink
Lots of SonarCloud Rules Added
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunomiac committed Sep 24, 2023
1 parent 44a899d commit 661dacd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sonar.organization=eunomiac

# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=eunos-blades
#sonar.projectVersion=1.0
sonar.projectVersion=0.1


# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
Expand Down
58 changes: 28 additions & 30 deletions ts/blades-actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import type {MergeObjectOptions} from "@league-of-foundry-developers/foundry-vtt
// #endregion


// https://foundryvtt.wiki/en/development/guides/polymorphism-actors-items
// Blades Theme Song: "Bangkok" from The Gray Man soundtrack: https://www.youtube.com/watch?v=cjjImvMqYlo&list=OLAK5uy_k9cZDd1Fbpd25jfDtte5A6HyauD2-cwgk&index=2
// Add "coin" item to general items --> equals 1 Coin worth of value, carried, and has Load 1.

// Also check out Discord thread: https://discord.com/channels/325094888133885952/1152316839163068527

class BladesActor extends Actor implements BladesDocument<Actor> {

Expand Down Expand Up @@ -128,7 +126,7 @@ class BladesActor extends Actor implements BladesDocument<Actor> {

/* Implement any prerequisite checks for embedding actors */

return true;
return actor && true;
}
private processEmbeddedActorMatches(globalActors: BladesActor[]) {

Expand Down Expand Up @@ -327,8 +325,8 @@ class BladesActor extends Actor implements BladesDocument<Actor> {
switch (pType) {
case PrereqType.HasActiveItem: {
const thisItem = this.activeSubItems
.filter((item) => !hitRecord[<PrereqType>pType]?.includes(item.id!))
.find((item) => item.system.world_name === pString);
.filter((i) => !hitRecord[<PrereqType>pType]?.includes(i.id!))
.find((i) => i.system.world_name === pString);
if (thisItem) {
hitRecord[<PrereqType>pType]!.push(thisItem.id!);
} else {
Expand All @@ -338,8 +336,8 @@ class BladesActor extends Actor implements BladesDocument<Actor> {
}
case PrereqType.HasActiveItemsByTag: {
const thisItem = this.activeSubItems
.filter((item) => !hitRecord[<PrereqType>pType]?.includes(item.id!))
.find((item) => item.hasTag(pString as BladesTag));
.filter((i) => !hitRecord[<PrereqType>pType]?.includes(i.id!))
.find((i) => i.hasTag(pString as BladesTag));
if (thisItem) {
hitRecord[<PrereqType>pType]!.push(thisItem.id!);
} else {
Expand Down Expand Up @@ -551,12 +549,20 @@ class BladesActor extends Actor implements BladesDocument<Actor> {
}

getSubItem(itemRef: ItemRef, activeOnly = false): BladesItem | undefined {
const activeCheck = (i: BladesItem) => !activeOnly || !i.hasTag(Tag.System.Archived);
if (typeof itemRef === "string" && this.items.get(itemRef)) {
return this.items.get(itemRef);
const returnItem = this.items.get(itemRef);
if (returnItem && activeCheck(returnItem)) {
return returnItem;
} else {
return undefined;
}
} else {
const globalItem = BladesItem.Get(itemRef);
if (!globalItem) { return undefined }
return this.items.find((item) => item.name === globalItem.name && activeCheck(item))
?? this.items.find((item) => item.system.world_name === globalItem.system.world_name && activeCheck(item));
}
const globalItem = BladesItem.Get(itemRef);
if (!globalItem) { return undefined }
return this.items.find((item) => item.name === globalItem.name) ?? this.items.find((item) => item.system.world_name === globalItem.system.world_name);
}

hasSubItemOf(itemRef: ItemRef): boolean {
Expand Down Expand Up @@ -813,16 +819,14 @@ class BladesActor extends Actor implements BladesDocument<Actor> {

getTaggedItemBonuses(tags: BladesTag[]): number {
// Check ACTIVE EFFECTS supplied by upgrade/ability against submitted tags?
return 0;
return tags.length; // Placeholder to avoid linter error
}
// #endregion

// #region PREPARING DERIVED DATA
override prepareDerivedData() {
if (BladesActor.IsType(this, BladesActorType.pc)) { this._preparePCData(this.system) }
if (BladesActor.IsType(this, BladesActorType.crew)) { this._prepareCrewData(this.system) }
if (BladesActor.IsType(this, BladesActorType.npc)) { this._prepareNPCData(this.system) }
if (BladesActor.IsType(this, BladesActorType.faction)) { this._prepareFactionData(this.system) }
}

_preparePCData(system: ExtractBladesActorSystem<BladesActorType.pc>) {
Expand All @@ -848,14 +852,6 @@ class BladesActor extends Actor implements BladesDocument<Actor> {
}
}

_prepareNPCData(system: ExtractBladesActorSystem<BladesActorType.npc>) {
if (!BladesActor.IsType(this, BladesActorType.npc)) { return }
}

_prepareFactionData(system: ExtractBladesActorSystem<BladesActorType.faction>) {
if (!BladesActor.IsType(this, BladesActorType.faction)) { return }
}

// #endregion

// #region OVERRIDES: _onCreateDescendantDocuments, update ~
Expand Down Expand Up @@ -917,14 +913,16 @@ class BladesActor extends Actor implements BladesDocument<Actor> {
// #region Rolling Dice ~
rollAttributePopup(attribute_name: Attribute | Action) {
const attribute_label: Capitalize<Attribute | Action> = U.tCase(attribute_name);
const MIN_DICE_MOD = -3;
const MAX_DICE_MOD = 3;

let content = `
<h2>${game.i18n.localize("BITD.Roll")} ${attribute_label}</h2>
<form>
<div class="form-group">
<label>${game.i18n.localize("BITD.Modifier")}:</label>
<select id="mod" name="mod">
${this.createListOfDiceMods(-3, +3, 0)}
${this.createListOfDiceMods(MIN_DICE_MOD, MAX_DICE_MOD, 0)}
</select>
</div>`;
if ([...Object.keys(Attribute), ...Object.keys(Action)].includes(attribute_name)) {
Expand Down Expand Up @@ -1051,14 +1049,14 @@ class BladesActor extends Actor implements BladesDocument<Actor> {
return arr[Math.floor(Math.random() * arr.length)];
}
const randomGen: Record<string, (gender?: string) => string> = {
name: (gender?: string) => {
name: (gen?: string) => {
return [
Math.random() <= titleChance
? sampleArray(Randomizers.NPC.name_title)
: "",
sampleArray([
...((gender ?? "").charAt(0).toLowerCase() !== "m" ? Randomizers.NPC.name_first.female : []),
...((gender ?? "").charAt(0).toLowerCase() !== "f" ? Randomizers.NPC.name_first.male : [])
...((gen ?? "").charAt(0).toLowerCase() !== "m" ? Randomizers.NPC.name_first.female : []),
...((gen ?? "").charAt(0).toLowerCase() !== "f" ? Randomizers.NPC.name_first.male : [])
]),
`"${sampleArray(Randomizers.NPC.name_alias)}"`,
sampleArray(Randomizers.NPC.name_surname),
Expand All @@ -1077,9 +1075,9 @@ class BladesActor extends Actor implements BladesDocument<Actor> {
trait: () => sampleArray(Randomizers.NPC.trait, persona.trait1.value, persona.trait2.value, persona.trait3.value, secret.trait.value),
interests: () => sampleArray(Randomizers.NPC.interests, persona.interests.value, secret.interests.value),
quirk: () => sampleArray(Randomizers.NPC.quirk, persona.quirk.value),
style: (gender = "") => sampleArray([
...(gender.charAt(0).toLowerCase() !== "m" ? Randomizers.NPC.style.female : []),
...(gender.charAt(0).toLowerCase() !== "f" ? Randomizers.NPC.style.male : [])
style: (gen = "") => sampleArray([
...(gen.charAt(0).toLowerCase() !== "m" ? Randomizers.NPC.style.female : []),
...(gen.charAt(0).toLowerCase() !== "f" ? Randomizers.NPC.style.male : [])
], persona.style.value)
};

Expand Down
7 changes: 1 addition & 6 deletions ts/sheets/actor/blades-pc-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ class BladesPCSheet extends BladesSheet {
// Dropping a Crew onto a PC Sheet: Add
parentActor.addSubActor(doc);
}
} // else if (doc instanceof BladesItem) {
// parentActor.addSubItem(doc);
// BladesItem.create(doc as {name: string, type: BladesItemType}, {parent: parentActor});
// return;
// }
// return false;
}
});
return loadTemplates([
"systems/eunos-blades/templates/items/clock_keeper-sheet.hbs",
Expand Down

0 comments on commit 661dacd

Please sign in to comment.