-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prejudiced-manipulator): prejudiced manipulator role (#699)
Closes #678
- Loading branch information
1 parent
4f67f80
commit f5c8f3c
Showing
59 changed files
with
52,746 additions
and
45,600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Prejudiced Manipulator Role" type="js.build_tools.npm" folderName="Cucumber Tags"> | ||
<package-json value="$PROJECT_DIR$/package.json" /> | ||
<command value="run" /> | ||
<scripts> | ||
<script value="test:cucumber" /> | ||
</scripts> | ||
<arguments value="-- --tags "@prejudiced-manipulator-role"" /> | ||
<node-interpreter value="project" /> | ||
<envs /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
47 changes: 47 additions & 0 deletions
47
src/modules/game/dto/base/decorators/composition/composition-groups-presence.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { ValidationOptions, ValidationArguments } from "class-validator"; | ||
import { registerDecorator } from "class-validator"; | ||
import { has } from "lodash"; | ||
|
||
import type { CreateGameDto } from "@/modules/game/dto/create-game/create-game.dto"; | ||
import { RoleNames } from "@/modules/role/enums/role.enum"; | ||
|
||
function isCompositionGroupsExistenceRespected(value: unknown): boolean { | ||
if (!Array.isArray(value) || value.some(player => !has(player, ["role", "name"]))) { | ||
return false; | ||
} | ||
const players = value as { role: { name: RoleNames }; group?: string }[]; | ||
const doesCompositionHasPrejudicedManipulator = players.some(({ role }) => role.name === RoleNames.PREJUDICED_MANIPULATOR); | ||
const doesSomePlayerHaveAGroup = players.some(({ group }) => group !== undefined); | ||
const doesEveryPlayerHaveAGroup = players.every(({ group }) => group !== undefined); | ||
return doesCompositionHasPrejudicedManipulator && doesEveryPlayerHaveAGroup || !doesCompositionHasPrejudicedManipulator && !doesSomePlayerHaveAGroup; | ||
} | ||
|
||
function getCompositionGroupsPresenceDefaultMessage(validationArguments: ValidationArguments): string { | ||
const { players } = validationArguments.object as Partial<CreateGameDto>; | ||
const doesCompositionHasPrejudicedManipulator = players?.some(({ role }) => role.name === RoleNames.PREJUDICED_MANIPULATOR) === true; | ||
if (doesCompositionHasPrejudicedManipulator) { | ||
return `each player must have a group if there is a player with role \`${RoleNames.PREJUDICED_MANIPULATOR}\``; | ||
} | ||
return `any player can't have a group if there is no player with role \`${RoleNames.PREJUDICED_MANIPULATOR}\``; | ||
} | ||
|
||
function CompositionGroupsPresence(validationOptions?: ValidationOptions) { | ||
return (object: object, propertyName: string): void => { | ||
registerDecorator({ | ||
name: "CompositionGroupsConsistency", | ||
target: object.constructor, | ||
propertyName, | ||
options: validationOptions, | ||
validator: { | ||
validate: isCompositionGroupsExistenceRespected, | ||
defaultMessage: getCompositionGroupsPresenceDefaultMessage, | ||
}, | ||
}); | ||
}; | ||
} | ||
|
||
export { | ||
CompositionGroupsPresence, | ||
isCompositionGroupsExistenceRespected, | ||
getCompositionGroupsPresenceDefaultMessage, | ||
}; |
41 changes: 41 additions & 0 deletions
41
...ecorators/composition/composition-has-two-groups-with-prejudiced-manipulator.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { ValidationOptions } from "class-validator"; | ||
import { registerDecorator } from "class-validator"; | ||
import { has } from "lodash"; | ||
|
||
import { RoleNames } from "@/modules/role/enums/role.enum"; | ||
|
||
function doesCompositionHasTwoGroupsWithPrejudicedManipulator(value: unknown): boolean { | ||
if (!Array.isArray(value) || value.some(player => !has(player, ["role", "name"]))) { | ||
return false; | ||
} | ||
const players = value as { role: { name: RoleNames }; group?: string }[]; | ||
const doesCompositionHasPrejudicedManipulator = players.some(({ role }) => role.name === RoleNames.PREJUDICED_MANIPULATOR); | ||
const distinctGroups = [...new Set(players.map(({ group }) => group))]; | ||
const expectedDistinctGroupsCount = 2; | ||
return !doesCompositionHasPrejudicedManipulator || distinctGroups.length === expectedDistinctGroupsCount; | ||
} | ||
|
||
function getCompositionHasTwoGroupsWithPrejudicedManipulatorDefaultMessage(): string { | ||
return `there must be exactly two groups among players when \`${RoleNames.PREJUDICED_MANIPULATOR}\` in the game`; | ||
} | ||
|
||
function CompositionHasTwoGroupsWithPrejudicedManipulator(validationOptions?: ValidationOptions) { | ||
return (object: object, propertyName: string): void => { | ||
registerDecorator({ | ||
name: "CompositionHasTwoGroupsWithPrejudicedManipulator", | ||
target: object.constructor, | ||
propertyName, | ||
options: validationOptions, | ||
validator: { | ||
validate: doesCompositionHasTwoGroupsWithPrejudicedManipulator, | ||
defaultMessage: getCompositionHasTwoGroupsWithPrejudicedManipulatorDefaultMessage, | ||
}, | ||
}); | ||
}; | ||
} | ||
|
||
export { | ||
CompositionHasTwoGroupsWithPrejudicedManipulator, | ||
doesCompositionHasTwoGroupsWithPrejudicedManipulator, | ||
getCompositionHasTwoGroupsWithPrejudicedManipulatorDefaultMessage, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/modules/game/dto/base/decorators/composition/composition-roles-max-in-game.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.