Skip to content

Commit

Permalink
fix: Bot compound actions (#109)
Browse files Browse the repository at this point in the history
* chore(server): path mapping

* fix: bunch of small changes

* test: fixes

* fix: comp action association

* feat: consider ready clients

* feat: first player is ready by default

* fix: issues around failed room start
  • Loading branch information
Zielak authored Jun 30, 2024
1 parent 73d6d5c commit fef1b7e
Show file tree
Hide file tree
Showing 193 changed files with 1,943 additions and 1,116 deletions.
16 changes: 14 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = {
"import/first": "error",
"import/named": "error",
"import/no-absolute-path": "error",
// "import/no-cycle": "error",
"import/no-mutable-exports": "error",
"import/no-self-import": "error",
"import/no-unused-modules": "error",
Expand All @@ -20,8 +19,21 @@ module.exports = {
order: "asc",
caseInsensitive: true,
},
// "groups": ["index", "sibling", "parent", "internal", "external", "builtin", "object"],
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
],
"newlines-between": "always",
pathGroups: [
{
pattern: "@/**",
group: "internal",
},
],
},
],
"no-extra-semi": "off",
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"files.exclude": {
"**/.turbo": true,
"**/lib": true,
"**/node_modules": true,
// "**/lib": true,
// "**/node_modules": true,
"docs/docs/api/**": true,
"docs/build/**": true,
"docs/.docusaurus/**": true
Expand Down
42 changes: 39 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"lint-staged": "^15.0.2",
"prettier": "^3.0.3",
"release-please": "^16.1.0",
"resolve-tspaths": "^0.8.19",
"rollup": "^2.67.2",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^29.0.3",
Expand Down
10 changes: 5 additions & 5 deletions packages/client/src/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ObjectSchemaColyBase<T> = {
onChange: SchemaChangeCallback
listen<K extends keyof T>(
propName: K,
callback: (value: T[K], previousValue: T[K]) => void
callback: (value: T[K], previousValue: T[K]) => void,
): () => void
}
type _ArrayCollection<T extends Array<any>> =
Expand Down Expand Up @@ -115,7 +115,7 @@ interface EntityParentNode {
* Root game state
*/
export type ClientGameStateProps = {
clients: string[]
clients: GameClientDefinition[]

currentPlayerIdx?: number
isGameStarted: boolean
Expand Down Expand Up @@ -169,13 +169,13 @@ export function isDefinitionOfMapSchema(o: unknown): o is MapSchemaDefinition {
}

export function isDefinitionOfArraySchema(
o: unknown
o: unknown,
): o is ArraySchemaDefinition {
return typeof o === "object" && o !== null && "array" in o
}

export function isDefinitionOfPrimitivesCollection(
o: unknown
o: unknown,
): o is CollectionOfPrimitivesDefinition {
if (isDefinitionOfMapSchema(o)) {
return typeof o.map === "string"
Expand All @@ -186,7 +186,7 @@ export function isDefinitionOfPrimitivesCollection(
}

export function isDefinitionOfObjectsCollection(
o: unknown
o: unknown,
): o is CollectionOfObjectsDefinition {
if (isDefinitionOfMapSchema(o)) {
return isDefinitionOfSchema(o.map)
Expand Down
10 changes: 10 additions & 0 deletions packages/server/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const base = require("@cardsgame/base-configs/jest.config.cjs")
const { pathsToModuleNameMapper } = require("ts-jest")

const { compilerOptions } = require("./tsconfig.json")

/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
...base,
displayName: "server",
setupFiles: ["./testSetup.ts"],
modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value
// modulePaths: [`<rootDir>/packages/server/${compilerOptions.baseUrl}`],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
// prefix: "<rootDir>/src/",
useESM: true,
}),
}
4 changes: 2 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
],
"scripts": {
"build": "concurrently npm:build:esm npm:build:cjs",
"build:esm": "tsc -p tsconfig.build.json",
"build:cjs": "tsc -p tsconfig.build.cjs.json && ../../scripts/mapToCjs.sh ./lib/cjs",
"build:esm": "tsc -p tsconfig.build.json && resolve-tspaths -p tsconfig.build.json && resolve-tspaths -p tsconfig.build.json -o ./lib/types/",
"build:cjs": "tsc -p tsconfig.build.cjs.json && resolve-tspaths -p tsconfig.build.cjs.json && ../../scripts/mapToCjs.sh ./lib/cjs",
"build:watch": "echo \"only for ESM!\" && tsc -p tsconfig.build.json --watch",
"test": "jest",
"test:watch": "jest --watch"
Expand Down
12 changes: 6 additions & 6 deletions packages/server/src/__test__/helpers/dumbEntities.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { canBeChild } from "../../annotations/canBeChild.js"
import { containsChildren } from "../../annotations/containsChildren.js"
import { ChildTrait } from "../../traits/child.js"
import { applyTraitsMixins, Entity } from "../../traits/entity.js"
import { IdentityTrait } from "../../traits/identity.js"
import { ParentTrait } from "../../traits/parent.js"
import { canBeChild } from "@/annotations/canBeChild.js"
import { containsChildren } from "@/annotations/containsChildren.js"
import { ChildTrait } from "@/traits/child.js"
import { applyTraitsMixins, Entity } from "@/traits/entity.js"
import { IdentityTrait } from "@/traits/identity.js"
import { ParentTrait } from "@/traits/parent.js"

@canBeChild
@containsChildren
Expand Down
14 changes: 7 additions & 7 deletions packages/server/src/__test__/helpers/labeledEntities.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { canBeChild } from "../../annotations/canBeChild.js"
import { containsChildren } from "../../annotations/containsChildren.js"
import { ChildTrait } from "../../traits/child.js"
import { applyTraitsMixins, Entity } from "../../traits/entity.js"
import { IdentityTrait } from "../../traits/identity.js"
import { LabelTrait } from "../../traits/label.js"
import { ParentTrait } from "../../traits/parent.js"
import { canBeChild } from "@/annotations/canBeChild.js"
import { containsChildren } from "@/annotations/containsChildren.js"
import { ChildTrait } from "@/traits/child.js"
import { applyTraitsMixins, Entity } from "@/traits/entity.js"
import { IdentityTrait } from "@/traits/identity.js"
import { LabelTrait } from "@/traits/label.js"
import { ParentTrait } from "@/traits/parent.js"

@canBeChild
@containsChildren
Expand Down
14 changes: 7 additions & 7 deletions packages/server/src/__test__/helpers/ownableEntities.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { canBeChild } from "../../annotations/canBeChild.js"
import { containsChildren } from "../../annotations/containsChildren.js"
import { ChildTrait } from "../../traits/child.js"
import { applyTraitsMixins, Entity } from "../../traits/entity.js"
import { IdentityTrait } from "../../traits/identity.js"
import { OwnershipTrait } from "../../traits/ownership.js"
import { ParentTrait } from "../../traits/parent.js"
import { canBeChild } from "@/annotations/canBeChild.js"
import { containsChildren } from "@/annotations/containsChildren.js"
import { ChildTrait } from "@/traits/child.js"
import { applyTraitsMixins, Entity } from "@/traits/entity.js"
import { IdentityTrait } from "@/traits/identity.js"
import { OwnershipTrait } from "@/traits/ownership.js"
import { ParentTrait } from "@/traits/parent.js"

@canBeChild
@containsChildren
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { noop } from "@cardsgame/utils"

import { defineRoom } from "../room/defineRoom.js"
import { defineRoom } from "@/room/defineRoom.js"

const TestRoom = defineRoom("TestRoom", {
onPlayerTurnEnded: jest.fn(),
Expand Down
14 changes: 7 additions & 7 deletions packages/server/src/__test__/helpers/selectableParent.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { canBeChild } from "../../annotations/canBeChild.js"
import { containsChildren } from "../../annotations/containsChildren.js"
import { ChildTrait } from "../../traits/child.js"
import { applyTraitsMixins, Entity } from "../../traits/entity.js"
import { IdentityTrait } from "../../traits/identity.js"
import { ParentTrait } from "../../traits/parent.js"
import { SelectableChildrenTrait } from "../../traits/selectableChildren.js"
import { canBeChild } from "@/annotations/canBeChild.js"
import { containsChildren } from "@/annotations/containsChildren.js"
import { ChildTrait } from "@/traits/child.js"
import { applyTraitsMixins, Entity } from "@/traits/entity.js"
import { IdentityTrait } from "@/traits/identity.js"
import { ParentTrait } from "@/traits/parent.js"
import { SelectableChildrenTrait } from "@/traits/selectableChildren.js"

@canBeChild
@containsChildren
Expand Down
18 changes: 9 additions & 9 deletions packages/server/src/__test__/helpers/smartEntities.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { def } from "@cardsgame/utils"

import { canBeChild } from "../../annotations/canBeChild.js"
import { containsChildren } from "../../annotations/containsChildren.js"
import type { State } from "../../state/state.js"
import { ChildTrait } from "../../traits/child.js"
import { applyTraitsMixins, Entity } from "../../traits/entity.js"
import { IdentityTrait } from "../../traits/identity.js"
import { LabelTrait } from "../../traits/label.js"
import { OwnershipTrait } from "../../traits/ownership.js"
import { ParentTrait } from "../../traits/parent.js"
import { canBeChild } from "@/annotations/canBeChild.js"
import { containsChildren } from "@/annotations/containsChildren.js"
import type { State } from "@/state/state.js"
import { ChildTrait } from "@/traits/child.js"
import { applyTraitsMixins, Entity } from "@/traits/entity.js"
import { IdentityTrait } from "@/traits/identity.js"
import { LabelTrait } from "@/traits/label.js"
import { OwnershipTrait } from "@/traits/ownership.js"
import { ParentTrait } from "@/traits/parent.js"

@canBeChild
@containsChildren
Expand Down
Loading

0 comments on commit fef1b7e

Please sign in to comment.