Skip to content

Commit

Permalink
chore(enums): transform enums to unions where needed (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Apr 9, 2024
1 parent efc6749 commit 44eebe2
Show file tree
Hide file tree
Showing 208 changed files with 85,307 additions and 71,202 deletions.
3,177 changes: 1,628 additions & 1,549 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ sonar.javascript.lcov.reportPaths=tests/coverage/lcov.info
# Coverage
sonar.coverage.exclusions=src/main.ts, src/**/*.schema.ts, src/**/*.dto.*s

# Duplication
sonar.cpd.exclusions=**/*.constants.ts

# Encoding
sonar.sourceEncoding=UTF-8
3 changes: 3 additions & 0 deletions src/modules/config/env/constants/env.constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const ENVIRONNEMENTS = ["development", "production", "test"] as const;

const MIN_PORT_VALUE = 0;

const MAX_PORT_VALUE = 65535;
Expand All @@ -7,6 +9,7 @@ const DEFAULT_APP_HOST = "127.0.0.1";
const DEFAULT_APP_PORT = 8080;

export {
ENVIRONNEMENTS,
MIN_PORT_VALUE,
MAX_PORT_VALUE,
DEFAULT_APP_HOST,
Expand Down
7 changes: 0 additions & 7 deletions src/modules/config/env/enums/env.enum.ts

This file was deleted.

12 changes: 7 additions & 5 deletions src/modules/config/env/types/env.types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString, Max, Min } from "class-validator";
import { IsIn, IsNotEmpty, IsNumber, IsOptional, IsString, Max, Min } from "class-validator";
import { TupleToUnion } from "type-fest";

import { DEFAULT_APP_HOST, DEFAULT_APP_PORT, MAX_PORT_VALUE, MIN_PORT_VALUE } from "@/modules/config/env/constants/env.constants";
import { Environnements } from "@/modules/config/env/enums/env.enum";
import { DEFAULT_APP_HOST, DEFAULT_APP_PORT, ENVIRONNEMENTS, MAX_PORT_VALUE, MIN_PORT_VALUE } from "@/modules/config/env/constants/env.constants";

type Environnement = TupleToUnion<typeof ENVIRONNEMENTS>;

class EnvironmentVariables {
@IsEnum(Environnements)
public ENVIRONMENT: Environnements;
@IsIn(ENVIRONNEMENTS)
public ENVIRONMENT: Environnement;

@IsOptional()
@IsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RoleNames } from "@/modules/role/enums/role.enum";
import type { RoleName } from "@/modules/role/types/role.types";

const GAME_ADDITIONAL_CARDS_RECIPIENTS = [RoleNames.THIEF, RoleNames.ACTOR] as const satisfies Readonly<(RoleNames)[]>;
const GAME_ADDITIONAL_CARDS_RECIPIENTS = ["thief", "actor"] as const satisfies Readonly<(RoleName)[]>;

export { GAME_ADDITIONAL_CARDS_RECIPIENTS };
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const GAME_HISTORY_RECORD_VOTING_RESULTS = [
"sheriff-election",
"tie",
"death",
"inconsequential",
"skipped",
] as const;

export { GAME_HISTORY_RECORD_VOTING_RESULTS };
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ReadonlyDeep } from "type-fest";

import { GamePhases } from "@/modules/game/enums/game.enum";
import type { GameOptions } from "@/modules/game/schemas/game-options/game-options.schema";

const DEFAULT_GAME_OPTIONS: ReadonlyDeep<GameOptions> = {
Expand All @@ -13,7 +12,7 @@ const DEFAULT_GAME_OPTIONS: ReadonlyDeep<GameOptions> = {
isEnabled: true,
electedAt: {
turn: 1,
phase: GamePhases.NIGHT,
phase: "night",
},
hasDoubledVote: true,
mustSettleTieInVotes: true,
Expand Down
104 changes: 76 additions & 28 deletions src/modules/game/constants/game-play/game-play.constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PlayerAttributeNames, PlayerGroups } from "@/modules/game/enums/player.enum";
import { RoleNames } from "@/modules/role/enums/role.enum";
import type { PlayerAttributeName } from "@/modules/game/types/player/player-attribute/player-attribute.types";
import type { PlayerGroup } from "@/modules/game/types/player/player.types";
import type { RoleName } from "@/modules/role/types/role.types";

const GAME_PLAY_TYPES = [
"no-action",
Expand All @@ -11,35 +12,82 @@ const GAME_PLAY_TYPES = [
"bury-dead-bodies",
] as const;

const GAME_PLAY_ACTIONS = [
"eat",
"look",
"charm",
"use-potions",
"shoot",
"protect",
"mark",
"meet-each-other",
"sniff",
"choose-model",
"choose-side",
"ban-voting",
"choose-card",
"elect-sheriff",
"vote",
"delegate",
"settle-votes",
"bury-dead-bodies",
"growl",
"infect",
"request-another-vote",
] as const;

const GAME_PLAY_SOURCE_NAMES = [
PlayerAttributeNames.SHERIFF,
PlayerGroups.CHARMED,
PlayerGroups.LOVERS,
PlayerGroups.SURVIVORS,
PlayerGroups.WEREWOLVES,
RoleNames.BIG_BAD_WOLF,
RoleNames.CUPID,
RoleNames.WOLF_HOUND,
RoleNames.FOX,
RoleNames.DEFENDER,
RoleNames.HUNTER,
RoleNames.PIED_PIPER,
RoleNames.SCANDALMONGER,
RoleNames.SCAPEGOAT,
RoleNames.SEER,
RoleNames.STUTTERING_JUDGE,
RoleNames.THIEF,
RoleNames.THREE_BROTHERS,
RoleNames.TWO_SISTERS,
RoleNames.WHITE_WEREWOLF,
RoleNames.WILD_CHILD,
RoleNames.WITCH,
RoleNames.ACTOR,
RoleNames.BEAR_TAMER,
RoleNames.ACCURSED_WOLF_FATHER,
] as const satisfies Readonly<(PlayerAttributeNames | PlayerGroups | RoleNames)[]>;
"sheriff",
"charmed",
"lovers",
"survivors",
"werewolves",
"big-bad-wolf",
"cupid",
"wolf-hound",
"fox",
"defender",
"hunter",
"pied-piper",
"scandalmonger",
"scapegoat",
"seer",
"stuttering-judge",
"thief",
"three-brothers",
"two-sisters",
"white-werewolf",
"wild-child",
"witch",
"actor",
"bear-tamer",
"accursed-wolf-father",
] as const satisfies Readonly<(PlayerAttributeName | PlayerGroup | RoleName)[]>;

const GAME_PLAY_CAUSES = [
"stuttering-judge-request",
"previous-votes-were-in-ties",
"angel-presence",
] as const;

const GAME_PLAY_OCCURRENCES = [
"one-night-only",
"on-nights",
"on-days",
"anytime",
"consequential",
] as const;

const WITCH_POTIONS = [
"life",
"death",
] as const;

export {
GAME_PLAY_TYPES,
GAME_PLAY_ACTIONS,
GAME_PLAY_SOURCE_NAMES,
GAME_PLAY_CAUSES,
GAME_PLAY_OCCURRENCES,
WITCH_POTIONS,
};
12 changes: 12 additions & 0 deletions src/modules/game/constants/game-victory/game-victory.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const GAME_VICTORY_TYPES = [
"none",
"werewolves",
"villagers",
"lovers",
"pied-piper",
"white-werewolf",
"angel",
"prejudiced-manipulator",
] as const;

export { GAME_VICTORY_TYPES };

0 comments on commit 44eebe2

Please sign in to comment.