|
|
/apps/mc-api/src/@apis/index.ts
|
0 problems
|
|
|
/apps/mc-api/src/@apis/response.ts
|
0 problems
|
|
|
/apps/mc-api/src/app.controller.ts
|
0 problems
|
|
|
/apps/mc-api/src/app.module.ts
|
0 problems
|
|
|
/apps/mc-api/src/app.service.ts
|
0 problems
|
|
|
/apps/mc-api/src/database.config.ts
|
0 problems
|
|
|
/apps/mc-api/src/main.ts
|
0 problems
|
|
|
/apps/mc-api/src/models/deck.ts
|
0 problems
|
|
|
/apps/mc-api/src/models/encounter.ts
|
0 problems
|
|
|
/apps/mc-api/src/models/enums.ts
|
0 problems
|
|
|
/apps/mc-api/src/models/hero.ts
|
0 problems
|
|
|
/apps/mc-api/src/models/index.ts
|
0 problems
|
|
|
/apps/mc-api/src/models/modular-set.ts
|
0 problems
|
|
|
/apps/mc-api/src/models/pack.ts
|
0 problems
|
|
|
/apps/mc-api/src/models/scenario.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/decks/deck.entity.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/decks/decks.module.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/decks/decks.service.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/encounters/encounter.entity.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/encounters/encounters.module.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/heroes/hero.entity.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/heroes/heroes.module.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/heroes/heroes.service.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/modular-sets/modular-set.entity.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/modular-sets/modular-sets.module.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/modular-sets/modular-sets.service.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/packs/pack.entity.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/packs/packs.module.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/packs/packs.service.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/scenarios/scenario.entity.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/scenarios/scenarios.module.ts
|
0 problems
|
|
|
/apps/mc-api/src/modules/scenarios/scenarios.service.ts
|
0 problems
|
|
|
/apps/mc/src/app.d.ts
|
0 problems
|
|
|
/apps/mc/src/lib/data.svelte
|
0 problems
|
|
|
/apps/mc/src/lib/functions.ts
|
3 problems (3 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 22, Column 64: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 27, Column 64: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 31, Column 64: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import type { Encounter, Hero, ModularSet, Scenario } from "$models"; |
| 2 |
|
| 3 |
export const notEmpty = <T>(value: T | null | undefined): value is T => value !== null && value !== undefined; |
| 4 |
|
| 5 |
export const excludeHeroes = (heroes: Hero[], scenarioName: string, encounters: Map<string, Hero[]>): Hero[] => |
| 6 |
heroes.filter((hero) => !(encounters.get(scenarioName) || []).includes(hero.name)); |
| 7 |
|
| 8 |
// eslint-disable-next-line max-params |
| 9 |
export function getWeightedData( |
| 10 |
encounters: Encounter[], |
| 11 |
scenarios: Scenario[], |
| 12 |
modularsets: ModularSet[], |
| 13 |
heroes: Hero[], |
| 14 |
): [number[], number[], number[]] { |
| 15 |
const base = encounters.length * 5; |
| 16 |
const weightedScenarios: number[] = []; |
| 17 |
const weightedModularSets: number[] = []; |
| 18 |
const weightedHeroes: number[] = []; |
| 19 |
|
| 20 |
const gamesHeroes = encounters |
| 21 |
.flatMap((encounter) => encounter.heroes) |
| Error |
Row 22, Column 64: "Map is not supported in IE 9"
compat/compat
|
| 22 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 23 |
|
| 24 |
const gamesModularSets = encounters |
| 25 |
.flatMap((encounter) => encounter.modularSets) |
| 26 |
.map((module) => module) |
| Error |
Row 27, Column 64: "Map is not supported in IE 9"
compat/compat
|
| 27 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 28 |
|
| 29 |
const gamesScenarios = encounters |
| 30 |
.map((encounter) => encounter.scenario) |
| Error |
Row 31, Column 64: "Map is not supported in IE 9"
compat/compat
|
| 31 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 32 |
|
| 33 |
modularsets.forEach((module) => { |
| 34 |
const pastOccurrences = gamesModularSets.has(module.name) ? gamesModularSets.get(module.name) : 0; |
| 35 |
|
| 36 |
weightedModularSets.push(base - pastOccurrences); |
| 37 |
}); |
| 38 |
|
| 39 |
scenarios.forEach((scenario) => { |
| 40 |
const pastOccurrences = gamesScenarios.has(scenario.name) ? gamesScenarios.get(scenario.name) : 0; |
| 41 |
|
| 42 |
weightedScenarios.push(base - pastOccurrences); |
| 43 |
}); |
| 44 |
|
| 45 |
heroes.forEach((hero) => { |
| 46 |
const pastOccurrences = gamesHeroes.has(hero.name) ? gamesHeroes.get(hero.name) : 0; |
| 47 |
|
| 48 |
weightedHeroes.push(base - pastOccurrences); |
| 49 |
}); |
| 50 |
|
| 51 |
return [weightedScenarios, weightedModularSets, weightedHeroes]; |
| 52 |
} |
| 53 |
|
|
|
|
/apps/mc/src/lib/interface.ts
|
0 problems
|
|
|
/apps/mc/src/lib/progression.svelte
|
4 problems (4 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 19, Column 53: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 41, Column 16: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 46, Column 35: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 87, Column 28: "Array.from() is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
<svelte:options tag="mc-progression" /> |
| 2 |
|
| 3 |
<script lang="ts"> |
| 4 |
import type { Encounter, Hero, Scenario } from "$models"; |
| 5 |
import type { HeroProgression } from "$lib/interface"; |
| 6 |
|
| 7 |
import { ResultEnum } from "$models"; |
| 8 |
|
| 9 |
import Progress from "$ui/progress/src/progress.svelte"; |
| 10 |
import Title from "$lib/title.svelte"; |
| 11 |
|
| 12 |
// eslint-disable-next-line import/no-mutable-exports |
| 13 |
export let heroes: Hero[] = []; |
| 14 |
// eslint-disable-next-line import/no-mutable-exports |
| 15 |
export let encounters: Encounter[] = []; |
| 16 |
// eslint-disable-next-line import/no-mutable-exports |
| 17 |
export let scenarios: Scenario[] = []; |
| 18 |
|
| Error |
Row 19, Column 53: "Map is not supported in IE 9"
compat/compat
|
| 19 |
const progressionTargets: Map<string, number> = new Map<string, number>(); |
| 20 |
let globalProgression = 0; |
| 21 |
|
| 22 |
let heroesLines: HeroProgression[] = []; |
| 23 |
|
| 24 |
$: { |
| 25 |
// heroes = heroes; |
| 26 |
// encounters = encounters; |
| 27 |
// scenarios = scenarios; |
| 28 |
|
| 29 |
const encountersHeroes = encounters |
| 30 |
.filter((encounter) => encounter.result === ResultEnum.WON) |
| 31 |
.reduce((acc, e) => { |
| 32 |
e.heroes.forEach((hero) => { |
| 33 |
if (hero !== null && !acc.has(hero.name)) { |
| 34 |
acc.set(hero.name, new Set()); |
| 35 |
} |
| 36 |
|
| 37 |
acc.get(hero.name).add(e.scenario.name); |
| 38 |
}); |
| 39 |
|
| 40 |
return acc; |
| Error |
Row 41, Column 16: "Map is not supported in IE 9"
compat/compat
|
| 41 |
}, new Map()); |
| 42 |
|
| 43 |
heroesLines = heroes.map((hero) => { |
| 44 |
const heroEncounters = encountersHeroes.get(hero.name); |
| 45 |
|
| Error |
Row 46, Column 35: "Map is not supported in IE 9"
compat/compat
|
| 46 |
const heroScenarios = new Map<string, boolean>(); |
| 47 |
|
| 48 |
scenarios.forEach((scenario) => { |
| 49 |
heroScenarios.set(scenario.name, heroEncounters != null && heroEncounters.has(scenario.name)); |
| 50 |
}); |
| 51 |
|
| 52 |
return { |
| 53 |
name: hero.name, |
| 54 |
scenarios: heroScenarios, |
| 55 |
}; |
| 56 |
}); |
| 57 |
|
| 58 |
scenarios.forEach((scenario) => { |
| 59 |
progressionTargets.set(scenario.name, 0); |
| 60 |
|
| 61 |
const scenarioProgression = heroesLines |
| 62 |
.map((line) => line.scenarios.get(scenario.name)) |
| 63 |
.filter((result) => result === true).length; |
| 64 |
|
| 65 |
progressionTargets.set(scenario.name, scenarioProgression); |
| 66 |
globalProgression += scenarioProgression; |
| 67 |
}); |
| 68 |
} |
| 69 |
</script> |
| 70 |
|
| 71 |
<Title title="Progression" /> |
| 72 |
|
| 73 |
{#if scenarios.length > 0} |
| 74 |
<table> |
| 75 |
<thead> |
| 76 |
<tr> |
| 77 |
<th></th> |
| 78 |
{#each scenarios as scenario} |
| 79 |
<th>{scenario.name}</th> |
| 80 |
{/each} |
| 81 |
</tr> |
| 82 |
</thead> |
| 83 |
<tbody> |
| 84 |
{#each heroesLines as hero} |
| 85 |
<tr> |
| 86 |
<th>{hero.name}</th> |
| Error |
Row 87, Column 28: "Array.from() is not supported in IE 9"
compat/compat
|
| 87 |
{#each Array.from(hero.scenarios.values()) as won} |
| 88 |
<td> |
| 89 |
{#if won === true} |
| 90 |
✓ |
| 91 |
{/if} |
| 92 |
</td> |
| 93 |
{/each} |
| 94 |
</tr> |
| 95 |
{/each} |
| 96 |
<!-- Percentage--> |
| 97 |
<tr> |
| 98 |
<th> |
| 99 |
<Progress value="{globalProgression}" max="{scenarios.length * heroes.length}" /> |
| 100 |
</th> |
| 101 |
{#each scenarios as scenario} |
| 102 |
<th> |
| 103 |
<Progress value="{progressionTargets.get(scenario.name)}" max="{scenarios.length}" /> |
| 104 |
</th> |
| 105 |
{/each} |
| 106 |
</tr> |
| 107 |
</tbody> |
| 108 |
</table> |
| 109 |
{/if} |
| 110 |
|
|
|
|
/apps/mc/src/lib/section.svelte
|
0 problems
|
|
|
/apps/mc/src/lib/select.svelte
|
0 problems
|
|
|
/apps/mc/src/lib/stats-table.svelte
|
2 problems (2 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 9, Column 44: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 11, Column 45: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
<svelte:options tag="mc-stats-table" /> |
| 2 |
|
| 3 |
<script lang="ts"> |
| 4 |
// eslint-disable-next-line import/no-mutable-exports |
| 5 |
export let data: []; |
| 6 |
// eslint-disable-next-line import/no-mutable-exports |
| 7 |
export let total = 0; |
| 8 |
// eslint-disable-next-line import/no-mutable-exports |
| Error |
Row 9, Column 44: "Map is not supported in IE 9"
compat/compat
|
| 9 |
export let wins: Map<string, number> = new Map(); |
| 10 |
// eslint-disable-next-line import/no-mutable-exports |
| Error |
Row 11, Column 45: "Map is not supported in IE 9"
compat/compat
|
| 11 |
export let dates: Map<string, number> = new Map(); |
| 12 |
|
| 13 |
$: { |
| 14 |
data = data.map(([key, value]) => { |
| 15 |
return { |
| 16 |
name: key, |
| 17 |
value, |
| 18 |
}; |
| 19 |
}); |
| 20 |
// total = total; |
| 21 |
// wins = wins; |
| 22 |
// dates = dates; |
| 23 |
|
| 24 |
if (wins.size > 0) { |
| 25 |
data = data.map((item) => { |
| 26 |
return { |
| 27 |
name: item.name, |
| 28 |
value: item.value, |
| 29 |
wins: wins.get(item.name) || 0, |
| 30 |
days: dates.get(item.name), |
| 31 |
}; |
| 32 |
}); |
| 33 |
} |
| 34 |
} |
| 35 |
</script> |
| 36 |
|
| 37 |
<table> |
| 38 |
{#each data as item} |
| 39 |
<tr> |
| 40 |
<td>{item.name}</td> |
| 41 |
{#if total > 0} |
| 42 |
<td>{item.value} ({((item.value / total) * 100).toFixed(0)} %)</td> |
| 43 |
{:else} |
| 44 |
<td>{item.value}</td> |
| 45 |
<td> |
| 46 |
({((item.wins / item.value) * 100).toFixed(0)} %) |
| 47 |
</td> |
| 48 |
{#if item.days != null} |
| 49 |
<td>{item.days} day(s) ago</td> |
| 50 |
{:else} |
| 51 |
<td></td> |
| 52 |
{/if} |
| 53 |
{/if} |
| 54 |
</tr> |
| 55 |
{/each} |
| 56 |
</table> |
| 57 |
|
|
|
|
/apps/mc/src/lib/stats.svelte
|
22 problems (22 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 19, Column 33: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 29, Column 36: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 33, Column 38: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 50, Column 12: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 56, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 62, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 69, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 89, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 95, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 101, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 108, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 113, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 119, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 126, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 134, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 143, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 146, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 149, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 152, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 155, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 158, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 162, Column 12: "Array.from() is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
<svelte:options tag="mc-stats" /> |
| 2 |
|
| 3 |
<script lang="ts"> |
| 4 |
import { diffDays } from "@jga/dates"; |
| 5 |
import type { Encounter } from "$models"; |
| 6 |
import { ResultEnum } from "$models"; |
| 7 |
|
| 8 |
import Title from "$lib/title.svelte"; |
| 9 |
import Subtitle from "$lib/subtitle.svelte"; |
| 10 |
import StatsTable from "$lib/stats-table.svelte"; |
| 11 |
|
| 12 |
// eslint-disable-next-line import/no-mutable-exports |
| 13 |
export let encounters: Encounter[] = []; |
| 14 |
|
| 15 |
let nbHeroesGames: Map<number, number>; |
| 16 |
|
| 17 |
let gamesHeroes: Map<string, number>; |
| 18 |
let gamesHeroesWins: Map<string, number>; |
| Error |
Row 19, Column 33: "Map is not supported in IE 9"
compat/compat
|
| 19 |
const gamesHeroesLastDate = new Map<string, number>(); |
| 20 |
|
| 21 |
let gamesDifficulties: Map<string, number>; |
| 22 |
let gamesDifficultiesWins: Map<string, number>; |
| 23 |
|
| 24 |
let gamesAspects: Map<string, number>; |
| 25 |
let gamesAspectsWins: Map<string, number>; |
| 26 |
|
| 27 |
let gamesScenarios: Map<string, number>; |
| 28 |
let gamesScenariosWins: Map<string, number>; |
| Error |
Row 29, Column 36: "Map is not supported in IE 9"
compat/compat
|
| 29 |
const gamesScenariosLastDate = new Map<string, number>(); |
| 30 |
|
| 31 |
let gamesModularSets: Map<string, number>; |
| 32 |
let gamesModularSetsWins: Map<string, number>; |
| Error |
Row 33, Column 38: "Map is not supported in IE 9"
compat/compat
|
| 33 |
const gamesModularSetsLastDate = new Map<string, number>(); |
| 34 |
|
| 35 |
let results: Map<string, number>; |
| 36 |
|
| 37 |
$: { |
| 38 |
// heroes = heroes; |
| 39 |
// encounters = encounters; |
| 40 |
// modules = modules; |
| 41 |
// scenarios = scenarios; |
| 42 |
|
| 43 |
// eslint-disable-next-line prefer-const |
| 44 |
nbHeroesGames = encounters.reduce((acc, e) => { |
| 45 |
const nbHeroes = e.heroes.length; |
| 46 |
|
| 47 |
acc.set(nbHeroes, (acc.get(nbHeroes) || 0) + 1); |
| 48 |
|
| 49 |
return acc; |
| Error |
Row 50, Column 12: "Map is not supported in IE 9"
compat/compat
|
| 50 |
}, new Map()); |
| 51 |
|
| 52 |
// eslint-disable-next-line prefer-const |
| 53 |
results = encounters |
| 54 |
.map((encounter) => encounter.result) |
| 55 |
.sort() |
| Error |
Row 56, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 56 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 57 |
|
| 58 |
// eslint-disable-next-line prefer-const |
| 59 |
gamesHeroes = encounters |
| 60 |
.flatMap((encounter) => encounter.heroes) |
| 61 |
.map((hero) => hero.name) |
| Error |
Row 62, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 62 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 63 |
|
| 64 |
// eslint-disable-next-line prefer-const |
| 65 |
gamesHeroesWins = encounters |
| 66 |
.filter((encounter) => encounter.result === ResultEnum.WON) |
| 67 |
.flatMap((encounter) => encounter.heroes) |
| 68 |
.map((hero) => hero.name) |
| Error |
Row 69, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 69 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 70 |
|
| 71 |
encounters |
| 72 |
.filter((encounter) => encounter.date != null) |
| 73 |
.forEach((encounter) => { |
| 74 |
encounter.heroes.forEach((hero) => { |
| 75 |
if (encounter.date != null) { |
| 76 |
gamesHeroesLastDate.set(hero.name, diffDays(new Date(), encounter.date)); |
| 77 |
gamesScenariosLastDate.set(encounter.scenario.name, diffDays(new Date(), encounter.date)); |
| 78 |
|
| 79 |
encounter.modularSets.forEach((modularSet) => { |
| 80 |
gamesModularSetsLastDate.set(modularSet.name, diffDays(new Date(), encounter.date)); |
| 81 |
}); |
| 82 |
} |
| 83 |
}); |
| 84 |
}); |
| 85 |
|
| 86 |
// eslint-disable-next-line prefer-const |
| 87 |
gamesDifficulties = encounters |
| 88 |
.map((encounter) => encounter.difficulty) |
| Error |
Row 89, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 89 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 90 |
|
| 91 |
// eslint-disable-next-line prefer-const |
| 92 |
gamesDifficultiesWins = encounters |
| 93 |
.filter((encounter) => encounter.result === ResultEnum.WON) |
| 94 |
.map((encounter) => encounter.difficulty) |
| Error |
Row 95, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 95 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 96 |
|
| 97 |
// eslint-disable-next-line prefer-const |
| 98 |
gamesAspects = encounters |
| 99 |
.flatMap((encounter) => encounter.heroes) |
| 100 |
.flatMap((hero) => hero.aspects) |
| Error |
Row 101, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 101 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 102 |
|
| 103 |
// eslint-disable-next-line prefer-const |
| 104 |
gamesAspectsWins = encounters |
| 105 |
.filter((encounter) => encounter.result === ResultEnum.WON) |
| 106 |
.flatMap((encounter) => encounter.heroes) |
| 107 |
.flatMap((hero) => hero.aspects) |
| Error |
Row 108, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 108 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 109 |
|
| 110 |
// eslint-disable-next-line prefer-const |
| 111 |
gamesScenarios = encounters |
| 112 |
.map((encounter) => encounter.scenario.name) |
| Error |
Row 113, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 113 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 114 |
|
| 115 |
// eslint-disable-next-line prefer-const |
| 116 |
gamesScenariosWins = encounters |
| 117 |
.filter((encounter) => encounter.result === ResultEnum.WON) |
| 118 |
.map((encounter) => encounter.scenario.name) |
| Error |
Row 119, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 119 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 120 |
|
| 121 |
// eslint-disable-next-line prefer-const |
| 122 |
gamesModularSets = encounters |
| 123 |
.filter((encounter) => encounter.modularSets != null) |
| 124 |
.flatMap((encounter) => encounter.modularSets) |
| 125 |
.map((modularSet) => modularSet?.name) |
| Error |
Row 126, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 126 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 127 |
|
| 128 |
// eslint-disable-next-line prefer-const |
| 129 |
gamesModularSetsWins = encounters |
| 130 |
.filter((encounter) => encounter.result === ResultEnum.WON) |
| 131 |
.filter((encounter) => encounter.modularSets != null) |
| 132 |
.flatMap((encounter) => encounter.modularSets) |
| 133 |
.map((modularSet) => modularSet?.name) |
| Error |
Row 134, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 134 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 135 |
} |
| 136 |
</script> |
| 137 |
|
| 138 |
<Title title="Stats" /> |
| 139 |
<Subtitle title="Games" /> |
| 140 |
<div>{encounters.length}</div> |
| 141 |
|
| 142 |
<Subtitle title="Number of heroes / Games" /> |
| Error |
Row 143, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| 143 |
<StatsTable data="{Array.from(nbHeroesGames).sort()}" total="{encounters.length}" /> |
| 144 |
|
| 145 |
<Subtitle title="Results" /> |
| Error |
Row 146, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| 146 |
<StatsTable data="{Array.from(results)}" total="{encounters.length}" /> |
| 147 |
|
| 148 |
<Subtitle title="Games / Heroes / Win %" /> |
| Error |
Row 149, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| 149 |
<StatsTable data="{Array.from(gamesHeroes).sort()}" wins="{gamesHeroesWins}" dates="{gamesHeroesLastDate}" /> |
| 150 |
|
| 151 |
<Subtitle title="Games / Difficulties / Win %" /> |
| Error |
Row 152, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| 152 |
<StatsTable data="{Array.from(gamesDifficulties).sort()}" wins="{gamesDifficultiesWins}" /> |
| 153 |
|
| 154 |
<Subtitle title="Games / Aspects / Win %" /> |
| Error |
Row 155, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| 155 |
<StatsTable data="{Array.from(gamesAspects).sort()}" wins="{gamesAspectsWins}" /> |
| 156 |
|
| 157 |
<Subtitle title="Games / Scenarios / Win %" /> |
| Error |
Row 158, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| 158 |
<StatsTable data="{Array.from(gamesScenarios).sort()}" wins="{gamesScenariosWins}" dates="{gamesScenariosLastDate}" /> |
| 159 |
|
| 160 |
<Subtitle title="Games / Modular Sets / Win %" /> |
| 161 |
<StatsTable |
| Error |
Row 162, Column 12: "Array.from() is not supported in IE 9"
compat/compat
|
| 162 |
data="{Array.from(gamesModularSets).sort()}" |
| 163 |
wins="{gamesModularSetsWins}" |
| 164 |
dates="{gamesModularSetsLastDate}" |
| 165 |
/> |
| 166 |
|
|
|
|
/apps/mc/src/lib/subtitle.svelte
|
0 problems
|
|
|
/apps/mc/src/lib/suggested.svelte
|
15 problems (15 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 45, Column 68: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 52, Column 12: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 55, Column 28: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 55, Column 36: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 76, Column 16: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 79, Column 34: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 80, Column 9: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 134, Column 40: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 183, Column 13: "Object.values() is not supported in IE 9"
compat/compat
|
| Error |
Row 187, Column 13: "Object.values() is not supported in IE 9"
compat/compat
|
| Error |
Row 191, Column 15: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 249, Column 79: "Object.values() is not supported in IE 9"
compat/compat
|
| Error |
Row 281, Column 38: "Object.values() is not supported in IE 9"
compat/compat
|
| Error |
Row 294, Column 79: "Object.values() is not supported in IE 9"
compat/compat
|
| Error |
Row 326, Column 38: "Object.values() is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
<svelte:options tag="mc-suggested" /> |
| 2 |
|
| 3 |
<script lang="ts"> |
| 4 |
import { random, weightedRandom } from "@jga/algorithms"; |
| 5 |
|
| 6 |
import type { Encounter, Hero, ModularSet, Scenario } from "$models"; |
| 7 |
import { DifficultyEnum, ResultEnum } from "$models"; |
| 8 |
|
| 9 |
import { EncountersService, HeroesService, ModularSetsService, ScenariosService } from "$services"; |
| 10 |
|
| 11 |
import { excludeHeroes, getWeightedData, notEmpty } from "./functions"; |
| 12 |
|
| 13 |
import Button from "$ui/button/src/button.svelte"; |
| 14 |
import Select from "$lib/select.svelte"; |
| 15 |
import Title from "$lib/title.svelte"; |
| 16 |
|
| 17 |
// eslint-disable-next-line import/no-mutable-exports |
| 18 |
export let heroes: Hero[] = []; |
| 19 |
// eslint-disable-next-line import/no-mutable-exports |
| 20 |
export let encounters: Encounter[] = []; |
| 21 |
// eslint-disable-next-line import/no-mutable-exports |
| 22 |
export let modules: ModularSet[] = []; |
| 23 |
// eslint-disable-next-line import/no-mutable-exports |
| 24 |
export let scenarios: Scenario[] = []; |
| 25 |
|
| 26 |
let gamesScenarios: Map<string, number>; |
| 27 |
let unorderedScenarios: Map<string, number>; |
| 28 |
let orderedScenarios: Map<string, number>; |
| 29 |
|
| 30 |
let scenariosWinEncounters: Map<string, Hero[]>; |
| 31 |
let progressionsEncounters: Map<Scenario, Partial<Encounter>[]>; |
| 32 |
let randomEncounters: Partial<Encounter>[]; |
| 33 |
let suggestedEncounters: Partial<Encounter>[]; |
| 34 |
|
| 35 |
$: { |
| 36 |
// heroes = heroes; |
| 37 |
// encounters = encounters; |
| 38 |
// modules = modules; |
| 39 |
// scenarios = scenarios; |
| 40 |
|
| 41 |
// order scenarios by play count |
| 42 |
// eslint-disable-next-line prefer-const |
| 43 |
gamesScenarios = encounters |
| 44 |
.map((encounter) => encounter.scenario.name) |
| Error |
Row 45, Column 68: "Map is not supported in IE 9"
compat/compat
|
| 45 |
.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map()); |
| 46 |
|
| 47 |
// eslint-disable-next-line prefer-const |
| 48 |
unorderedScenarios = scenarios.reduce((acc, e) => { |
| 49 |
acc.set(e, (acc.get(e) || 0) + (gamesScenarios.get(e.name) || 0)); |
| 50 |
|
| 51 |
return acc; |
| Error |
Row 52, Column 12: "Map is not supported in IE 9"
compat/compat
|
| 52 |
}, new Map()); |
| 53 |
|
| 54 |
// eslint-disable-next-line prefer-const |
| Error |
Row 55, Column 28: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 55, Column 36: "Array.from() is not supported in IE 9"
compat/compat
|
| 55 |
orderedScenarios = new Map(Array.from(unorderedScenarios.entries()).sort((a, b) => a[1] - b[1])); |
| 56 |
|
| 57 |
// eslint-disable-next-line prefer-const |
| 58 |
scenariosWinEncounters = encounters |
| 59 |
.filter((encounter) => encounter.result === ResultEnum.WON) |
| 60 |
.reduce((acc, e) => { |
| 61 |
if (!acc.has(e.scenario.name)) { |
| 62 |
acc.set(e.scenario.name, []); |
| 63 |
} |
| 64 |
|
| 65 |
const newHeroes = acc.get(e.scenario.name); |
| 66 |
[e] |
| 67 |
.flatMap((encounter) => encounter.heroes) |
| 68 |
.filter((hero) => hero != null) |
| 69 |
.map((hero) => hero.name) |
| 70 |
.filter((hero, i, array) => array.indexOf(hero) === i) |
| 71 |
.forEach((hero) => newHeroes.push(hero)); |
| 72 |
|
| 73 |
acc.set(e.scenario.name, newHeroes.sort()); |
| 74 |
|
| 75 |
return acc; |
| Error |
Row 76, Column 16: "Map is not supported in IE 9"
compat/compat
|
| 76 |
}, new Map()); |
| 77 |
|
| 78 |
// eslint-disable-next-line prefer-const |
| Error |
Row 79, Column 34: "Map is not supported in IE 9"
compat/compat
|
| 79 |
progressionsEncounters = new Map(); |
| Error |
Row 80, Column 9: "Array.from() is not supported in IE 9"
compat/compat
|
| 80 |
Array.from(orderedScenarios.keys()).forEach((scenario) => { |
| 81 |
heroes.forEach((hero) => { |
| 82 |
if ( |
| 83 |
!scenariosWinEncounters.has(scenario.name) || |
| 84 |
!scenariosWinEncounters.get(scenario.name).includes(hero.name) |
| 85 |
) { |
| 86 |
if (!progressionsEncounters.has(scenario)) { |
| 87 |
progressionsEncounters.set(scenario, []); |
| 88 |
} |
| 89 |
|
| 90 |
const tryHeroes = progressionsEncounters.get(scenario) as Partial<Encounter>[]; |
| 91 |
tryHeroes.push({ |
| 92 |
scenario, |
| 93 |
modularSets: scenario.modularSets, |
| 94 |
difficulty: DifficultyEnum.STANDARD, |
| 95 |
heroes: [hero], |
| 96 |
}); |
| 97 |
|
| 98 |
progressionsEncounters.set(scenario, tryHeroes); |
| 99 |
} |
| 100 |
}); |
| 101 |
}); |
| 102 |
|
| 103 |
// eslint-disable-next-line prefer-const |
| 104 |
randomEncounters = []; |
| 105 |
|
| 106 |
if (scenarios.length > 0 && modules.length > 0 && heroes.length > 0) { |
| 107 |
// Add 5 random scenario |
| 108 |
[1, 2, 3, 4, 5].forEach(() => { |
| 109 |
const [weightedScenarios, weightedModularSets, weightedHeroes] = getWeightedData( |
| 110 |
encounters, |
| 111 |
scenarios, |
| 112 |
modules, |
| 113 |
heroes, |
| 114 |
); |
| 115 |
|
| 116 |
const randomScenario = weightedRandom(scenarios, weightedScenarios); |
| 117 |
const randomModularSet = weightedRandom(modules, weightedModularSets); |
| 118 |
const randomHero = weightedRandom(heroes, weightedHeroes); |
| 119 |
|
| 120 |
const encounter = { |
| 121 |
scenario: randomScenario, |
| 122 |
heroes: [randomHero], |
| 123 |
modularSets: [randomModularSet], |
| 124 |
}; |
| 125 |
|
| 126 |
randomEncounters.push(encounter); |
| 127 |
}); |
| 128 |
} |
| 129 |
|
| 130 |
// eslint-disable-next-line prefer-const |
| 131 |
suggestedEncounters = []; |
| 132 |
// Pick a random one for each progression scenario |
| 133 |
progressionsEncounters.forEach((scenario) => { |
| Error |
Row 134, Column 40: "Array.from() is not supported in IE 9"
compat/compat
|
| 134 |
const scenarioEncounters = Array.from(scenario); |
| 135 |
const scenarioEncounter = scenarioEncounters[random(0, scenarioEncounters.length - 1)]; |
| 136 |
|
| 137 |
suggestedEncounters.push(scenarioEncounter); |
| 138 |
}); |
| 139 |
} |
| 140 |
|
| 141 |
async function add(event) { |
| 142 |
const { parentNode } = event.detail.parentNode; |
| 143 |
|
| 144 |
const isRandom = parentNode.classList.contains("random"); |
| 145 |
|
| 146 |
const scenarioElement = parentNode.children[0]; |
| 147 |
const modulesElement = parentNode.children[1]; |
| 148 |
const difficultyElement = parentNode.children[2]; |
| 149 |
const hero1Element = parentNode.children[3]; |
| 150 |
const hero2Element = parentNode.children[4]; |
| 151 |
const hero3Element = parentNode.children[5]; |
| 152 |
const hero4Element = parentNode.children[6]; |
| 153 |
const resultElement = parentNode.children[7]; |
| 154 |
|
| 155 |
const scenariosService = new ScenariosService(); |
| 156 |
const heroesService = new HeroesService(); |
| 157 |
const modularSetsService = new ModularSetsService(); |
| 158 |
|
| 159 |
const encounterHeroes = []; |
| 160 |
|
| 161 |
const scenarioValue = isRandom ? scenarioElement.children[0].value : scenarioElement.innerHTML; |
| 162 |
|
| 163 |
const scenario = await scenariosService.find(scenarioValue); |
| 164 |
const hero1 = await heroesService.find(hero1Element.children[0].value); |
| 165 |
encounterHeroes.push(hero1); |
| 166 |
|
| 167 |
if (hero2Element.children[0].value !== "") { |
| 168 |
const hero2 = await heroesService.find(hero2Element.children[0].value); |
| 169 |
encounterHeroes.push(hero2); |
| 170 |
} |
| 171 |
|
| 172 |
if (hero3Element.children[0].value !== "") { |
| 173 |
const hero3 = await heroesService.find(hero3Element.children[0].value); |
| 174 |
encounterHeroes.push(hero3); |
| 175 |
} |
| 176 |
|
| 177 |
if (hero4Element.children[0].value !== "") { |
| 178 |
const hero4 = await heroesService.find(hero4Element.children[0].value); |
| 179 |
encounterHeroes.push(hero4); |
| 180 |
} |
| 181 |
|
| 182 |
const difficulty = |
| Error |
Row 183, Column 13: "Object.values() is not supported in IE 9"
compat/compat
|
| 183 |
Object.values(DifficultyEnum).find((x) => x === difficultyElement.children[0].value) || |
| 184 |
DifficultyEnum.STANDARD; |
| 185 |
|
| 186 |
const result = |
| Error |
Row 187, Column 13: "Object.values() is not supported in IE 9"
compat/compat
|
| 187 |
Object.values(ResultEnum).find((x) => x === resultElement.children[0].value) || ResultEnum.FORFEIT; |
| 188 |
|
| 189 |
// Retrieve modular sets |
| 190 |
const encounterModularSetsValues = isRandom |
| Error |
Row 191, Column 15: "Array.from() is not supported in IE 9"
compat/compat
|
| 191 |
? Array.from(modulesElement.children[0].selectedOptions, (option) => option.value) |
| 192 |
: modulesElement.innerHTML.split(", "); |
| 193 |
|
| 194 |
const rawEncounterModularSets = await Promise.all( |
| 195 |
encounterModularSetsValues.map((modularSet) => modularSetsService.find(modularSet)), |
| 196 |
); |
| 197 |
const encounterModules: ModularSet[] = rawEncounterModularSets.filter(notEmpty); |
| 198 |
|
| 199 |
const encounter = { |
| 200 |
id: null, |
| 201 |
scenario, |
| 202 |
encounterHeroes, |
| 203 |
modularSets: encounterModules, |
| 204 |
difficulty, |
| 205 |
result, |
| 206 |
}; |
| 207 |
|
| 208 |
// console.log(encounter); |
| 209 |
|
| 210 |
const encountersService = new EncountersService(); |
| 211 |
encountersService.save(encounter).then(() => window.location.reload()); |
| 212 |
} |
| 213 |
</script> |
| 214 |
|
| 215 |
<Title title="Suggested encounters" /> |
| 216 |
|
| 217 |
<table> |
| 218 |
<thead> |
| 219 |
<tr> |
| 220 |
<th>Scenario</th> |
| 221 |
<th>Modular Sets</th> |
| 222 |
<th>Difficulty</th> |
| 223 |
<th>Hero 1</th> |
| 224 |
<th>Hero 2</th> |
| 225 |
<th>Hero 3</th> |
| 226 |
<th>Hero 4</th> |
| 227 |
<th>Result</th> |
| 228 |
<th></th> |
| 229 |
</tr> |
| 230 |
</thead> |
| 231 |
<tbody> |
| 232 |
<!-- Add 5 random encounters --> |
| 233 |
{#each randomEncounters as encounter} |
| 234 |
<tr class="random"> |
| 235 |
<td> |
| 236 |
<Select |
| 237 |
defaultValue="{encounter.scenario.name}" |
| 238 |
source="{scenarios.map((scenario) => scenario.name)}" |
| 239 |
/> |
| 240 |
</td> |
| 241 |
<td> |
| 242 |
<Select |
| 243 |
defaultValue="{encounter.modularSets[0].name}" |
| 244 |
source="{modules.map((module) => module.name)}" |
| 245 |
multiple="{true}" |
| 246 |
/> |
| 247 |
</td> |
| 248 |
<td> |
| Error |
Row 249, Column 79: "Object.values() is not supported in IE 9"
compat/compat
|
| 249 |
<Select defaultValue="{DifficultyEnum.STANDARD}" source="{Object.values(DifficultyEnum)}" /> |
| 250 |
</td> |
| 251 |
<td> |
| 252 |
<Select |
| 253 |
defaultValue="{encounter.heroes[0].name}" |
| 254 |
source="{excludeHeroes(heroes, encounter.scenario.name, scenariosWinEncounters).map( |
| 255 |
(hero) => hero.name, |
| 256 |
)}" |
| 257 |
/> |
| 258 |
</td> |
| 259 |
<td> |
| 260 |
<Select |
| 261 |
source="{excludeHeroes(heroes, encounter.scenario.name, scenariosWinEncounters).map( |
| 262 |
(hero) => hero.name, |
| 263 |
)}" |
| 264 |
/> |
| 265 |
</td> |
| 266 |
<td> |
| 267 |
<Select |
| 268 |
source="{excludeHeroes(heroes, encounter.scenario.name, scenariosWinEncounters).map( |
| 269 |
(hero) => hero.name, |
| 270 |
)}" |
| 271 |
/> |
| 272 |
</td> |
| 273 |
<td> |
| 274 |
<Select |
| 275 |
source="{excludeHeroes(heroes, encounter.scenario.name, scenariosWinEncounters).map( |
| 276 |
(hero) => hero.name, |
| 277 |
)}" |
| 278 |
/> |
| 279 |
</td> |
| 280 |
<td> |
| Error |
Row 281, Column 38: "Object.values() is not supported in IE 9"
compat/compat
|
| 281 |
<Select source="{Object.values(ResultEnum)}" /> |
| 282 |
</td> |
| 283 |
<td> |
| 284 |
<Button label="Add" on:buttonClicked="{add}" /> |
| 285 |
</td> |
| 286 |
</tr> |
| 287 |
{/each} |
| 288 |
<!-- Add progression encounters --> |
| 289 |
{#each suggestedEncounters as encounter} |
| 290 |
<tr class="suggested"> |
| 291 |
<td>{encounter.scenario.name}</td> |
| 292 |
<td>{encounter.modularSets?.map((module) => module.name).join(", ") || ""}</td> |
| 293 |
<td> |
| Error |
Row 294, Column 79: "Object.values() is not supported in IE 9"
compat/compat
|
| 294 |
<Select defaultValue="{DifficultyEnum.STANDARD}" source="{Object.values(DifficultyEnum)}" /> |
| 295 |
</td> |
| 296 |
<td> |
| 297 |
<Select |
| 298 |
defaultValue="{encounter.heroes[0].name}" |
| 299 |
source="{excludeHeroes(heroes, encounter.scenario.name, scenariosWinEncounters).map( |
| 300 |
(hero) => hero.name, |
| 301 |
)}" |
| 302 |
/> |
| 303 |
</td> |
| 304 |
<td> |
| 305 |
<Select |
| 306 |
source="{excludeHeroes(heroes, encounter.scenario.name, scenariosWinEncounters).map( |
| 307 |
(hero) => hero.name, |
| 308 |
)}" |
| 309 |
/> |
| 310 |
</td> |
| 311 |
<td> |
| 312 |
<Select |
| 313 |
source="{excludeHeroes(heroes, encounter.scenario.name, scenariosWinEncounters).map( |
| 314 |
(hero) => hero.name, |
| 315 |
)}" |
| 316 |
/> |
| 317 |
</td> |
| 318 |
<td> |
| 319 |
<Select |
| 320 |
source="{excludeHeroes(heroes, encounter.scenario.name, scenariosWinEncounters).map( |
| 321 |
(hero) => hero.name, |
| 322 |
)}" |
| 323 |
/> |
| 324 |
</td> |
| 325 |
<td> |
| Error |
Row 326, Column 38: "Object.values() is not supported in IE 9"
compat/compat
|
| 326 |
<Select source="{Object.values(ResultEnum)}" /> |
| 327 |
</td> |
| 328 |
<td> |
| 329 |
<Button label="Add" on:buttonClicked="{add}" /> |
| 330 |
</td> |
| 331 |
</tr> |
| 332 |
{/each} |
| 333 |
</tbody> |
| 334 |
</table> |
| 335 |
|
|
|
|
/apps/mc/src/lib/title.svelte
|
0 problems
|
|
|
/apps/mc/src/lib/upcoming.svelte
|
0 problems
|
|
|
/apps/mc/src/routes/+layout.ts
|
0 problems
|
|
|
/apps/mc/src/routes/+page.svelte
|
0 problems
|
|
|
/apps/mc/src/services/encounters.ts
|
0 problems
|
|
|
/apps/mc/src/services/heroes.ts
|
0 problems
|
|
|
/apps/mc/src/services/index.ts
|
0 problems
|
|
|
/apps/mc/src/services/load.ts
|
0 problems
|
|
|
/apps/mc/src/services/modular-sets.ts
|
0 problems
|
|
|
/apps/mc/src/services/packs.ts
|
0 problems
|
|
|
/apps/mc/src/services/scenarios.ts
|
0 problems
|
|
|
/apps/mc/src/services/service.ts
|
0 problems
|
|
|
/apps/resume/src/app.d.ts
|
0 problems
|
|
|
/apps/resume/src/lib/contact.svelte
|
0 problems
|
|
|
/apps/resume/src/lib/education.svelte
|
0 problems
|
|
|
/apps/resume/src/lib/experience.svelte
|
0 problems
|
|
|
/apps/resume/src/lib/language.svelte
|
0 problems
|
|
|
/apps/resume/src/lib/profile.svelte
|
0 problems
|
|
|
/apps/resume/src/models/resume.ts
|
0 problems
|
|
|
/apps/resume/src/routes/+layout.ts
|
0 problems
|
|
|
/apps/resume/src/routes/+page.svelte
|
0 problems
|
|
|
/apps/roguelike/src/app.d.ts
|
0 problems
|
|
|
/apps/roguelike/src/lib/console.svelte
|
0 problems
|
|
|
/apps/roguelike/src/lib/game.svelte
|
0 problems
|
|
|
/apps/roguelike/src/lib/links.svelte
|
0 problems
|
|
|
/apps/roguelike/src/routes/+layout.ts
|
0 problems
|
|
|
/apps/roguelike/src/routes/+page.svelte
|
0 problems
|
|
|
/apps/roguelike/src/stores/index.ts
|
0 problems
|
|
|
/apps/roguelike/src/stores/messages.ts
|
0 problems
|
|
|
/apps/storybook/stories/Art/Pixel.stories.ts
|
0 problems
|
|
|
/apps/storybook/stories/Base/Buttons.stories.ts
|
0 problems
|
|
|
/apps/storybook/stories/Base/Shapes.stories.ts
|
0 problems
|
|
|
/apps/storybook/stories/Components/Collapse.stories.ts
|
0 problems
|
|
|
/apps/storybook/stories/Components/Data.stories.ts
|
0 problems
|
|
|
/apps/storybook/stories/Components/Leaderboard.stories.ts
|
0 problems
|
|
|
/apps/storybook/stories/Components/PlaceholderLoader.stories.ts
|
0 problems
|
|
|
/apps/storybook/stories/Components/Progress.stories.ts
|
0 problems
|
|
|
/apps/storybook/stories/Components/Table.stories.ts
|
0 problems
|
|
|
/apps/storybook/stories/Components/Tabs.stories.ts
|
0 problems
|
|
|
/libs/algorithms/src/coalesce.ts
|
0 problems
|
|
|
/libs/algorithms/src/index.ts
|
0 problems
|
|
|
/libs/algorithms/src/random.ts
|
0 problems
|
|
|
/libs/algorithms/src/shuffle.ts
|
0 problems
|
|
|
/libs/algorithms/src/sort.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 20, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
const sortCompare = <Element, Key extends keyof Element>(a: Element, b: Element, key: Key): number => { |
| 2 |
// eslint-disable-next-line security/detect-object-injection |
| 3 |
if (a[key] > b[key]) { |
| 4 |
return 1; |
| 5 |
} |
| 6 |
// eslint-disable-next-line security/detect-object-injection |
| 7 |
if (a[key] < b[key]) { |
| 8 |
return -1; |
| 9 |
} |
| 10 |
return 0; |
| 11 |
}; |
| 12 |
|
| 13 |
export const by = <Element, Key extends keyof Element>(array: Element[], key: Key): Element[] => { |
| 14 |
// eslint-disable-next-line security/detect-object-injection,no-nested-ternary |
| 15 |
return array.concat().sort((a: Element, b: Element) => sortCompare<Element, Key>(a, b, key)); |
| 16 |
}; |
| 17 |
|
| 18 |
// @src https://github.com/kutyel/typescript-algorithms/blob/master/src/bubbleSort/index.ts |
| 19 |
export const bubble = <Element>(array: Element[]): Element[] => { |
| Error |
Row 20, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| 20 |
const sorted = Array.from(array); |
| 21 |
|
| 22 |
// eslint-disable-next-line no-loops/no-loops, no-constant-condition |
| 23 |
while (true) { |
| 24 |
let swapped = false; |
| 25 |
|
| 26 |
// eslint-disable-next-line no-loops/no-loops |
| 27 |
for (let i = 0; i < sorted.length - 1; i++) { |
| 28 |
// eslint-disable-next-line security/detect-object-injection |
| 29 |
if (sorted[i] > sorted[i + 1]) { |
| 30 |
// eslint-disable-next-line security/detect-object-injection |
| 31 |
[sorted[i], sorted[i + 1]] = [sorted[i + 1], sorted[i]]; |
| 32 |
swapped = true; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
if (!swapped) { |
| 37 |
break; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
return sorted; |
| 42 |
}; |
| 43 |
|
| 44 |
export const insertion = <Element>(array: Element[]): Element[] => { |
| 45 |
const sorted = array; |
| 46 |
// eslint-disable-next-line no-loops/no-loops |
| 47 |
for (let index = 1; index < sorted.length; index++) { |
| 48 |
// eslint-disable-next-line security/detect-object-injection |
| 49 |
const currentItem: Element = sorted[index]; |
| 50 |
let currentLeftIndex: number = index - 1; |
| 51 |
|
| 52 |
// eslint-disable-next-line no-loops/no-loops, security/detect-object-injection |
| 53 |
while (currentLeftIndex >= 0 && sorted[currentLeftIndex] > currentItem) { |
| 54 |
// eslint-disable-next-line security/detect-object-injection |
| 55 |
sorted[currentLeftIndex + 1] = sorted[currentLeftIndex]; |
| 56 |
currentLeftIndex -= 1; |
| 57 |
} |
| 58 |
|
| 59 |
sorted[currentLeftIndex + 1] = currentItem; |
| 60 |
} |
| 61 |
|
| 62 |
return sorted; |
| 63 |
}; |
| 64 |
|
| 65 |
// @see https://www.jesuisundev.com/comprendre-les-algorithmes-de-tri-en-7-minutes/ |
| 66 |
export const merge = <Element>(array: Element[]): Element[] => { |
| 67 |
const sorted = array; |
| 68 |
|
| 69 |
if (sorted.length > 1) { |
| 70 |
const middleIndex = Math.floor(sorted.length / 2); |
| 71 |
const leftSide = sorted.slice(0, middleIndex); |
| 72 |
const rightSide = sorted.slice(middleIndex); |
| 73 |
|
| 74 |
merge(leftSide); |
| 75 |
merge(rightSide); |
| 76 |
|
| 77 |
let leftIndex = 0; |
| 78 |
let rightIndex = 0; |
| 79 |
let globalIndex = 0; |
| 80 |
|
| 81 |
// eslint-disable-next-line no-loops/no-loops |
| 82 |
while (leftIndex < leftSide.length && rightIndex < rightSide.length) { |
| 83 |
// eslint-disable-next-line security/detect-object-injection |
| 84 |
if (leftSide[leftIndex] < rightSide[rightIndex]) { |
| 85 |
// eslint-disable-next-line security/detect-object-injection |
| 86 |
sorted[globalIndex] = leftSide[leftIndex]; |
| 87 |
// eslint-disable-next-line no-plusplus |
| 88 |
leftIndex += 1; |
| 89 |
} else { |
| 90 |
// eslint-disable-next-line security/detect-object-injection |
| 91 |
sorted[globalIndex] = rightSide[rightIndex]; |
| 92 |
// eslint-disable-next-line no-plusplus |
| 93 |
rightIndex += 1; |
| 94 |
} |
| 95 |
globalIndex += 1; |
| 96 |
} |
| 97 |
|
| 98 |
// eslint-disable-next-line no-loops/no-loops |
| 99 |
while (leftIndex < leftSide.length) { |
| 100 |
// eslint-disable-next-line security/detect-object-injection |
| 101 |
sorted[globalIndex] = leftSide[leftIndex]; |
| 102 |
leftIndex += 1; |
| 103 |
globalIndex += 1; |
| 104 |
} |
| 105 |
|
| 106 |
// eslint-disable-next-line no-loops/no-loops |
| 107 |
while (rightIndex < rightSide.length) { |
| 108 |
// eslint-disable-next-line security/detect-object-injection |
| 109 |
sorted[globalIndex] = rightSide[rightIndex]; |
| 110 |
rightIndex += 1; |
| 111 |
globalIndex += 1; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
return sorted; |
| 116 |
}; |
| 117 |
|
| 118 |
export const quick = <Element>(array: Element[]): Element[] => { |
| 119 |
if (array.length <= 1) { |
| 120 |
return array; |
| 121 |
} |
| 122 |
const pivot = array.pop() as Element; |
| 123 |
const smallerValues = array.filter((item) => item < pivot); |
| 124 |
const biggerValues = array.filter((item) => item > pivot); |
| 125 |
|
| 126 |
return [...quick(smallerValues), pivot, ...quick(biggerValues)]; |
| 127 |
}; |
| 128 |
|
|
|
|
/libs/algorithms/tests/coalesce.spec.ts
|
0 problems
|
|
|
/libs/algorithms/tests/random.spec.ts
|
0 problems
|
|
|
/libs/algorithms/tests/shuffle.spec.ts
|
0 problems
|
|
|
/libs/algorithms/tests/sort.spec.ts
|
0 problems
|
|
|
/libs/algorithms/tests/weighted-random.spec.ts
|
0 problems
|
|
|
/libs/apis/src/index.ts
|
0 problems
|
|
|
/libs/apis/src/response.ts
|
0 problems
|
|
|
/libs/apis/tests/response.spec.ts
|
0 problems
|
|
|
/libs/arrays/src/average.ts
|
0 problems
|
|
|
/libs/arrays/src/count.ts
|
0 problems
|
|
|
/libs/arrays/src/getby.ts
|
0 problems
|
|
|
/libs/arrays/src/index.ts
|
0 problems
|
|
|
/libs/arrays/src/isempty.ts
|
0 problems
|
|
|
/libs/arrays/src/unique.ts
|
0 problems
|
|
|
/libs/arrays/tests/average.spec.ts
|
0 problems
|
|
|
/libs/arrays/tests/count.spec.ts
|
0 problems
|
|
|
/libs/arrays/tests/getby.spec.ts
|
0 problems
|
|
|
/libs/arrays/tests/isempty.spec.ts
|
0 problems
|
|
|
/libs/arrays/tests/unique.spec.ts
|
0 problems
|
|
|
/libs/converters/tests/array-to-csv.spec.ts
|
0 problems
|
|
|
/libs/converters/tests/celsiustofahrenheit.spec.ts
|
0 problems
|
|
|
/libs/converters/tests/csv-to-json.spec.ts
|
0 problems
|
|
|
/libs/converters/tests/json-to-csv.spec.ts
|
0 problems
|
|
|
/libs/converters/tests/mapfromobject.spec.ts
|
2 problems (2 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 15, Column 61: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 15, Column 69: "Object.entries() is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { MapFromObject } from "@jga/converters/index"; |
| 2 |
|
| 3 |
describe("mapFormObject", () => { |
| 4 |
it("should return object property", () => { |
| 5 |
interface Model { |
| 6 |
firstname: string; |
| 7 |
lastname: string; |
| 8 |
} |
| 9 |
|
| 10 |
const model: Model = { |
| 11 |
firstname: "John", |
| 12 |
lastname: "Doe", |
| 13 |
}; |
| 14 |
|
| Error |
Row 15, Column 61: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 15, Column 69: "Object.entries() is not supported in IE 9"
compat/compat
|
| 15 |
const modelMap: MapFromObject<Model, keyof Model> = new Map(Object.entries(model)); |
| 16 |
|
| 17 |
expect(modelMap.get("firstname")).toBe(model.firstname); |
| 18 |
expect(modelMap.get("lastname")).toBe(model.lastname); |
| 19 |
}); |
| 20 |
}); |
| 21 |
|
|
|
|
/libs/data/src/index.ts
|
0 problems
|
|
|
/libs/data/src/queue.ts
|
0 problems
|
|
|
/libs/data/src/stack.ts
|
0 problems
|
|
|
/libs/data/tests/queue.spec.ts
|
0 problems
|
|
|
/libs/data/tests/stack.spec.ts
|
0 problems
|
|
|
/libs/dates/src/add.ts
|
0 problems
|
|
|
/libs/dates/src/current-time.ts
|
0 problems
|
|
|
/libs/dates/src/diff.ts
|
0 problems
|
|
|
/libs/dates/src/index.ts
|
0 problems
|
|
|
/libs/dates/src/substract.ts
|
0 problems
|
|
|
/libs/dates/tests/add.spec.ts
|
0 problems
|
|
|
/libs/dates/tests/currenttime.spec.ts
|
0 problems
|
|
|
/libs/dates/tests/diff.spec.ts
|
0 problems
|
|
|
/libs/dates/tests/substract.spec.ts
|
0 problems
|
|
|
/libs/games/src/colors/colors.ts
|
0 problems
|
|
|
/libs/games/src/colors/hsbToRgb.ts
|
0 problems
|
|
|
/libs/games/src/colors/index.ts
|
0 problems
|
|
|
/libs/games/src/colors/random.ts
|
0 problems
|
|
|
/libs/games/src/colors/rgbToHex.ts
|
0 problems
|
|
|
/libs/games/src/commands/index.ts
|
0 problems
|
|
|
/libs/games/src/commands/keys.ts
|
0 problems
|
|
|
/libs/games/src/commands/move.ts
|
0 problems
|
|
|
/libs/games/src/commands/roll.ts
|
0 problems
|
|
|
/libs/games/src/console/console.ts
|
0 problems
|
|
|
/libs/games/src/console/index.ts
|
0 problems
|
|
|
/libs/games/src/console/interface.ts
|
0 problems
|
|
|
/libs/games/src/console/renderer.ts
|
0 problems
|
|
|
/libs/games/src/dices/dice6.ts
|
0 problems
|
|
|
/libs/games/src/dices/diceBase.ts
|
0 problems
|
|
|
/libs/games/src/dices/diceInterface.ts
|
0 problems
|
|
|
/libs/games/src/dices/index.ts
|
0 problems
|
|
|
/libs/games/src/display/display.ts
|
0 problems
|
|
|
/libs/games/src/display/index.ts
|
0 problems
|
|
|
/libs/games/src/engine/components/appearance.ts
|
0 problems
|
|
|
/libs/games/src/engine/components/attack.ts
|
0 problems
|
|
|
/libs/games/src/engine/components/damageable.ts
|
0 problems
|
|
|
/libs/games/src/engine/components/enum.ts
|
0 problems
|
|
|
/libs/games/src/engine/components/index.ts
|
0 problems
|
|
|
/libs/games/src/engine/components/moveable.ts
|
0 problems
|
|
|
/libs/games/src/engine/components/position.ts
|
0 problems
|
|
|
/libs/games/src/engine/components/spread.ts
|
0 problems
|
|
|
/libs/games/src/engine/entities/actor.ts
|
0 problems
|
|
|
/libs/games/src/engine/entities/entity.ts
|
0 problems
|
|
|
/libs/games/src/engine/entities/factory.ts
|
0 problems
|
|
|
/libs/games/src/engine/entities/index.ts
|
0 problems
|
|
|
/libs/games/src/engine/entities/player.ts
|
0 problems
|
|
|
/libs/games/src/engine/index.ts
|
0 problems
|
|
|
/libs/games/src/engine/loop.ts
|
0 problems
|
|
|
/libs/games/src/engine/scheduler.ts
|
0 problems
|
|
|
/libs/games/src/engine/systems/damage.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 13, Column 15: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { isAttackComponent, isDamageableComponent, ComponentName } from "../components"; |
| 2 |
|
| 3 |
import { Actor, Entity } from "../entities"; |
| 4 |
import { World } from "../world"; |
| 5 |
import { System } from "./system"; |
| 6 |
|
| 7 |
export class DamageSystem extends System { |
| 8 |
private readonly attacker: Actor; |
| 9 |
|
| 10 |
private readonly target: Entity; |
| 11 |
|
| 12 |
public constructor(attacker: Actor, target: Entity) { |
| Error |
Row 13, Column 15: "Map is not supported in IE 9"
compat/compat
|
| 13 |
super(new Map(), [ComponentName.DAMAGEABLE]); |
| 14 |
|
| 15 |
this.attacker = attacker; |
| 16 |
this.target = target; |
| 17 |
} |
| 18 |
|
| 19 |
public run(world: World): void { |
| 20 |
const attack = this.attacker.getComponent(ComponentName.ATTACK); |
| 21 |
const component = this.target.getComponent(ComponentName.DAMAGEABLE); |
| 22 |
|
| 23 |
if (isAttackComponent(attack) && isDamageableComponent(component)) { |
| 24 |
const remainingHitPoints = component.takeDamage(attack.getValue()); |
| 25 |
|
| 26 |
if (remainingHitPoints <= 0) { |
| 27 |
world.removeEntity(this.target); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
|
|
|
|
/libs/games/src/engine/systems/draw.ts
|
0 problems
|
|
|
/libs/games/src/engine/systems/index.ts
|
0 problems
|
|
|
/libs/games/src/engine/systems/movement.ts
|
2 problems (2 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 77, Column 16: "Array.from() is not supported in IE 9"
compat/compat
|
| Error |
Row 88, Column 26: "Array.from() is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { GameMap, PositionInterface } from "../../maps/index"; |
| 2 |
import { TileInterface } from "../../tiles/index"; |
| 3 |
|
| 4 |
import { ComponentName, isPositionComponent } from "../components"; |
| 5 |
|
| 6 |
import { isActor, Entity, isEntity } from "../entities"; |
| 7 |
import { World } from "../world"; |
| 8 |
import { DamageSystem } from "./damage"; |
| 9 |
import { System } from "./system"; |
| 10 |
|
| 11 |
export interface MoveInterface { |
| 12 |
canMove: boolean; |
| 13 |
newPosition: PositionInterface | null; |
| 14 |
} |
| 15 |
|
| 16 |
export class MovementSystem extends System { |
| 17 |
protected position: PositionInterface; |
| 18 |
|
| 19 |
protected targets: Map<string, Entity>; |
| 20 |
|
| 21 |
public constructor(entities: Map<string, Entity>, position: PositionInterface, targets: Map<string, Entity>) { |
| 22 |
super(entities, [ComponentName.MOVEABLE, ComponentName.POSITION]); |
| 23 |
|
| 24 |
this.position = position; |
| 25 |
this.targets = this.filterEntities(targets, [ComponentName.POSITION]); |
| 26 |
} |
| 27 |
|
| 28 |
public getPosition(): PositionInterface { |
| 29 |
return this.position; |
| 30 |
} |
| 31 |
|
| 32 |
public run(world: World): void { |
| 33 |
return this.entities.forEach((entity): void => { |
| 34 |
const move = this.canMove(world); |
| 35 |
|
| 36 |
if (move.canMove) { |
| 37 |
const positionComponent = entity.getComponent(ComponentName.POSITION); |
| 38 |
|
| 39 |
if (isPositionComponent(positionComponent)) { |
| 40 |
positionComponent.setPosition(this.position); |
| 41 |
} |
| 42 |
} |
| 43 |
}); |
| 44 |
} |
| 45 |
|
| 46 |
public canMove(world: World): MoveInterface { |
| 47 |
const move: MoveInterface = { |
| 48 |
canMove: false, |
| 49 |
newPosition: this.position, |
| 50 |
}; |
| 51 |
|
| 52 |
if (this.position != null && world != null && world.getMap() !== null) { |
| 53 |
const map: GameMap = world.getMap(); |
| 54 |
const tile: TileInterface = map.getTile(this.position); |
| 55 |
const targets: Entity[] = this.filterTargetsAtPosition(); |
| 56 |
|
| 57 |
if (tile !== null) { |
| 58 |
// if there is a target, attack |
| 59 |
if (targets.length !== 0) { |
| 60 |
this.attack(targets[0], world); |
| 61 |
} else { |
| 62 |
// else move |
| 63 |
// eslint-disable-next-line no-lonely-if |
| 64 |
if (tile.isWalkable) { |
| 65 |
move.canMove = true; |
| 66 |
} else if (tile.isDiggable) { |
| 67 |
map.dig(this.position); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
return move; |
| 74 |
} |
| 75 |
|
| 76 |
private filterTargetsAtPosition(): Entity[] { |
| Error |
Row 77, Column 16: "Array.from() is not supported in IE 9"
compat/compat
|
| 77 |
return Array.from(this.targets.values()).filter((entity) => { |
| 78 |
const entityPosition = entity.getComponent(ComponentName.POSITION); |
| 79 |
|
| 80 |
return isPositionComponent(entityPosition) |
| 81 |
? this.position.x === entityPosition.getPosition().x && |
| 82 |
this.position.y === entityPosition.getPosition().y |
| 83 |
: false; |
| 84 |
}); |
| 85 |
} |
| 86 |
|
| 87 |
private attack(target: Entity, world: World): void { |
| Error |
Row 88, Column 26: "Array.from() is not supported in IE 9"
compat/compat
|
| 88 |
const attacker = Array.from(this.entities.values())[0]; |
| 89 |
|
| 90 |
if ( |
| 91 |
isActor(attacker) && |
| 92 |
isEntity(target) && |
| 93 |
attacker.hasComponent(ComponentName.ATTACK) && |
| 94 |
target.hasComponent(ComponentName.DAMAGEABLE) |
| 95 |
) { |
| 96 |
const damageSystem = new DamageSystem(attacker, target); |
| 97 |
damageSystem.run(world); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
|
|
|
/libs/games/src/engine/systems/position.ts
|
0 problems
|
|
|
/libs/games/src/engine/systems/spread.ts
|
0 problems
|
|
|
/libs/games/src/engine/systems/system.ts
|
2 problems (2 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 7, Column 47: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 21, Column 47: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { SystemInterface, WorldInterface } from "@jga/patterns"; |
| 2 |
|
| 3 |
import { ComponentName } from "../components"; |
| 4 |
import { Entity } from "../entities"; |
| 5 |
|
| 6 |
export abstract class System implements SystemInterface { |
| Error |
Row 7, Column 47: "Map is not supported in IE 9"
compat/compat
|
| 7 |
protected entities: Map<string, Entity> = new Map<string, Entity>(); |
| 8 |
|
| 9 |
public constructor(entities: Map<string, Entity>, filters: ComponentName[]) { |
| 10 |
this.entities = this.filterEntities(entities, filters); |
| 11 |
} |
| 12 |
|
| 13 |
public getEntities(): Map<string, Entity> { |
| 14 |
return this.entities; |
| 15 |
} |
| 16 |
|
| 17 |
public abstract run(world?: WorldInterface): void; |
| 18 |
|
| 19 |
// eslint-disable-next-line class-methods-use-this |
| 20 |
protected filterEntities(entities: Map<string, Entity>, filters: ComponentName[]): Map<string, Entity> { |
| Error |
Row 21, Column 47: "Map is not supported in IE 9"
compat/compat
|
| 21 |
const filtered: Map<string, Entity> = new Map<string, Entity>(); |
| 22 |
|
| 23 |
entities.forEach((entity, key): void => { |
| 24 |
let found = 0; |
| 25 |
filters.forEach((filter): void => { |
| 26 |
if (entity != null && entity.hasComponent(filter)) { |
| 27 |
found += 1; |
| 28 |
} |
| 29 |
}); |
| 30 |
|
| 31 |
if (found === filters.length) { |
| 32 |
filtered.set(key, entity); |
| 33 |
} |
| 34 |
}); |
| 35 |
|
| 36 |
return filtered; |
| 37 |
} |
| 38 |
} |
| 39 |
|
|
|
|
/libs/games/src/engine/world.ts
|
3 problems (3 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 37, Column 25: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 38, Column 24: "Set is not supported in IE 9"
compat/compat
|
| Error |
Row 173, Column 35: "Array.from() is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { random } from "@jga/algorithms"; |
| 2 |
import { uuid } from "@jga/generators"; |
| 3 |
import { Command, CommandManager, CommandResultInterface, WorldInterface, SystemInterface } from "@jga/patterns"; |
| 4 |
|
| 5 |
import { GameMap, PositionInterface } from "../maps/index"; |
| 6 |
|
| 7 |
import { Scheduler } from "./scheduler"; |
| 8 |
import { Loop } from "./loop"; |
| 9 |
|
| 10 |
import { Entity, EntityFactoryInterface, Player } from "./entities"; |
| 11 |
import { isPositionComponent, ComponentName } from "./components"; |
| 12 |
|
| 13 |
export class World implements WorldInterface { |
| 14 |
protected entities: Map<string, Entity>; |
| 15 |
|
| 16 |
protected systems: Set<SystemInterface>; |
| 17 |
|
| 18 |
private player!: Player; |
| 19 |
|
| 20 |
private readonly scheduler: Scheduler; |
| 21 |
|
| 22 |
private readonly map: GameMap; |
| 23 |
|
| 24 |
private readonly loop: Loop; |
| 25 |
|
| 26 |
private readonly commandManager: CommandManager; |
| 27 |
|
| 28 |
private readonly entityFactory: EntityFactoryInterface; |
| 29 |
|
| 30 |
// eslint-disable-next-line max-params |
| 31 |
public constructor( |
| 32 |
scheduler: Scheduler, |
| 33 |
map: GameMap, |
| 34 |
commandManager: CommandManager, |
| 35 |
factory: EntityFactoryInterface, |
| 36 |
) { |
| Error |
Row 37, Column 25: "Map is not supported in IE 9"
compat/compat
|
| 37 |
this.entities = new Map<string, Entity>(); |
| Error |
Row 38, Column 24: "Set is not supported in IE 9"
compat/compat
|
| 38 |
this.systems = new Set<SystemInterface>(); |
| 39 |
this.scheduler = scheduler; |
| 40 |
this.map = map; |
| 41 |
this.loop = new Loop(this.scheduler); |
| 42 |
this.commandManager = commandManager; |
| 43 |
this.entityFactory = factory; |
| 44 |
} |
| 45 |
|
| 46 |
public addEntity(entity: Entity, repeatable = false): Map<string, Entity> { |
| 47 |
this.scheduler.add(entity, repeatable); |
| 48 |
|
| 49 |
return this.entities.set(entity.getId(), entity); |
| 50 |
} |
| 51 |
|
| 52 |
public removeEntity(entity: Entity): Map<string, Entity> { |
| 53 |
if (this.entities.has(entity.getId())) { |
| 54 |
this.scheduler.remove(entity); |
| 55 |
this.entities.delete(entity.getId()); |
| 56 |
} |
| 57 |
|
| 58 |
return this.entities; |
| 59 |
} |
| 60 |
|
| 61 |
public createEntity(): Entity { |
| 62 |
const entity = new Entity(this.generateId()); |
| 63 |
|
| 64 |
this.addEntity(entity); |
| 65 |
|
| 66 |
return entity; |
| 67 |
} |
| 68 |
|
| 69 |
public getEntities(): Map<string, Entity> { |
| 70 |
return this.entities; |
| 71 |
} |
| 72 |
|
| 73 |
public createPlayer(): Player { |
| 74 |
this.player = new Player(this.generateId()); |
| 75 |
|
| 76 |
this.addEntityAtRandomPosition(this.player, true); |
| 77 |
|
| 78 |
return this.getPlayer(); |
| 79 |
} |
| 80 |
|
| 81 |
public getSystems(): Set<SystemInterface> { |
| 82 |
return this.systems; |
| 83 |
} |
| 84 |
|
| 85 |
public registerSystems(systems: SystemInterface[]): void { |
| 86 |
this.systems.clear(); |
| 87 |
systems.forEach((system) => this.systems.add(system)); |
| 88 |
} |
| 89 |
|
| 90 |
public getPlayer(): Player { |
| 91 |
return this.player; |
| 92 |
} |
| 93 |
|
| 94 |
public getMap(): GameMap { |
| 95 |
return this.map; |
| 96 |
} |
| 97 |
|
| 98 |
public execute(command: Command): CommandResultInterface { |
| 99 |
return this.commandManager.execute(command); |
| 100 |
} |
| 101 |
|
| 102 |
public process(): void { |
| 103 |
return this.systems.forEach((system): void => { |
| 104 |
system.run(this); |
| 105 |
}); |
| 106 |
} |
| 107 |
|
| 108 |
public run(system: SystemInterface): void { |
| 109 |
system.run(this); |
| 110 |
} |
| 111 |
|
| 112 |
public addEntityAtRandomPosition(entity: Entity, repeatable = false): Map<string, Entity> { |
| 113 |
if (entity.hasComponent(ComponentName.POSITION)) { |
| 114 |
const component = entity.getComponent(ComponentName.POSITION); |
| 115 |
if (isPositionComponent(component)) { |
| 116 |
component.setPosition(this.getRandomFloorPosition()); |
| 117 |
} |
| 118 |
|
| 119 |
this.addEntity(entity, repeatable); |
| 120 |
} |
| 121 |
|
| 122 |
return this.entities; |
| 123 |
} |
| 124 |
|
| 125 |
public lock(): Loop { |
| 126 |
return this.loop.lock(); |
| 127 |
} |
| 128 |
|
| 129 |
public unlock(): Loop { |
| 130 |
return this.loop.unlock(); |
| 131 |
} |
| 132 |
|
| 133 |
public async mainLoop(): Promise<Loop> { |
| 134 |
return this.loop.start(); |
| 135 |
} |
| 136 |
|
| 137 |
public getRandomFloorPosition(): PositionInterface { |
| 138 |
let x: number; |
| 139 |
let y: number; |
| 140 |
|
| 141 |
// eslint-disable-next-line no-loops/no-loops |
| 142 |
do { |
| 143 |
x = random(0, this.map.getWidth() - 1); |
| 144 |
y = random(0, this.map.getHeight() - 1); |
| 145 |
} while (!this.isEmptyFloor({ x, y })); |
| 146 |
|
| 147 |
return this.hasTargetAtPosition({ x, y }) ? { x, y } : this.getRandomFloorPosition(); |
| 148 |
} |
| 149 |
|
| 150 |
public isEmptyFloor(position: PositionInterface): boolean { |
| 151 |
return !this.isNotEmptyFloor(position); |
| 152 |
} |
| 153 |
|
| 154 |
private isNotEmptyFloor(position: PositionInterface): boolean { |
| 155 |
return this.map.getTile(position) !== null && !this.map.getTile(position).isWalkable; |
| 156 |
} |
| 157 |
|
| 158 |
public getEntityFactory(): EntityFactoryInterface { |
| 159 |
return this.entityFactory; |
| 160 |
} |
| 161 |
|
| 162 |
protected generateId(): string { |
| 163 |
let id: string; |
| 164 |
// eslint-disable-next-line no-loops/no-loops |
| 165 |
do { |
| 166 |
id = uuid(); |
| 167 |
} while (this.entities.has(id)); |
| 168 |
|
| 169 |
return id; |
| 170 |
} |
| 171 |
|
| 172 |
private hasTargetAtPosition(position: PositionInterface): boolean { |
| Error |
Row 173, Column 35: "Array.from() is not supported in IE 9"
compat/compat
|
| 173 |
const targets: Entity[] = Array.from(this.entities.values()).filter((entity) => { |
| 174 |
const component = entity.getComponent(ComponentName.POSITION); |
| 175 |
|
| 176 |
return isPositionComponent(component) ? position === component.getPosition() : false; |
| 177 |
}); |
| 178 |
|
| 179 |
return targets.length === 0; |
| 180 |
} |
| 181 |
} |
| 182 |
|
|
|
|
/libs/games/src/glyphs/character.ts
|
0 problems
|
|
|
/libs/games/src/glyphs/floor.ts
|
0 problems
|
|
|
/libs/games/src/glyphs/glyph.ts
|
0 problems
|
|
|
/libs/games/src/glyphs/index.ts
|
0 problems
|
|
|
/libs/games/src/glyphs/wall.ts
|
0 problems
|
|
|
/libs/games/src/index.ts
|
0 problems
|
|
|
/libs/games/src/maps/enums.ts
|
0 problems
|
|
|
/libs/games/src/maps/generator-cellular.ts
|
0 problems
|
|
|
/libs/games/src/maps/index.ts
|
0 problems
|
|
|
/libs/games/src/maps/interfaces.ts
|
0 problems
|
|
|
/libs/games/src/maps/map.ts
|
0 problems
|
|
|
/libs/games/src/opend6/difficulty.ts
|
0 problems
|
|
|
/libs/games/src/opend6/index.ts
|
0 problems
|
|
|
/libs/games/src/opend6/roll.ts
|
0 problems
|
|
|
/libs/games/src/screens/index.ts
|
0 problems
|
|
|
/libs/games/src/screens/interface.ts
|
0 problems
|
|
|
/libs/games/src/screens/observer.ts
|
0 problems
|
|
|
/libs/games/src/screens/screen.ts
|
0 problems
|
|
|
/libs/games/src/tiles/factory.ts
|
0 problems
|
|
|
/libs/games/src/tiles/floor.ts
|
0 problems
|
|
|
/libs/games/src/tiles/index.ts
|
0 problems
|
|
|
/libs/games/src/tiles/null.ts
|
0 problems
|
|
|
/libs/games/src/tiles/tile.ts
|
0 problems
|
|
|
/libs/games/src/tiles/wall.ts
|
0 problems
|
|
|
/libs/games/tests/colors/color.spec.ts
|
0 problems
|
|
|
/libs/games/tests/colors/hsbToRgb.spec.ts
|
0 problems
|
|
|
/libs/games/tests/colors/random.spec.ts
|
0 problems
|
|
|
/libs/games/tests/colors/rgbToHex.spec.ts
|
0 problems
|
|
|
/libs/games/tests/commands/keys.spec.ts
|
0 problems
|
|
|
/libs/games/tests/commands/move.spec.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 56, Column 51: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { anything, instance, mock, reset, when } from "ts-mockito"; |
| 2 |
|
| 3 |
import { Component } from "@jga/patterns"; |
| 4 |
|
| 5 |
import { |
| 6 |
Actor, |
| 7 |
ComponentName, |
| 8 |
Directions, |
| 9 |
Engine, |
| 10 |
Entity, |
| 11 |
GameMap, |
| 12 |
GlyphInterface, |
| 13 |
MoveCommand, |
| 14 |
PositionInterface, |
| 15 |
TileInterface, |
| 16 |
} from "@jga/games/index"; |
| 17 |
|
| 18 |
describe("Move Command", () => { |
| 19 |
let glyphMock: GlyphInterface; |
| 20 |
let tileMock: TileInterface; |
| 21 |
let gameMapMock: GameMap; |
| 22 |
let engineMock: Engine; |
| 23 |
let playerMock: Actor; |
| 24 |
let componentMock: Component; |
| 25 |
|
| 26 |
const mockGlyph: GlyphInterface = mock<GlyphInterface>(); |
| 27 |
const mockTile: TileInterface = mock<TileInterface>(); |
| 28 |
const mockGameMap: GameMap = mock<GameMap>(); |
| 29 |
const mockEngine: Engine = mock<Engine>(); |
| 30 |
const mockPlayer: Actor = mock<Actor>(); |
| 31 |
const mockComponent: Component = mock<Component>(); |
| 32 |
|
| 33 |
const initialPosition: PositionInterface = { x: 2, y: 2 }; |
| 34 |
|
| 35 |
beforeEach(() => { |
| 36 |
when(mockTile.getGlyph()).thenReturn(glyphMock); |
| 37 |
|
| 38 |
glyphMock = instance(mockGlyph); |
| 39 |
tileMock = instance(mockTile); |
| 40 |
|
| 41 |
when(mockComponent.getPosition()).thenReturn(initialPosition); |
| 42 |
componentMock = instance(mockComponent); |
| 43 |
|
| 44 |
when(mockPlayer.getComponent(ComponentName.POSITION)).thenReturn(componentMock); |
| 45 |
|
| 46 |
playerMock = instance(mockPlayer); |
| 47 |
|
| 48 |
when(mockGameMap.getTile(anything())).thenReturn(tileMock); |
| 49 |
when(mockGameMap.getWidth()).thenReturn(10); |
| 50 |
when(mockGameMap.getHeight()).thenReturn(10); |
| 51 |
|
| 52 |
gameMapMock = instance(mockGameMap); |
| 53 |
|
| 54 |
when(mockEngine.getPlayer()).thenReturn(playerMock); |
| 55 |
when(mockEngine.getMap()).thenReturn(gameMapMock); |
| Error |
Row 56, Column 51: "Map is not supported in IE 9"
compat/compat
|
| 56 |
when(mockEngine.getEntities()).thenReturn(new Map<string, Entity>()); |
| 57 |
when(mockEngine.process(anything())).thenReturn(null); |
| 58 |
|
| 59 |
engineMock = instance(mockEngine); |
| 60 |
|
| 61 |
jest.clearAllMocks(); |
| 62 |
}); |
| 63 |
|
| 64 |
afterEach(() => { |
| 65 |
reset(mockGlyph); |
| 66 |
reset(mockTile); |
| 67 |
reset(mockComponent); |
| 68 |
reset(mockPlayer); |
| 69 |
reset(mockGameMap); |
| 70 |
reset(mockEngine); |
| 71 |
}); |
| 72 |
|
| 73 |
describe("execute", () => { |
| 74 |
it("should return a message", () => { |
| 75 |
const result = new MoveCommand().execute(); |
| 76 |
|
| 77 |
expect(result.message).toContain(`Move =>`); |
| 78 |
}); |
| 79 |
|
| 80 |
it("should return a result", () => { |
| 81 |
const result = new MoveCommand().execute(); |
| 82 |
|
| 83 |
expect(result.result).toBeDefined(); |
| 84 |
}); |
| 85 |
}); |
| 86 |
|
| 87 |
describe("move", () => { |
| 88 |
it("should be able to move `down`", () => { |
| 89 |
const command = new MoveCommand(playerMock, Directions.DOWN, engineMock); |
| 90 |
|
| 91 |
const action = command.execute(); |
| 92 |
|
| 93 |
expect(action.result).toEqual({ x: 2, y: 3 }); |
| 94 |
}); |
| 95 |
|
| 96 |
it("should be able to move `left`", () => { |
| 97 |
const command = new MoveCommand(playerMock, Directions.LEFT, engineMock); |
| 98 |
|
| 99 |
const action = command.execute(); |
| 100 |
|
| 101 |
expect(action.result).toEqual({ x: 1, y: 2 }); |
| 102 |
}); |
| 103 |
|
| 104 |
it("should be able to move `right`", () => { |
| 105 |
const command = new MoveCommand(playerMock, Directions.RIGHT, engineMock); |
| 106 |
|
| 107 |
const action = command.execute(); |
| 108 |
|
| 109 |
expect(action.result).toEqual({ x: 3, y: 2 }); |
| 110 |
}); |
| 111 |
|
| 112 |
it("should be able to move `up`", () => { |
| 113 |
const command = new MoveCommand(playerMock, Directions.UP, engineMock); |
| 114 |
|
| 115 |
const action = command.execute(); |
| 116 |
|
| 117 |
expect(action.result).toEqual({ x: 2, y: 1 }); |
| 118 |
}); |
| 119 |
|
| 120 |
it("should not move if directions is unknown", () => { |
| 121 |
const command = new MoveCommand(playerMock, "nowhere", engineMock); |
| 122 |
|
| 123 |
const action = command.execute(); |
| 124 |
|
| 125 |
expect(action.result).toBeNull(); |
| 126 |
}); |
| 127 |
}); |
| 128 |
|
| 129 |
describe("undo", () => { |
| 130 |
it("should be able to move back `down`", () => { |
| 131 |
const command = new MoveCommand(playerMock, Directions.DOWN, engineMock); |
| 132 |
|
| 133 |
const undo = command.undo(); |
| 134 |
expect(undo.result).toEqual({ x: 2, y: 1 }); |
| 135 |
}); |
| 136 |
|
| 137 |
it("should be able to move back `left`", () => { |
| 138 |
const command = new MoveCommand(playerMock, Directions.LEFT, engineMock); |
| 139 |
|
| 140 |
const undo = command.undo(); |
| 141 |
expect(undo.result).toEqual({ x: 3, y: 2 }); |
| 142 |
}); |
| 143 |
|
| 144 |
it("should be able to move back `right`", () => { |
| 145 |
const command = new MoveCommand(playerMock, Directions.RIGHT, engineMock); |
| 146 |
|
| 147 |
const undo = command.undo(); |
| 148 |
expect(undo.result).toEqual({ x: 1, y: 2 }); |
| 149 |
}); |
| 150 |
|
| 151 |
it("should be able to move back `up`", () => { |
| 152 |
const command = new MoveCommand(playerMock, Directions.UP, engineMock); |
| 153 |
|
| 154 |
const undo = command.undo(); |
| 155 |
expect(undo.result).toEqual({ x: 2, y: 3 }); |
| 156 |
}); |
| 157 |
|
| 158 |
// eslint-disable-next-line sonarjs/no-identical-functions |
| 159 |
it("should not move back if directions is unknown", () => { |
| 160 |
const command = new MoveCommand(playerMock, "nowhere", engineMock); |
| 161 |
|
| 162 |
const undo = command.undo(); |
| 163 |
expect(undo.result).toBeNull(); |
| 164 |
}); |
| 165 |
}); |
| 166 |
}); |
| 167 |
|
|
|
|
/libs/games/tests/commands/roll.spec.ts
|
0 problems
|
|
|
/libs/games/tests/console/console.spec.ts
|
0 problems
|
|
|
/libs/games/tests/console/renderer.spec.ts
|
0 problems
|
|
|
/libs/games/tests/dices/dice.spec.ts
|
0 problems
|
|
|
/libs/games/tests/dices/dice6.spec.ts
|
0 problems
|
|
|
/libs/games/tests/display/display.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/components/appearance.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/components/attack.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/components/damageable.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/components/position.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/components/spread.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/entities/actor.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/entities/entity.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/entities/player.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/loop.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/scheduler.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/systems/damage.spec.ts
|
0 problems
|
|
|
/libs/games/tests/engine/systems/draw.spec.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 17, Column 39: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { |
| 2 |
CharacterGlyph, |
| 3 |
Display, |
| 4 |
AppearanceComponent, |
| 5 |
DrawSystem, |
| 6 |
Entity, |
| 7 |
OffsetInterface, |
| 8 |
PositionComponent, |
| 9 |
} from "@jga/games/index"; |
| 10 |
|
| 11 |
const appearanceComponent = new AppearanceComponent(new CharacterGlyph()); |
| 12 |
const positionComponent = new PositionComponent(); |
| 13 |
|
| 14 |
const entity = new Entity("42"); |
| 15 |
entity.addComponent(appearanceComponent); |
| 16 |
entity.addComponent(positionComponent); |
| Error |
Row 17, Column 39: "Map is not supported in IE 9"
compat/compat
|
| 17 |
const entities: Map<string, Entity> = new Map<string, Entity>(); |
| 18 |
entities.set("42", entity); |
| 19 |
|
| 20 |
const display: Display = new Display(80, 60); |
| 21 |
|
| 22 |
const offset: OffsetInterface = { x: 0, y: 0 }; |
| 23 |
|
| 24 |
describe("Draw System", (): void => { |
| 25 |
it("should be instantiable", (): void => { |
| 26 |
const system = new DrawSystem(entities, display, offset); |
| 27 |
|
| 28 |
expect(system).not.toBeNull(); |
| 29 |
}); |
| 30 |
|
| 31 |
describe("constructor", (): void => { |
| 32 |
it("should init offset", (): void => { |
| 33 |
const system = new DrawSystem(entities, display, offset); |
| 34 |
|
| 35 |
expect(system.getOffset()).toBe(offset); |
| 36 |
}); |
| 37 |
|
| 38 |
it("should set default offset", (): void => { |
| 39 |
const expected = { x: 0, y: 0 }; |
| 40 |
const system = new DrawSystem(entities, display); |
| 41 |
|
| 42 |
expect(system.getOffset()).toStrictEqual(expected); |
| 43 |
}); |
| 44 |
}); |
| 45 |
|
| 46 |
describe("run", (): void => { |
| 47 |
it("should draw entity", (): void => { |
| 48 |
const drawSpy = jest.spyOn(Display.prototype, "draw"); |
| 49 |
|
| 50 |
const system = new DrawSystem(entities, display, offset); |
| 51 |
|
| 52 |
system.run(); |
| 53 |
|
| 54 |
const expectedPosition = { x: 0, y: 0 }; |
| 55 |
const expectedGlyph = appearanceComponent.getGlyph(); |
| 56 |
|
| 57 |
expect(drawSpy).toHaveBeenCalledTimes(1); |
| 58 |
expect(drawSpy).toHaveBeenCalledWith(expectedPosition, expectedGlyph); |
| 59 |
|
| 60 |
drawSpy.mockRestore(); |
| 61 |
}); |
| 62 |
}); |
| 63 |
}); |
| 64 |
|
|
|
|
/libs/games/tests/engine/systems/movement.spec.ts
|
8 problems (8 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 34, Column 39: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 40, Column 21: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 67, Column 55: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 98, Column 55: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 282, Column 37: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 323, Column 37: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 364, Column 37: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 370, Column 31: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { CommandManager } from "@jga/patterns/index"; |
| 2 |
import { |
| 3 |
CellularMapGenerator, |
| 4 |
GameMap, |
| 5 |
PositionInterface, |
| 6 |
FloorTile, |
| 7 |
NullTile, |
| 8 |
TileFactory, |
| 9 |
WallTile, |
| 10 |
Actor, |
| 11 |
AttackComponent, |
| 12 |
ComponentName, |
| 13 |
DamageableComponent, |
| 14 |
DamageSystem, |
| 15 |
Entity, |
| 16 |
MoveableComponent, |
| 17 |
MoveInterface, |
| 18 |
MovementSystem, |
| 19 |
PositionComponent, |
| 20 |
Scheduler, |
| 21 |
World, |
| 22 |
} from "@jga/games/index"; |
| 23 |
|
| 24 |
const position: PositionInterface = { x: 0, y: 1 }; |
| 25 |
const tileFactory: TileFactory = new TileFactory(); |
| 26 |
const generator: CellularMapGenerator = new CellularMapGenerator(10, 10, tileFactory); |
| 27 |
const map: GameMap = new GameMap({ |
| 28 |
generator, |
| 29 |
height: 10, |
| 30 |
width: 10, |
| 31 |
tileFactory, |
| 32 |
}); |
| 33 |
const entity = new Entity("42"); |
| Error |
Row 34, Column 39: "Map is not supported in IE 9"
compat/compat
|
| 34 |
const entities: Map<string, Entity> = new Map<string, Entity>(); |
| 35 |
entities.set("42", entity); |
| 36 |
|
| 37 |
const mapEntity = new Entity("42"); |
| 38 |
mapEntity.addComponent(new PositionComponent({ x: 0, y: 1 })); |
| 39 |
mapEntity.addComponent(new DamageableComponent()); |
| Error |
Row 40, Column 21: "Map is not supported in IE 9"
compat/compat
|
| 40 |
const mapEntities = new Map<string, Entity>(); |
| 41 |
mapEntities.set(mapEntity.getId(), mapEntity); |
| 42 |
|
| 43 |
const world = new World(new Scheduler(), map, new CommandManager()); |
| 44 |
|
| 45 |
describe("Movement System", (): void => { |
| 46 |
beforeEach(() => jest.clearAllMocks()); |
| 47 |
|
| 48 |
it("should be instantiable", (): void => { |
| 49 |
const system = new MovementSystem(entities, position, mapEntities); |
| 50 |
|
| 51 |
expect(system).not.toBeNull(); |
| 52 |
}); |
| 53 |
|
| 54 |
describe("constructor", (): void => { |
| 55 |
it("should init position", (): void => { |
| 56 |
const system = new MovementSystem(entities, position, mapEntities); |
| 57 |
|
| 58 |
expect(system.getPosition()).toBe(position); |
| 59 |
}); |
| 60 |
}); |
| 61 |
|
| 62 |
describe("run", (): void => { |
| 63 |
it("should do nothing if can move return false", (): void => { |
| 64 |
const mockEntity = new Entity("42"); |
| 65 |
mockEntity.addComponent(new MoveableComponent()); |
| 66 |
mockEntity.addComponent(new PositionComponent()); |
| Error |
Row 67, Column 55: "Map is not supported in IE 9"
compat/compat
|
| 67 |
const mockEntities: Map<string, Entity> = new Map<string, Entity>(); |
| 68 |
mockEntities.set("42", mockEntity); |
| 69 |
|
| 70 |
const system = new MovementSystem(mockEntities, position, mapEntities); |
| 71 |
|
| 72 |
const expectedPosition = system.getEntities().get("42").getComponent(ComponentName.POSITION).getPosition(); |
| 73 |
|
| 74 |
const mockMove: MoveInterface = { |
| 75 |
canMove: false, |
| 76 |
newPosition: expectedPosition, |
| 77 |
}; |
| 78 |
|
| 79 |
const originalImpl = MovementSystem.prototype.canMove; |
| 80 |
|
| 81 |
MovementSystem.prototype.canMove = jest.fn().mockImplementation(() => { |
| 82 |
return mockMove; |
| 83 |
}); |
| 84 |
|
| 85 |
system.run(world); |
| 86 |
|
| 87 |
expect(system.getEntities().get("42").getComponent(ComponentName.POSITION).getPosition()).toBe( |
| 88 |
expectedPosition, |
| 89 |
); |
| 90 |
|
| 91 |
MovementSystem.prototype.canMove = originalImpl; |
| 92 |
}); |
| 93 |
|
| 94 |
it("should set position if can move return true", (): void => { |
| 95 |
const mockEntity = new Entity("42"); |
| 96 |
mockEntity.addComponent(new MoveableComponent()); |
| 97 |
mockEntity.addComponent(new PositionComponent()); |
| Error |
Row 98, Column 55: "Map is not supported in IE 9"
compat/compat
|
| 98 |
const mockEntities: Map<string, Entity> = new Map<string, Entity>(); |
| 99 |
mockEntities.set("42", mockEntity); |
| 100 |
|
| 101 |
const mockMove: MoveInterface = { |
| 102 |
canMove: true, |
| 103 |
newPosition: position, |
| 104 |
}; |
| 105 |
|
| 106 |
const originalImpl = MovementSystem.prototype.canMove; |
| 107 |
|
| 108 |
MovementSystem.prototype.canMove = jest.fn().mockImplementation(() => { |
| 109 |
return mockMove; |
| 110 |
}); |
| 111 |
|
| 112 |
const system = new MovementSystem(mockEntities, position, mapEntities); |
| 113 |
|
| 114 |
system.run(world); |
| 115 |
|
| 116 |
expect(system.getEntities().get("42").getComponent(ComponentName.POSITION).getPosition()).toBe(position); |
| 117 |
|
| 118 |
MovementSystem.prototype.canMove = originalImpl; |
| 119 |
}); |
| 120 |
}); |
| 121 |
|
| 122 |
describe("can move", (): void => { |
| 123 |
it("should return false if position is not set", (): void => { |
| 124 |
const system = new MovementSystem(entities, null, mapEntities); |
| 125 |
|
| 126 |
const expected: MoveInterface = { |
| 127 |
canMove: false, |
| 128 |
newPosition: null, |
| 129 |
}; |
| 130 |
|
| 131 |
expect(system.canMove(world)).toStrictEqual(expected); |
| 132 |
}); |
| 133 |
|
| 134 |
it("should return false if map is not set", () => { |
| 135 |
const system = new MovementSystem(entities, position, mapEntities); |
| 136 |
|
| 137 |
const expected: MoveInterface = { |
| 138 |
canMove: false, |
| 139 |
newPosition: position, |
| 140 |
}; |
| 141 |
|
| 142 |
expect(system.canMove(null)).toStrictEqual(expected); |
| 143 |
}); |
| 144 |
|
| 145 |
it("should return false if tile is not set", () => { |
| 146 |
const mockTile = null; |
| 147 |
const mockMap = new GameMap({ |
| 148 |
generator, |
| 149 |
height: 1, |
| 150 |
width: 1, |
| 151 |
tileFactory, |
| 152 |
}); |
| 153 |
|
| 154 |
const mockWorld = new World(new Scheduler(), mockMap, new CommandManager()); |
| 155 |
|
| 156 |
const originalImpl = GameMap.prototype.getTile; |
| 157 |
|
| 158 |
GameMap.prototype.getTile = jest.fn().mockImplementation(() => { |
| 159 |
return mockTile; |
| 160 |
}); |
| 161 |
|
| 162 |
const system = new MovementSystem(entities, position, mapEntities); |
| 163 |
|
| 164 |
const expected: MoveInterface = { |
| 165 |
canMove: false, |
| 166 |
newPosition: position, |
| 167 |
}; |
| 168 |
|
| 169 |
expect(system.canMove(mockWorld)).toStrictEqual(expected); |
| 170 |
|
| 171 |
GameMap.prototype.getTile = originalImpl; |
| 172 |
}); |
| 173 |
|
| 174 |
it("should return true if tile is walkable", () => { |
| 175 |
const mockTile = new FloorTile(); |
| 176 |
const mockMap = new GameMap({ |
| 177 |
generator, |
| 178 |
height: 1, |
| 179 |
width: 1, |
| 180 |
tileFactory, |
| 181 |
}); |
| 182 |
const mockWorld = new World(new Scheduler(), mockMap, new CommandManager()); |
| 183 |
const mapPosition = { x: 0, y: 0 }; |
| 184 |
|
| 185 |
const originalImpl = GameMap.prototype.getTile; |
| 186 |
|
| 187 |
GameMap.prototype.getTile = jest.fn().mockImplementation(() => { |
| 188 |
return mockTile; |
| 189 |
}); |
| 190 |
|
| 191 |
const system = new MovementSystem(entities, mapPosition, mapEntities); |
| 192 |
|
| 193 |
const expected: MoveInterface = { |
| 194 |
canMove: true, |
| 195 |
newPosition: mapPosition, |
| 196 |
}; |
| 197 |
|
| 198 |
expect(system.canMove(mockWorld)).toStrictEqual(expected); |
| 199 |
|
| 200 |
GameMap.prototype.getTile = originalImpl; |
| 201 |
}); |
| 202 |
|
| 203 |
it("should return false if tile is diggable", () => { |
| 204 |
const mockTile = new WallTile(); |
| 205 |
const mockMap = new GameMap({ |
| 206 |
generator, |
| 207 |
height: 2, |
| 208 |
width: 2, |
| 209 |
tileFactory, |
| 210 |
}); |
| 211 |
const mockWorld = new World(new Scheduler(), mockMap, new CommandManager()); |
| 212 |
const mapPosition = { x: 0, y: 0 }; |
| 213 |
|
| 214 |
const originalImpl = GameMap.prototype.getTile; |
| 215 |
|
| 216 |
GameMap.prototype.getTile = jest.fn().mockImplementation(() => { |
| 217 |
return mockTile; |
| 218 |
}); |
| 219 |
|
| 220 |
const system = new MovementSystem(entities, mapPosition, mapEntities); |
| 221 |
|
| 222 |
const expected: MoveInterface = { |
| 223 |
canMove: false, |
| 224 |
newPosition: mapPosition, |
| 225 |
}; |
| 226 |
|
| 227 |
expect(system.canMove(mockWorld)).toStrictEqual(expected); |
| 228 |
|
| 229 |
GameMap.prototype.getTile = originalImpl; |
| 230 |
}); |
| 231 |
|
| 232 |
it("should return false if tile is not walkable and not diggable", () => { |
| 233 |
const mockTile = new NullTile(); |
| 234 |
const mockMap = new GameMap({ |
| 235 |
generator, |
| 236 |
height: 1, |
| 237 |
width: 1, |
| 238 |
tileFactory, |
| 239 |
}); |
| 240 |
const mockWorld = new World(new Scheduler(), mockMap, new CommandManager()); |
| 241 |
const mapPosition = { x: 0, y: 0 }; |
| 242 |
|
| 243 |
const originalImpl = GameMap.prototype.getTile; |
| 244 |
|
| 245 |
GameMap.prototype.getTile = jest.fn().mockImplementation(() => { |
| 246 |
return mockTile; |
| 247 |
}); |
| 248 |
|
| 249 |
const system = new MovementSystem(entities, mapPosition, mapEntities); |
| 250 |
|
| 251 |
const expected: MoveInterface = { |
| 252 |
canMove: false, |
| 253 |
newPosition: mapPosition, |
| 254 |
}; |
| 255 |
|
| 256 |
expect(system.canMove(mockWorld)).toStrictEqual(expected); |
| 257 |
|
| 258 |
GameMap.prototype.getTile = originalImpl; |
| 259 |
}); |
| 260 |
|
| 261 |
it("should attack if there is a target on selected position", () => { |
| 262 |
const damageSystemSpy = jest.spyOn(DamageSystem.prototype, "run"); |
| 263 |
|
| 264 |
const mockTile = new FloorTile(); |
| 265 |
const mockMap = new GameMap({ |
| 266 |
generator, |
| 267 |
height: 2, |
| 268 |
width: 2, |
| 269 |
tileFactory, |
| 270 |
}); |
| 271 |
const mockWorld = new World(new Scheduler(), mockMap, new CommandManager()); |
| 272 |
const mapPosition = { x: 0, y: 1 }; |
| 273 |
const actor = new Actor(); |
| 274 |
actor.addComponent(new PositionComponent({ x: 0, y: 0 })); |
| 275 |
actor.addComponent(new MoveableComponent()); |
| 276 |
actor.addComponent(new AttackComponent(10)); |
| 277 |
const targetEntity = new Entity("42"); |
| 278 |
targetEntity.addComponent(new PositionComponent({ x: 0, y: 0 })); |
| 279 |
targetEntity.addComponent(new MoveableComponent()); |
| 280 |
targetEntity.addComponent(new AttackComponent(10)); |
| 281 |
targetEntity.addComponent(new DamageableComponent()); |
| Error |
Row 282, Column 37: "Map is not supported in IE 9"
compat/compat
|
| 282 |
const targetEntitites = new Map<string, Entity>(); |
| 283 |
targetEntitites.set("1", actor); |
| 284 |
targetEntitites.set(targetEntity.getId(), targetEntity); |
| 285 |
|
| 286 |
const originalImpl = GameMap.prototype.getTile; |
| 287 |
|
| 288 |
GameMap.prototype.getTile = jest.fn().mockImplementation(() => { |
| 289 |
return mockTile; |
| 290 |
}); |
| 291 |
|
| 292 |
const system = new MovementSystem(targetEntitites, mapPosition, mapEntities); |
| 293 |
|
| 294 |
const expected: MoveInterface = { |
| 295 |
canMove: false, |
| 296 |
newPosition: mapPosition, |
| 297 |
}; |
| 298 |
|
| 299 |
expect(system.canMove(mockWorld)).toStrictEqual(expected); |
| 300 |
expect(damageSystemSpy).toHaveBeenCalledWith(mockWorld); |
| 301 |
|
| 302 |
GameMap.prototype.getTile = originalImpl; |
| 303 |
|
| 304 |
damageSystemSpy.mockRestore(); |
| 305 |
}); |
| 306 |
|
| 307 |
it("should do nothing if actor has no attack component", () => { |
| 308 |
const damageSystemSpy = jest.spyOn(DamageSystem.prototype, "run"); |
| 309 |
|
| 310 |
const mockTile = new FloorTile(); |
| 311 |
const mockMap = new GameMap({ |
| 312 |
generator, |
| 313 |
height: 2, |
| 314 |
width: 2, |
| 315 |
tileFactory, |
| 316 |
}); |
| 317 |
const mockWorld = new World(new Scheduler(), mockMap, new CommandManager()); |
| 318 |
const mapPosition = { x: 0, y: 1 }; |
| 319 |
const targetEntity = new Entity("42"); |
| 320 |
targetEntity.addComponent(new PositionComponent({ x: 0, y: 0 })); |
| 321 |
targetEntity.addComponent(new MoveableComponent()); |
| 322 |
|
| Error |
Row 323, Column 37: "Map is not supported in IE 9"
compat/compat
|
| 323 |
const targetEntitites = new Map<string, Entity>(); |
| 324 |
targetEntitites.set(targetEntity.getId(), targetEntity); |
| 325 |
|
| 326 |
const originalImpl = GameMap.prototype.getTile; |
| 327 |
|
| 328 |
GameMap.prototype.getTile = jest.fn().mockImplementation(() => { |
| 329 |
return mockTile; |
| 330 |
}); |
| 331 |
|
| 332 |
const system = new MovementSystem(targetEntitites, mapPosition, mapEntities); |
| 333 |
|
| 334 |
const expected: MoveInterface = { |
| 335 |
canMove: false, |
| 336 |
newPosition: mapPosition, |
| 337 |
}; |
| 338 |
|
| 339 |
expect(system.canMove(mockWorld)).toStrictEqual(expected); |
| 340 |
expect(damageSystemSpy).not.toHaveBeenCalled(); |
| 341 |
|
| 342 |
GameMap.prototype.getTile = originalImpl; |
| 343 |
|
| 344 |
damageSystemSpy.mockRestore(); |
| 345 |
}); |
| 346 |
|
| 347 |
it("should do nothing if target has no damageable component", () => { |
| 348 |
const damageSystemSpy = jest.spyOn(DamageSystem.prototype, "run"); |
| 349 |
|
| 350 |
const mockTile = new FloorTile(); |
| 351 |
const mockMap = new GameMap({ |
| 352 |
generator, |
| 353 |
height: 2, |
| 354 |
width: 2, |
| 355 |
tileFactory, |
| 356 |
}); |
| 357 |
const mockWorld = new World(new Scheduler(), mockMap, new CommandManager()); |
| 358 |
const mapPosition = { x: 0, y: 1 }; |
| 359 |
const targetEntity = new Entity("42"); |
| 360 |
targetEntity.addComponent(new PositionComponent({ x: 0, y: 0 })); |
| 361 |
targetEntity.addComponent(new MoveableComponent()); |
| 362 |
targetEntity.addComponent(new AttackComponent(10)); |
| 363 |
|
| Error |
Row 364, Column 37: "Map is not supported in IE 9"
compat/compat
|
| 364 |
const targetEntitites = new Map<string, Entity>(); |
| 365 |
targetEntitites.set(targetEntity.getId(), targetEntity); |
| 366 |
|
| 367 |
const target = new Entity("42"); |
| 368 |
target.addComponent(new PositionComponent({ x: 0, y: 1 })); |
| 369 |
|
| Error |
Row 370, Column 31: "Map is not supported in IE 9"
compat/compat
|
| 370 |
const mapTarget = new Map<string, Entity>(); |
| 371 |
mapTarget.set(target.getId(), target); |
| 372 |
|
| 373 |
const originalImpl = GameMap.prototype.getTile; |
| 374 |
|
| 375 |
GameMap.prototype.getTile = jest.fn().mockImplementation(() => { |
| 376 |
return mockTile; |
| 377 |
}); |
| 378 |
|
| 379 |
const system = new MovementSystem(targetEntitites, mapPosition, mapTarget); |
| 380 |
|
| 381 |
const expected: MoveInterface = { |
| 382 |
canMove: false, |
| 383 |
newPosition: mapPosition, |
| 384 |
}; |
| 385 |
|
| 386 |
expect(system.canMove(mockWorld)).toStrictEqual(expected); |
| 387 |
expect(damageSystemSpy).not.toHaveBeenCalled(); |
| 388 |
|
| 389 |
GameMap.prototype.getTile = originalImpl; |
| 390 |
|
| 391 |
damageSystemSpy.mockRestore(); |
| 392 |
}); |
| 393 |
}); |
| 394 |
}); |
| 395 |
|
|
|
|
/libs/games/tests/engine/systems/position.spec.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 6, Column 39: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { ComponentName, Entity, PositionComponent, PositionInterface, PositionSystem } from "@jga/games/index"; |
| 2 |
|
| 3 |
const position: PositionInterface = { x: 0, y: 0 }; |
| 4 |
const entity = new Entity("42"); |
| 5 |
entity.addComponent(new PositionComponent()); |
| Error |
Row 6, Column 39: "Map is not supported in IE 9"
compat/compat
|
| 6 |
const entities: Map<string, Entity> = new Map<string, Entity>(); |
| 7 |
entities.set("42", entity); |
| 8 |
|
| 9 |
describe("Position System", (): void => { |
| 10 |
it("should be instantiable", (): void => { |
| 11 |
const system = new PositionSystem(entities, position); |
| 12 |
|
| 13 |
expect(system).not.toBeNull(); |
| 14 |
}); |
| 15 |
|
| 16 |
describe("constructor", (): void => { |
| 17 |
it("should set position", (): void => { |
| 18 |
const system = new PositionSystem(entities, position); |
| 19 |
|
| 20 |
expect(system.getPosition()).toBe(position); |
| 21 |
}); |
| 22 |
}); |
| 23 |
|
| 24 |
describe("run", (): void => { |
| 25 |
it("should set position for each entity", (): void => { |
| 26 |
const system = new PositionSystem(entities, position); |
| 27 |
|
| 28 |
system.run(); |
| 29 |
|
| 30 |
const entity1 = system.getEntities().get("42"); |
| 31 |
|
| 32 |
expect(entity1.getComponent(ComponentName.POSITION).getPosition()).toBe(position); |
| 33 |
}); |
| 34 |
}); |
| 35 |
}); |
| 36 |
|
|
|
|
/libs/games/tests/engine/systems/spread.spec.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 61, Column 51: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { anything, instance, mock, when } from "ts-mockito"; |
| 2 |
|
| 3 |
import { random } from "@jga/algorithms"; |
| 4 |
|
| 5 |
import { |
| 6 |
ComponentName, |
| 7 |
Entity, |
| 8 |
EntityFactory, |
| 9 |
PositionComponent, |
| 10 |
SpreadComponent, |
| 11 |
SpreadSystem, |
| 12 |
World, |
| 13 |
} from "@jga/games/index"; |
| 14 |
|
| 15 |
jest.mock("@jga/algorithms/random"); |
| 16 |
|
| 17 |
describe("Spread System", () => { |
| 18 |
beforeEach(() => { |
| 19 |
random.prototype = jest.fn().mockReturnValue(20); |
| 20 |
}); |
| 21 |
|
| 22 |
afterAll(() => { |
| 23 |
jest.fn().mockClear(); |
| 24 |
}); |
| 25 |
|
| 26 |
it("should be instantiable", (): void => { |
| 27 |
const system = new SpreadSystem([]); |
| 28 |
|
| 29 |
expect(system).not.toBeNull(); |
| 30 |
}); |
| 31 |
|
| 32 |
describe("run", (): void => { |
| 33 |
// eslint-disable-next-line jest/expect-expect |
| 34 |
it("should spread entity", (): void => { |
| 35 |
const mockPositionComponent: PositionComponent = mock(PositionComponent); |
| 36 |
when(mockPositionComponent.setPosition(anything())).thenReturn(null); |
| 37 |
const positionComponentMock: PositionComponent = instance(mockPositionComponent); |
| 38 |
|
| 39 |
const mockSpreadComponent: SpreadComponent = mock(SpreadComponent); |
| 40 |
when(mockSpreadComponent.getName()).thenReturn("Spread"); |
| 41 |
when(mockSpreadComponent.getRemainingGrowth()).thenReturn(5); |
| 42 |
when(mockSpreadComponent.spread()).thenReturn(null); |
| 43 |
const spreadComponentMock: SpreadComponent = instance(mockSpreadComponent); |
| 44 |
|
| 45 |
const mockEntity: Entity = mock(Entity); |
| 46 |
when(mockEntity.getComponent(ComponentName.POSITION)).thenReturn(positionComponentMock); |
| 47 |
when(mockEntity.getComponent(ComponentName.SPREAD)).thenReturn(spreadComponentMock); |
| 48 |
const entityMock: Entity = instance(mockEntity); |
| 49 |
|
| 50 |
const mockFactory: EntityFactory = mock(EntityFactory); |
| 51 |
when(mockFactory.create(anything())).thenReturn(entityMock); |
| 52 |
const factoryMock: EntityFactory = instance(mockFactory); |
| 53 |
|
| 54 |
const mockWord: World = mock(World); |
| 55 |
when(mockWord.isEmptyFloor(anything())).thenReturn(true); |
| 56 |
when(mockWord.getEntityFactory()).thenReturn(factoryMock); |
| 57 |
const worldMock: World = instance(mockWord); |
| 58 |
|
| 59 |
const entity = new Entity("42"); |
| 60 |
entity.addComponent(spreadComponentMock); |
| Error |
Row 61, Column 51: "Map is not supported in IE 9"
compat/compat
|
| 61 |
const entities: Map<string, Entity> = new Map<string, Entity>(); |
| 62 |
entities.set("42", entity); |
| 63 |
|
| 64 |
const system = new SpreadSystem(entities); |
| 65 |
|
| 66 |
system.run(worldMock); |
| 67 |
}); |
| 68 |
}); |
| 69 |
}); |
| 70 |
|
|
|
|
/libs/games/tests/engine/world.spec.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 394, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { anything, anyNumber, instance, mock, reset, spy, verify, when } from "ts-mockito"; |
| 2 |
|
| 3 |
import { Command, CommandManager } from "@jga/patterns"; |
| 4 |
|
| 5 |
import { |
| 6 |
Entity, |
| 7 |
EntityFactory, |
| 8 |
FloorTile, |
| 9 |
GameMap, |
| 10 |
Loop, |
| 11 |
Player, |
| 12 |
PositionComponent, |
| 13 |
Scheduler, |
| 14 |
System, |
| 15 |
Tile, |
| 16 |
TileFactory, |
| 17 |
WallTile, |
| 18 |
World, |
| 19 |
} from "@jga/games/index"; |
| 20 |
|
| 21 |
class ConcreteSystem extends System { |
| 22 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars,class-methods-use-this |
| 23 |
public run(map?: GameMap): void { |
| 24 |
// eslint-disable-next-line no-console |
| 25 |
console.log(`run ConcreteSystem`); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
describe("World", () => { |
| 30 |
const mockMap: GameMap = mock(GameMap); |
| 31 |
const mockTileFactory: TileFactory = mock<TileFactory>(); |
| 32 |
const mockTile: Tile = mock(Tile); |
| 33 |
const mockCommandManager: CommandManager = mock<CommandManager>(); |
| 34 |
const mockEntityFactory: EntityFactory = mock(EntityFactory); |
| 35 |
|
| 36 |
let gameMapMock: GameMap; |
| 37 |
let tileFactoryMock: TileFactory; |
| 38 |
let tileMock: Tile; |
| 39 |
let commandManagerMock: CommandManager; |
| 40 |
let entityFactoryMock: EntityFactory; |
| 41 |
|
| 42 |
beforeEach(() => { |
| 43 |
tileMock = instance(mockTile); |
| 44 |
tileMock.isWalkable = true; |
| 45 |
|
| 46 |
when(mockMap.getTile({ x: anyNumber(), y: anyNumber() })).thenReturn(tileMock); |
| 47 |
when(mockMap.getHeight()).thenReturn(1); |
| 48 |
when(mockMap.getWidth()).thenReturn(1); |
| 49 |
|
| 50 |
gameMapMock = instance(mockMap); |
| 51 |
tileFactoryMock = instance(mockTileFactory); |
| 52 |
commandManagerMock = instance(mockCommandManager); |
| 53 |
entityFactoryMock = instance(mockEntityFactory); |
| 54 |
}); |
| 55 |
|
| 56 |
afterAll(() => { |
| 57 |
reset(mockMap); |
| 58 |
reset(mockTileFactory); |
| 59 |
reset(mockTile); |
| 60 |
reset(mockCommandManager); |
| 61 |
reset(mockEntityFactory); |
| 62 |
}); |
| 63 |
|
| 64 |
it("should be instantiable", () => { |
| 65 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 66 |
expect(engine).not.toBeNull(); |
| 67 |
}); |
| 68 |
|
| 69 |
describe("constructor", () => { |
| 70 |
it("should init entity factory", () => { |
| 71 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 72 |
|
| 73 |
expect(engine.getEntityFactory()).toBe(entityFactoryMock); |
| 74 |
}); |
| 75 |
}); |
| 76 |
|
| 77 |
it("should be able to retrieve map", () => { |
| 78 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 79 |
expect(engine.getMap()).toBe(gameMapMock); |
| 80 |
}); |
| 81 |
|
| 82 |
it("can create and retrieve player", () => { |
| 83 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 84 |
|
| 85 |
const spiedEngine = spy(engine); |
| 86 |
when(spiedEngine.getRandomFloorPosition()).thenReturn({ x: 0, y: 0 }); |
| 87 |
|
| 88 |
engine.createPlayer(); |
| 89 |
const player = engine.getPlayer(); |
| 90 |
|
| 91 |
expect(player).toBeInstanceOf(Player); |
| 92 |
}); |
| 93 |
|
| 94 |
it("add an entity when creating a player", () => { |
| 95 |
const floorTile = new FloorTile(); |
| 96 |
const wallTile = new WallTile(); |
| 97 |
|
| 98 |
const map = new GameMap({ |
| 99 |
height: 1, |
| 100 |
tileFactory: tileFactoryMock, |
| 101 |
tiles: [[floorTile], [wallTile]], |
| 102 |
width: 2, |
| 103 |
}); |
| 104 |
|
| 105 |
const engine = new World(new Scheduler(), map, commandManagerMock, entityFactoryMock); |
| 106 |
const spiedEngine = spy(engine); |
| 107 |
when(spiedEngine.getRandomFloorPosition()).thenReturn({ x: 0, y: 0 }); |
| 108 |
|
| 109 |
expect(engine.getEntities().size).toBe(0); |
| 110 |
|
| 111 |
engine.createPlayer(); |
| 112 |
|
| 113 |
expect(engine.getEntities().size).toBe(1); |
| 114 |
}); |
| 115 |
|
| 116 |
it("should be able to add and remove an entity", () => { |
| 117 |
const floorTile = new FloorTile(); |
| 118 |
const wallTile = new WallTile(); |
| 119 |
|
| 120 |
const map = new GameMap({ |
| 121 |
height: 1, |
| 122 |
tileFactory: tileFactoryMock, |
| 123 |
tiles: [[floorTile], [wallTile]], |
| 124 |
width: 2, |
| 125 |
}); |
| 126 |
|
| 127 |
const engine = new World(new Scheduler(), map, commandManagerMock, entityFactoryMock); |
| 128 |
|
| 129 |
expect(engine.getEntities().size).toBe(0); |
| 130 |
|
| 131 |
const entity = new Entity("42"); |
| 132 |
|
| 133 |
engine.addEntity(entity); |
| 134 |
|
| 135 |
expect(engine.getEntities().size).toBe(1); |
| 136 |
|
| 137 |
engine.removeEntity(entity); |
| 138 |
|
| 139 |
expect(engine.getEntities().size).toBe(0); |
| 140 |
}); |
| 141 |
|
| 142 |
it("should be able to create an entity", () => { |
| 143 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 144 |
|
| 145 |
expect(engine.getEntities().size).toBe(0); |
| 146 |
|
| 147 |
const result = engine.createEntity(); |
| 148 |
|
| 149 |
expect(result).toBeInstanceOf(Entity); |
| 150 |
expect(engine.getEntities().size).toBe(1); |
| 151 |
}); |
| 152 |
|
| 153 |
it("add entity to scheduler on `addEntity` call", () => { |
| 154 |
const floorTile = new FloorTile(); |
| 155 |
const wallTile = new WallTile(); |
| 156 |
|
| 157 |
const map = new GameMap({ |
| 158 |
height: 1, |
| 159 |
tileFactory: tileFactoryMock, |
| 160 |
tiles: [[floorTile], [wallTile]], |
| 161 |
width: 2, |
| 162 |
}); |
| 163 |
|
| 164 |
const engine = new World(new Scheduler(), map, commandManagerMock, entityFactoryMock); |
| 165 |
const schedulerSpy = jest.spyOn(Scheduler.prototype, "add"); |
| 166 |
const entity = new Entity("42"); |
| 167 |
|
| 168 |
engine.addEntity(entity); |
| 169 |
|
| 170 |
expect(schedulerSpy).toHaveBeenCalledTimes(1); |
| 171 |
}); |
| 172 |
|
| 173 |
describe("lock", () => { |
| 174 |
it("should call `Loop.lock`", () => { |
| 175 |
const loopLockSpy = jest.spyOn(Loop.prototype, "lock"); |
| 176 |
|
| 177 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 178 |
|
| 179 |
engine.lock(); |
| 180 |
|
| 181 |
expect(loopLockSpy).toHaveBeenCalled(); |
| 182 |
loopLockSpy.mockRestore(); |
| 183 |
}); |
| 184 |
}); |
| 185 |
|
| 186 |
describe("unlock", () => { |
| 187 |
it("should call `Loop.unlock`", () => { |
| 188 |
const loopLockSpy = jest.spyOn(Loop.prototype, "unlock"); |
| 189 |
|
| 190 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 191 |
|
| 192 |
engine.unlock(); |
| 193 |
|
| 194 |
expect(loopLockSpy).toHaveBeenCalled(); |
| 195 |
loopLockSpy.mockRestore(); |
| 196 |
}); |
| 197 |
}); |
| 198 |
|
| 199 |
describe("mainLoop", () => { |
| 200 |
it("should call `act` for each actor", () => { |
| 201 |
const entity = new Entity("42"); |
| 202 |
const entity1 = new Entity("43"); |
| 203 |
const entity2 = new Entity("44"); |
| 204 |
const entitySpy = jest.spyOn(Entity.prototype, "act"); |
| 205 |
const schedulerSpy = jest.spyOn(Scheduler.prototype, "next"); |
| 206 |
|
| 207 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 208 |
|
| 209 |
engine.addEntity(entity); |
| 210 |
engine.addEntity(entity1); |
| 211 |
engine.addEntity(entity2); |
| 212 |
|
| 213 |
engine.mainLoop(); |
| 214 |
|
| 215 |
expect(entitySpy).toHaveBeenCalledTimes(3); |
| 216 |
expect(schedulerSpy).toHaveBeenCalledTimes(4); |
| 217 |
|
| 218 |
entitySpy.mockRestore(); |
| 219 |
schedulerSpy.mockRestore(); |
| 220 |
}); |
| 221 |
}); |
| 222 |
|
| 223 |
describe("process", () => { |
| 224 |
// eslint-disable-next-line jest/expect-expect |
| 225 |
it("should run systems", () => { |
| 226 |
const mockSystem: ConcreteSystem = mock(ConcreteSystem); |
| 227 |
|
| 228 |
when(mockSystem.run(anything())).thenReturn(null); |
| 229 |
|
| 230 |
const systemMock = instance(mockSystem); |
| 231 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 232 |
|
| 233 |
engine.registerSystems([systemMock]); |
| 234 |
|
| 235 |
engine.process(); |
| 236 |
|
| 237 |
verify(mockSystem.run(anything())).once(); |
| 238 |
}); |
| 239 |
}); |
| 240 |
|
| 241 |
describe("run", () => { |
| 242 |
// eslint-disable-next-line jest/expect-expect |
| 243 |
it("should run a system", () => { |
| 244 |
const mockSystem: ConcreteSystem = mock(ConcreteSystem); |
| 245 |
|
| 246 |
when(mockSystem.run(anything())).thenReturn(null); |
| 247 |
|
| 248 |
const systemMock = instance(mockSystem); |
| 249 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 250 |
|
| 251 |
engine.run(systemMock); |
| 252 |
|
| 253 |
verify(mockSystem.run(anything())).once(); |
| 254 |
}); |
| 255 |
}); |
| 256 |
|
| 257 |
describe("execute", () => { |
| 258 |
// eslint-disable-next-line jest/expect-expect |
| 259 |
it("should call command manager execute", () => { |
| 260 |
const mockCommand: Command = mock(Command); |
| 261 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 262 |
|
| 263 |
const commandMock = instance(mockCommand); |
| 264 |
|
| 265 |
engine.execute(commandMock); |
| 266 |
|
| 267 |
verify(mockCommandManager.execute(commandMock)).once(); |
| 268 |
}); |
| 269 |
}); |
| 270 |
|
| 271 |
describe("addEntityAtRandomPosition", () => { |
| 272 |
it("should add a new entity if it has `PositionComponent`", () => { |
| 273 |
const floorTile = new FloorTile(); |
| 274 |
const wallTile = new WallTile(); |
| 275 |
|
| 276 |
const addEntitySpy = jest.spyOn(World.prototype, "addEntity"); |
| 277 |
const schedulerAddSpy = jest.spyOn(Scheduler.prototype, "add"); |
| 278 |
|
| 279 |
const mockComponent: PositionComponent = mock(PositionComponent); |
| 280 |
const mockEntity: Entity = mock(Entity); |
| 281 |
|
| 282 |
when(mockComponent.setPosition(anything())).thenReturn(); |
| 283 |
|
| 284 |
const componentMock = instance(mockComponent); |
| 285 |
|
| 286 |
when(mockEntity.hasComponent(anything())).thenReturn(true); |
| 287 |
when(mockEntity.getComponent(anything())).thenReturn(componentMock); |
| 288 |
|
| 289 |
const entityMock1 = instance(mockEntity); |
| 290 |
// const entityMock2 = instance(mockEntity); |
| 291 |
|
| 292 |
const map = new GameMap({ |
| 293 |
height: 1, |
| 294 |
tileFactory: tileFactoryMock, |
| 295 |
tiles: [[floorTile], [wallTile]], |
| 296 |
width: 2, |
| 297 |
}); |
| 298 |
|
| 299 |
const engine = new World(new Scheduler(), map, commandManagerMock, entityFactoryMock); |
| 300 |
const spiedEngine = spy(engine); |
| 301 |
when(spiedEngine.getRandomFloorPosition()).thenReturn({ x: 0, y: 0 }); |
| 302 |
|
| 303 |
expect(engine.getEntities().size).toBe(0); |
| 304 |
|
| 305 |
const result = engine.addEntityAtRandomPosition(entityMock1); |
| 306 |
|
| 307 |
expect(addEntitySpy).toHaveBeenCalledWith(entityMock1, false); |
| 308 |
expect(schedulerAddSpy).toHaveBeenCalledWith(entityMock1, false); |
| 309 |
expect(result.size).toBe(1); |
| 310 |
|
| 311 |
addEntitySpy.mockRestore(); |
| 312 |
schedulerAddSpy.mockRestore(); |
| 313 |
}); |
| 314 |
|
| 315 |
it("should do nothing if entity has no `PositionComponent`", () => { |
| 316 |
const floorTile = new FloorTile(); |
| 317 |
const wallTile = new WallTile(); |
| 318 |
|
| 319 |
const map = new GameMap({ |
| 320 |
height: 1, |
| 321 |
tileFactory: tileFactoryMock, |
| 322 |
tiles: [[floorTile], [wallTile]], |
| 323 |
width: 2, |
| 324 |
}); |
| 325 |
|
| 326 |
const mockEntity: Entity = mock(Entity); |
| 327 |
|
| 328 |
when(mockEntity.hasComponent(anything())).thenReturn(false); |
| 329 |
|
| 330 |
const entityMock = instance(mockEntity); |
| 331 |
|
| 332 |
const engine = new World(new Scheduler(), map, commandManagerMock, entityFactoryMock); |
| 333 |
|
| 334 |
expect(engine.getEntities().size).toBe(0); |
| 335 |
|
| 336 |
const result = engine.addEntityAtRandomPosition(entityMock); |
| 337 |
|
| 338 |
expect(result.size).toBe(0); |
| 339 |
}); |
| 340 |
}); |
| 341 |
|
| 342 |
describe("getRandomFloorPosition", (): void => { |
| 343 |
it("should return a walkable tile", (): void => { |
| 344 |
const floorTile = new FloorTile(); |
| 345 |
const wallTile = new WallTile(); |
| 346 |
|
| 347 |
const map = new GameMap({ |
| 348 |
height: 1, |
| 349 |
tileFactory: tileFactoryMock, |
| 350 |
tiles: [[floorTile], [wallTile]], |
| 351 |
width: 2, |
| 352 |
}); |
| 353 |
|
| 354 |
const engine = new World(new Scheduler(), map, commandManagerMock, entityFactoryMock); |
| 355 |
|
| 356 |
const result = engine.getRandomFloorPosition(); |
| 357 |
const tile = engine.getMap().getTile(result); |
| 358 |
|
| 359 |
expect(tile).toBe(floorTile); |
| 360 |
}); |
| 361 |
|
| 362 |
it("should be called again if target is not empty", (): void => { |
| 363 |
const floorTile = new FloorTile(); |
| 364 |
const wallTile = new WallTile(); |
| 365 |
|
| 366 |
const mockMapR: GameMap = mock(GameMap); |
| 367 |
when(mockMapR.getTiles()).thenReturn([[wallTile, wallTile, floorTile]]); |
| 368 |
when(mockMapR.getTile(anything())).thenReturn(wallTile).thenReturn(floorTile); |
| 369 |
when(mockMapR.getHeight()).thenReturn(1); |
| 370 |
when(mockMapR.getWidth()).thenReturn(3); |
| 371 |
|
| 372 |
const gameMapMockR: GameMap = instance(mockMapR); |
| 373 |
|
| 374 |
const engine = new World(new Scheduler(), gameMapMockR, commandManagerMock, entityFactoryMock); |
| 375 |
|
| 376 |
const result = engine.getRandomFloorPosition(); |
| 377 |
|
| 378 |
const tile = engine.getMap().getTile(result); |
| 379 |
|
| 380 |
expect(tile).toBe(floorTile); |
| 381 |
|
| 382 |
reset(mockMapR); |
| 383 |
}); |
| 384 |
}); |
| 385 |
|
| 386 |
describe("getSystems", () => { |
| 387 |
it("should return registered syystems", () => { |
| 388 |
const mockSystem: ConcreteSystem = mock(ConcreteSystem); |
| 389 |
const systemMock = instance(mockSystem); |
| 390 |
const engine = new World(new Scheduler(), gameMapMock, commandManagerMock, entityFactoryMock); |
| 391 |
|
| 392 |
engine.registerSystems([systemMock]); |
| 393 |
|
| Error |
Row 394, Column 20: "Array.from() is not supported in IE 9"
compat/compat
|
| 394 |
expect(Array.from(engine.getSystems())).toStrictEqual([systemMock]); |
| 395 |
}); |
| 396 |
}); |
| 397 |
}); |
| 398 |
|
|
|
|
/libs/games/tests/glyphs/character.spec.ts
|
0 problems
|
|
|
/libs/games/tests/glyphs/floor.spec.ts
|
0 problems
|
|
|
/libs/games/tests/glyphs/glyph.spec.ts
|
0 problems
|
|
|
/libs/games/tests/glyphs/wall.spec.ts
|
0 problems
|
|
|
/libs/games/tests/maps/directions.spec.ts
|
0 problems
|
|
|
/libs/games/tests/maps/generator-cellular.spec.ts
|
0 problems
|
|
|
/libs/games/tests/maps/map.spec.ts
|
0 problems
|
|
|
/libs/games/tests/opend6/difficulty.spec.ts
|
0 problems
|
|
|
/libs/games/tests/opend6/roll.spec.ts
|
0 problems
|
|
|
/libs/games/tests/screens/observer.spec.ts
|
0 problems
|
|
|
/libs/games/tests/screens/screen.spec.ts
|
0 problems
|
|
|
/libs/games/tests/tiles/factory.spec.ts
|
0 problems
|
|
|
/libs/games/tests/tiles/floor.spec.ts
|
0 problems
|
|
|
/libs/games/tests/tiles/null.spec.ts
|
0 problems
|
|
|
/libs/games/tests/tiles/tile.spec.ts
|
0 problems
|
|
|
/libs/games/tests/tiles/wall.spec.ts
|
0 problems
|
|
|
/libs/generators/tests/boolean.spec.ts
|
0 problems
|
|
|
/libs/generators/tests/uuid.spec.ts
|
0 problems
|
|
|
/libs/models/src/index.ts
|
0 problems
|
|
|
/libs/models/src/interfaces/index.ts
|
0 problems
|
|
|
/libs/models/src/interfaces/person.ts
|
0 problems
|
|
|
/libs/models/src/models/index.ts
|
0 problems
|
|
|
/libs/models/src/models/person.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 17, Column 9: "Object.assign() is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { NonFunctionKeys } from "utility-types"; |
| 2 |
|
| 3 |
import { Person } from "../interfaces"; |
| 4 |
|
| 5 |
export class PersonModel implements Person { |
| 6 |
public address!: string; |
| 7 |
|
| 8 |
public emailAddress!: string; |
| 9 |
|
| 10 |
public firstName!: string; |
| 11 |
|
| 12 |
public lastName!: string; |
| 13 |
|
| 14 |
public phoneNumber!: string; |
| 15 |
|
| 16 |
public constructor(data: Pick<Person, NonFunctionKeys<Person>>) { |
| Error |
Row 17, Column 9: "Object.assign() is not supported in IE 9"
compat/compat
|
| 17 |
Object.assign(this, data); |
| 18 |
} |
| 19 |
} |
| 20 |
|
|
|
|
/libs/models/tests/models/person.spec.ts
|
0 problems
|
|
|
/libs/patterns/src/command/command.ts
|
0 problems
|
|
|
/libs/patterns/src/command/index.ts
|
0 problems
|
|
|
/libs/patterns/src/command/manager.ts
|
0 problems
|
|
|
/libs/patterns/src/ecs/component.ts
|
0 problems
|
|
|
/libs/patterns/src/ecs/entity.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 19, Column 27: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { ComponentInterface } from "./component"; |
| 2 |
|
| 3 |
export interface EntityInterface { |
| 4 |
getId(): string; |
| 5 |
getComponent(name: string): ComponentInterface | undefined; |
| 6 |
getComponents(): Map<string, ComponentInterface>; |
| 7 |
addComponent(component: ComponentInterface): void; |
| 8 |
removeComponent(component: ComponentInterface): void; |
| 9 |
hasComponent(name: string): boolean; |
| 10 |
} |
| 11 |
|
| 12 |
export class Entity implements EntityInterface { |
| 13 |
protected id: string; |
| 14 |
|
| 15 |
protected components: Map<string, ComponentInterface>; |
| 16 |
|
| 17 |
public constructor(id: string) { |
| 18 |
this.id = id; |
| Error |
Row 19, Column 27: "Map is not supported in IE 9"
compat/compat
|
| 19 |
this.components = new Map<string, ComponentInterface>(); |
| 20 |
} |
| 21 |
|
| 22 |
public getId(): string { |
| 23 |
return this.id; |
| 24 |
} |
| 25 |
|
| 26 |
public getComponents(): Map<string, ComponentInterface> { |
| 27 |
return this.components; |
| 28 |
} |
| 29 |
|
| 30 |
public getComponent(name: string): ComponentInterface | undefined { |
| 31 |
return this.components.get(name); |
| 32 |
} |
| 33 |
|
| 34 |
public addComponent(component: ComponentInterface): Map<string, ComponentInterface> { |
| 35 |
return this.components.set(component.getName(), component); |
| 36 |
} |
| 37 |
|
| 38 |
public removeComponent(component: ComponentInterface): boolean { |
| 39 |
if (this.components.has(component.getName())) { |
| 40 |
return this.components.delete(component.getName()); |
| 41 |
} |
| 42 |
|
| 43 |
return true; |
| 44 |
} |
| 45 |
|
| 46 |
public hasComponent(name: string): boolean { |
| 47 |
return this.components.has(name); |
| 48 |
} |
| 49 |
} |
| 50 |
|
|
|
|
/libs/patterns/src/ecs/index.ts
|
0 problems
|
|
|
/libs/patterns/src/ecs/system.ts
|
0 problems
|
|
|
/libs/patterns/src/ecs/world.interface.ts
|
0 problems
|
|
|
/libs/patterns/src/ecs/world.ts
|
2 problems (2 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 15, Column 25: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 16, Column 24: "Set is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { uuid } from "@jga/generators"; |
| 2 |
|
| 3 |
import { WorldInterface } from "./world.interface"; |
| 4 |
|
| 5 |
import { SystemInterface } from "./system"; |
| 6 |
|
| 7 |
import { Entity } from "./entity"; |
| 8 |
|
| 9 |
export class World implements WorldInterface { |
| 10 |
protected entities: Map<string, Entity>; |
| 11 |
|
| 12 |
protected systems: Set<SystemInterface>; |
| 13 |
|
| 14 |
public constructor() { |
| Error |
Row 15, Column 25: "Map is not supported in IE 9"
compat/compat
|
| 15 |
this.entities = new Map<string, Entity>(); |
| Error |
Row 16, Column 24: "Set is not supported in IE 9"
compat/compat
|
| 16 |
this.systems = new Set<SystemInterface>(); |
| 17 |
} |
| 18 |
|
| 19 |
public getEntities(): Map<string, Entity> { |
| 20 |
return this.entities; |
| 21 |
} |
| 22 |
|
| 23 |
public getSystems(): Set<SystemInterface> { |
| 24 |
return this.systems; |
| 25 |
} |
| 26 |
|
| 27 |
public createEntity(): Entity { |
| 28 |
const entity = new Entity(this.generateId()); |
| 29 |
|
| 30 |
this.addEntity(entity); |
| 31 |
|
| 32 |
return entity; |
| 33 |
} |
| 34 |
|
| 35 |
public addEntity(entity: Entity): Map<string, Entity> { |
| 36 |
return this.entities.set(entity.getId(), entity); |
| 37 |
} |
| 38 |
|
| 39 |
public removeEntity(entity: Entity): Map<string, Entity> { |
| 40 |
if (this.entities.has(entity.getId())) { |
| 41 |
this.entities.delete(entity.getId()); |
| 42 |
} |
| 43 |
|
| 44 |
return this.entities; |
| 45 |
} |
| 46 |
|
| 47 |
public registerSystems(systems: SystemInterface[]): void { |
| 48 |
this.systems.clear(); |
| 49 |
systems.forEach((system) => this.systems.add(system)); |
| 50 |
} |
| 51 |
|
| 52 |
public process(): void { |
| 53 |
return this.systems.forEach((system): void => { |
| 54 |
system.run(this); |
| 55 |
}); |
| 56 |
} |
| 57 |
|
| 58 |
protected generateId(): string { |
| 59 |
let id: string; |
| 60 |
// eslint-disable-next-line no-loops/no-loops |
| 61 |
do { |
| 62 |
id = uuid(); |
| 63 |
} while (this.entities.has(id)); |
| 64 |
|
| 65 |
return id; |
| 66 |
} |
| 67 |
} |
| 68 |
|
|
|
|
/libs/patterns/src/factory.ts
|
0 problems
|
|
|
/libs/patterns/src/index.ts
|
0 problems
|
|
|
/libs/patterns/src/iterable.ts
|
0 problems
|
|
|
/libs/patterns/src/iterator.ts
|
0 problems
|
|
|
/libs/patterns/src/money/account.ts
|
1 problem (1 error, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 17, Column 25: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { CurrencyInterface } from "./currency"; |
| 2 |
import { MoneyInterface } from "./money"; |
| 3 |
|
| 4 |
export interface AccountInterface { |
| 5 |
getId(): number; |
| 6 |
getBalance(currency: CurrencyInterface): number; |
| 7 |
deposit(monye: MoneyInterface): number; |
| 8 |
} |
| 9 |
|
| 10 |
export class Account implements AccountInterface { |
| 11 |
protected id: number; |
| 12 |
|
| 13 |
protected balances: Map<CurrencyInterface, number>; |
| 14 |
|
| 15 |
public constructor(id: number) { |
| 16 |
this.id = id; |
| Error |
Row 17, Column 25: "Map is not supported in IE 9"
compat/compat
|
| 17 |
this.balances = new Map<CurrencyInterface, number>(); |
| 18 |
} |
| 19 |
|
| 20 |
public getId(): number { |
| 21 |
return this.id; |
| 22 |
} |
| 23 |
|
| 24 |
public getBalance(currency: CurrencyInterface): number { |
| 25 |
return this.balances.has(currency) && this.balances.get(currency) != null |
| 26 |
? Number(this.balances.get(currency)) |
| 27 |
: 0; |
| 28 |
} |
| 29 |
|
| 30 |
public deposit(money: MoneyInterface): number { |
| 31 |
if (!this.balances.has(money.getCurrency())) { |
| 32 |
this.balances.set(money.getCurrency(), 0); |
| 33 |
} |
| 34 |
|
| 35 |
this.balances.set(money.getCurrency(), Number(this.balances.get(money.getCurrency())) + money.getAmount()); |
| 36 |
|
| 37 |
return Number(this.balances.get(money.getCurrency())); |
| 38 |
} |
| 39 |
|
| 40 |
public withdraw(money: MoneyInterface): number { |
| 41 |
if (!this.balances.has(money.getCurrency())) { |
| 42 |
throw new Error(`This account has no currency ${money.getCurrency().getStringRepresentation()}`); |
| 43 |
} |
| 44 |
|
| 45 |
if (Number(this.balances.get(money.getCurrency())) < money.getAmount()) { |
| 46 |
throw new Error("Balance is not enough for this withdraw"); |
| 47 |
} |
| 48 |
|
| 49 |
this.balances.set(money.getCurrency(), Number(this.balances.get(money.getCurrency())) - money.getAmount()); |
| 50 |
|
| 51 |
return Number(this.balances.get(money.getCurrency())); |
| 52 |
} |
| 53 |
} |
| 54 |
|
|
|
|
/libs/patterns/src/money/currency.ts
|
0 problems
|
|
|
/libs/patterns/src/money/index.ts
|
0 problems
|
|
|
/libs/patterns/src/money/money.ts
|
0 problems
|
|
|
/libs/patterns/src/observer.ts
|
0 problems
|
|
|
/libs/patterns/src/singleton.ts
|
0 problems
|
|
|
/libs/patterns/tests/command.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/ecs/component.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/ecs/entity.spec.ts
|
5 problems (5 errors, 0 warnings)
|
| Severity |
Rule |
| Error |
Row 37, Column 30: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 46, Column 26: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 57, Column 31: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 59, Column 31: "Map is not supported in IE 9"
compat/compat
|
| Error |
Row 73, Column 30: "Map is not supported in IE 9"
compat/compat
|
| Line |
Source |
| 1 |
import { instance, mock, reset, when } from "ts-mockito"; |
| 2 |
|
| 3 |
import { Component, ComponentInterface, Entity } from "@jga/patterns/index"; |
| 4 |
|
| 5 |
const uuid = "2c5ea4c0-4067-11e9-8bad-9b1deb4d3b7d"; |
| 6 |
|
| 7 |
describe("Entity", (): void => { |
| 8 |
const componentName: ComponentInterface = "My awesome component"; |
| 9 |
const mockComponent: ComponentInterface = mock(Component); |
| 10 |
when(mockComponent.getName()).thenReturn(componentName); |
| 11 |
|
| 12 |
let componentMock: ComponentInterface; |
| 13 |
|
| 14 |
beforeEach(() => { |
| 15 |
componentMock = instance(mockComponent); |
| 16 |
}); |
| 17 |
|
| 18 |
afterAll(() => { |
| 19 |
reset(mockComponent); |
| 20 |
}); |
| 21 |
|
| 22 |
it("should be instantiable", (): void => { |
| 23 |
const entity = new Entity(uuid); |
| 24 |
|
| 25 |
expect(entity).not.toBeNull(); |
| 26 |
}); |
| 27 |
|
| 28 |
describe("constructor", (): void => { |
| 29 |
it("should init id", (): void => { |
| 30 |
const expected = uuid; |
| 31 |
const entity = new Entity(uuid); |
| 32 |
|
| 33 |
expect(entity.getId()).toBe(expected); |
| 34 |
}); |
| 35 |
|
| 36 |
it("should have empty components on init", (): void => { |
| Error |
Row 37, Column 30: "Map is not supported in IE 9"
compat/compat
|
| 37 |
const expected = new Map<string, ComponentInterface>(); |
| 38 |
const entity = new Entity(uuid); |
| 39 |
|
| 40 |
expect(entity.getComponents()).toStrictEqual(expected); |
| 41 |
}); |
| 42 |
}); |
| 43 |
|
| 44 |
it("should be able to add component", (): void => { |
| 45 |
const component = componentMock; |
| Error |
Row 46, Column 26: "Map is not supported in IE 9"
compat/compat
|
| 46 |
const expected = new Map<string, ComponentInterface>(); |
| 47 |
expected.set(component.getName(), component); |
| 48 |
const entity = new Entity(uuid); |
| 49 |
entity.addComponent(component); |
| 50 |
|
| 51 |
expect(entity.getComponents()).toStrictEqual(expected); |
| 52 |
}); |
| 53 |
|
| 54 |
describe("removeComponent", (): void => { |
| 55 |
it("should be able to remove component", (): void => { |
| 56 |
const component = componentMock; |
| Error |
Row 57, Column 31: "Map is not supported in IE 9"
compat/compat
|
| 57 |
const expected1 = new Map<string, ComponentInterface>(); |
| 58 |
expected1.set(component.getName(), component); |
| Error |
Row 59, Column 31: "Map is not supported in IE 9"
compat/compat
|
| 59 |
const expected2 = new Map<string, ComponentInterface>(); |
| 60 |
const entity = new Entity(uuid); |
| 61 |
entity.addComponent(component); |
| 62 |
|
| 63 |
expect(entity.getComponents()).toStrictEqual(expected1); |
| 64 |
|
| 65 |
entity.removeComponent(component); |
| 66 |
|
| 67 |
expect(entity.getComponents()).toStrictEqual(expected2); |
| 68 |
}); |
| 69 |
|
| 70 |
it("should do nothing if component is not found", (): void => { |
| 71 |
const component = componentMock; |
| 72 |
|
| Error |
Row 73, Column 30: "Map is not supported in IE 9"
compat/compat
|
| 73 |
const expected = new Map<string, ComponentInterface>(); |
| 74 |
|
| 75 |
const entity = new Entity(uuid); |
| 76 |
entity.removeComponent(component); |
| 77 |
|
| 78 |
expect(entity.getComponents()).toStrictEqual(expected); |
| 79 |
}); |
| 80 |
}); |
| 81 |
|
| 82 |
it("should be able to find if a component is present", (): void => { |
| 83 |
const component = componentMock; |
| 84 |
const entity = new Entity(uuid); |
| 85 |
|
| 86 |
entity.addComponent(component); |
| 87 |
|
| 88 |
expect(entity.hasComponent(componentName)).toBe(true); |
| 89 |
}); |
| 90 |
|
| 91 |
it("should be able to retrieve a component", (): void => { |
| 92 |
const expected = componentMock; |
| 93 |
const entity = new Entity(uuid); |
| 94 |
|
| 95 |
entity.addComponent(expected); |
| 96 |
|
| 97 |
expect(entity.getComponent(componentName)).toBe(expected); |
| 98 |
}); |
| 99 |
}); |
| 100 |
|
|
|
|
/libs/patterns/tests/ecs/world.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/factory.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/iterable.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/iterator.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/money/account.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/money/currency.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/money/money.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/observer.spec.ts
|
0 problems
|
|
|
/libs/patterns/tests/singleton.spec.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/entities/factory.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/entities/fungus.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/entities/index.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/game.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/index.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/screens/factory.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/screens/index.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/screens/lose.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/screens/play.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/screens/start.ts
|
0 problems
|
|
|
/libs/roguelike-engine/src/screens/win.ts
|
0 problems
|
|
|
/libs/roguelike-engine/tests/entities/factory.spec.ts
|
0 problems
|
|
|
/libs/roguelike-engine/tests/entities/fungus.spec.ts
|
0 problems
|
|
|
/libs/roguelike-engine/tests/game.spec.ts
|
0 problems
|
|
|
/libs/roguelike-engine/tests/screens/factory.spec.ts
|
0 problems
|
|
|
/libs/roguelike-engine/tests/screens/lose.spec.ts
|
0 problems
|
|
|
/libs/roguelike-engine/tests/screens/play.spec.ts
|
0 problems
|
|
|
/libs/roguelike-engine/tests/screens/start.spec.ts
|
0 problems
|
|
|
/libs/roguelike-engine/tests/screens/win.spec.ts
|
0 problems
|
|
|
/libs/strings/src/capitalize.ts
|
0 problems
|
|
|
/libs/strings/src/index.ts
|
0 problems
|
|
|
/libs/strings/src/leftpad.ts
|
0 problems
|
|
|
/libs/strings/tests/capitalize-every-word.spec.ts
|
0 problems
|
|
|
/libs/strings/tests/capitalize.spec.ts
|
0 problems
|
|
|
/libs/strings/tests/leftpad.spec.ts
|
0 problems
|
|
|
/libs/ui/button/src/button.svelte
|
0 problems
|
|
|
/libs/ui/button/src/global.d.ts
|
0 problems
|
|
|
/libs/ui/button/src/main.ts
|
0 problems
|
|
|
/libs/ui/button/tests/button.spec.ts
|
0 problems
|
|
|
/libs/ui/collapse/src/collapse.svelte
|
0 problems
|
|
|
/libs/ui/collapse/src/global.d.ts
|
0 problems
|
|
|
/libs/ui/collapse/src/main.ts
|
0 problems
|
|
|
/libs/ui/collapse/tests/collapse.spec.ts
|
0 problems
|
|
|
/libs/ui/leaderboard/src/global.d.ts
|
0 problems
|
|
|
/libs/ui/leaderboard/src/leaderboard.svelte
|
0 problems
|
|
|
/libs/ui/leaderboard/src/main.ts
|
0 problems
|
|
|
/libs/ui/leaderboard/tests/leaderboard.spec.ts
|
0 problems
|
|
|
/libs/ui/placeholder-loader/src/global.d.ts
|
0 problems
|
|
|
/libs/ui/placeholder-loader/src/main.ts
|
0 problems
|
|
|
/libs/ui/placeholder-loader/src/placeholder-loader.svelte
|
0 problems
|
|
|
/libs/ui/placeholder-loader/tests/placeholder-loader.spec.ts
|
0 problems
|
|
|
/libs/ui/progress/src/global.d.ts
|
0 problems
|
|
|
/libs/ui/progress/src/main.ts
|
0 problems
|
|
|
/libs/ui/progress/src/progress.svelte
|
0 problems
|
|
|
/libs/ui/progress/tests/progress.spec.ts
|
0 problems
|
|
|
/libs/ui/table/src/global.d.ts
|
0 problems
|
|
|
/libs/ui/table/src/main.ts
|
0 problems
|
|
|
/libs/ui/table/src/table.svelte
|
0 problems
|
|
|
/libs/ui/table/tests/table.spec.ts
|
0 problems
|
|
|
/libs/ui/tabs/src/global.d.ts
|
0 problems
|
|
|
/libs/ui/tabs/src/main.ts
|
0 problems
|
|
|
/libs/ui/tabs/src/tabs.svelte
|
0 problems
|
|
|
/libs/ui/tabs/tests/tabs.spec.ts
|
0 problems
|