-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #895 from virtualcommons/solo
feat: add solo mode
- Loading branch information
Showing
73 changed files
with
3,216 additions
and
63 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Room } from "colyseus.js"; | ||
import { EventContinue, Invest, SoloGameRequest } from "@port-of-mars/shared/sologame"; | ||
|
||
export class SoloGameRequestAPI { | ||
room!: Room; | ||
|
||
connect(room: Room) { | ||
this.room = room; | ||
} | ||
|
||
public leave() { | ||
if (this.room) { | ||
this.room.leave(); | ||
} | ||
} | ||
|
||
public send(req: SoloGameRequest) { | ||
this.room.send(req.kind, req); | ||
} | ||
|
||
public eventContinue() { | ||
const msg: EventContinue = { kind: "event-continue" }; | ||
this.send(msg); | ||
} | ||
|
||
public invest(systemHealthInvestment: number) { | ||
const msg: Invest = { | ||
kind: "invest", | ||
systemHealthInvestment, | ||
}; | ||
this.send(msg); | ||
} | ||
} |
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,67 @@ | ||
import { Room } from "colyseus.js"; | ||
import { DataChange, Schema } from "@colyseus/schema"; | ||
import { SetHiddenParams } from "@port-of-mars/shared/sologame"; | ||
|
||
type Schemify<T> = T & Schema; | ||
|
||
function deschemify<T>(s: Schemify<T>): T { | ||
return s.toJSON() as T; | ||
} | ||
|
||
export function applySoloGameServerResponses(room: Room, component: any) { | ||
// const store = component.$tstore; | ||
// const router = component.$router; | ||
|
||
room.onError((code: number, message?: string) => { | ||
console.log(`Error ${code} occurred in room: ${message} `); | ||
alert("sorry, we encountered an error, please try refreshing the page or contact us"); | ||
}); | ||
|
||
room.onLeave((code: number) => { | ||
console.log(`client left the room: ${code}`); | ||
}); | ||
|
||
function applyChanges(target: any, changes: DataChange[], fields: string[]) { | ||
changes.forEach(change => { | ||
if (fields.includes(change.field)) { | ||
target[change.field] = change.value; | ||
} | ||
}); | ||
} | ||
|
||
room.state.player.onChange = (changes: DataChange[]) => { | ||
applyChanges(component.state.player, changes, ["points", "resources"]); | ||
}; | ||
|
||
room.state.treatmentParams.onChange = (changes: DataChange[]) => { | ||
applyChanges(component.state.treatmentParams, changes, [ | ||
"isNumberOfRoundsKnown", | ||
"isEventDeckKnown", | ||
"thresholdInformation", | ||
]); | ||
}; | ||
|
||
room.state.onChange = (changes: DataChange[]) => { | ||
applyChanges(component.state, changes, [ | ||
"round", | ||
"timeRemaining", | ||
"systemHealth", | ||
"activeCardId", | ||
"canInvest", | ||
"isRoundTransitioning", | ||
"status", | ||
]); | ||
}; | ||
|
||
room.state.visibleEventCards.onAdd = (eventCard: any, key: number) => { | ||
component.state.visibleEventCards.push(deschemify(eventCard)); | ||
}; | ||
|
||
room.state.visibleEventCards.onRemove = (eventCard: any, key: number) => { | ||
component.state.visibleEventCards.shift(); | ||
}; | ||
|
||
room.onMessage("set-hidden-params", (msg: SetHiddenParams) => { | ||
component.state = { ...component.state, ...msg.data }; | ||
}); | ||
} |
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
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<div class="d-flex py-2 px-3 vfd-container"> | ||
<VFDNumberDisplay :digits="2" :value="minutesRemaining" variant="red" :size="3" /> | ||
<p style="font-size: 3rem" class="vfd-text-glow vfd-red">:</p> | ||
<VFDNumberDisplay | ||
:digits="2" | ||
:value="secondsRemaining" | ||
:padZeros="true" | ||
variant="red" | ||
:size="3" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { Vue, Component, Prop } from "vue-property-decorator"; | ||
import VFDNumberDisplay from "@port-of-mars/client/components/sologame/VFDNumberDisplay.vue"; | ||
@Component({ | ||
components: { | ||
VFDNumberDisplay, | ||
}, | ||
}) | ||
export default class Clock extends Vue { | ||
@Prop({ default: 0 }) timeRemaining!: number; | ||
@Prop({ default: 3 }) size!: number; // in rem | ||
get secondsRemaining() { | ||
return this.timeRemaining % 60; | ||
} | ||
get minutesRemaining() { | ||
return Math.floor(this.timeRemaining / 60); | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss"></style> |
Oops, something went wrong.