Skip to content

Commit

Permalink
placeball
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Oct 25, 2023
1 parent a55fe32 commit e46ceee
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/diagram.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/controller/placeball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class PlaceBall extends ControllerBase {

override onFirst() {
const cueball = this.container.table.cueball
cueball.pos.copy(new Vector3((-R * 11) / 0.5, 0, 0))
if (this.container.rules.allowsPlaceBall()) {
cueball.pos.copy(this.container.rules.placeBall())
}
cueball.setStationary()
cueball.updateMesh(0)
this.container.table.cue.placeBallMode()
Expand Down
9 changes: 9 additions & 0 deletions src/controller/rules/nineball.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Vector3 } from "three"
import { Container } from "../../container/container"
import { Aim } from "../../controller/aim"
import { Controller } from "../../controller/controller"
Expand All @@ -13,6 +14,7 @@ import { Rack } from "../../utils/rack"
import { zero } from "../../utils/utils"
import { End } from "../end"
import { Rules } from "./rules"
import { R } from "../../model/physics/constants"

export class NineBall implements Rules {
readonly container: Container
Expand All @@ -23,6 +25,13 @@ export class NineBall implements Rules {
this.container = container
}

placeBall(target?): Vector3 {
if (target) {
return target
}
return new Vector3((-R * 11) / 0.5, 0, 0)
}

asset(): string {
return "models/p8.min.gltf"
}
Expand Down
2 changes: 2 additions & 0 deletions src/controller/rules/rules.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Vector3 } from "three"
import { Controller } from "../../controller/controller"
import { Ball } from "../../model/ball"
import { Outcome } from "../../model/outcome"
Expand All @@ -13,5 +14,6 @@ export interface Rules {
isPartOfBreak(outcome: Outcome[]): boolean
isEndOfGame(outcome: Outcome[]): boolean
allowsPlaceBall(): boolean
placeBall(target?): Vector3
asset(): string
}
8 changes: 8 additions & 0 deletions src/controller/rules/snooker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Vector3 } from "three"
import { WatchEvent } from "../../events/watchevent"
import { Outcome } from "../../model/outcome"
import { Rack } from "../../utils/rack"
Expand All @@ -16,6 +17,13 @@ export class Snooker extends NineBall implements Rules {
return Rack.snooker()
}

override placeBall(target?): Vector3 {
if (target) {
return target
}
return new Vector3(Rack.baulk, -Rack.sixth / 3, 0)
}

override update(outcome: Outcome[]): Controller {
const pots = Outcome.potCount(outcome)
if (pots > 0) {
Expand Down
6 changes: 6 additions & 0 deletions src/controller/rules/threecushion.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Vector3 } from "three"
import { Container } from "../../container/container"
import { Aim } from "../../controller/aim"
import { Controller } from "../../controller/controller"
Expand All @@ -11,6 +12,7 @@ import { Rack } from "../../utils/rack"
import { CameraTop } from "../../view/cameratop"
import { TableGeometry } from "../../view/tablegeometry"
import { Rules } from "./rules"
import { zero } from "../../utils/utils"

export class ThreeCushion implements Rules {
readonly container: Container
Expand All @@ -21,6 +23,10 @@ export class ThreeCushion implements Rules {
this.container = container
}

placeBall(_?: any): Vector3 {
return zero
}

asset(): string {
return "models/threecushion.min.gltf"
}
Expand Down

0 comments on commit e46ceee

Please sign in to comment.