Skip to content

Commit

Permalink
Fix dynamic linking of phases
Browse files Browse the repository at this point in the history
  • Loading branch information
vck3000 committed Feb 12, 2024
1 parent 277cb42 commit 7c5cfec
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "ProAvalon",
"scripts": {
"build": "tsc && webpack --config webpack.prod.js && cp -R ./src/views ./out",
"build": "rm -rf out; tsc && webpack --config webpack.prod.js && cp -R ./src/views ./out",
"dev": "concurrently -k \"npm:dev:tsnd\" \"npm:dev:webpack\"",
"dev:tsnd": "ts-node-dev --respawn --inspect --ignore-watch \".tsx$\" ./src/app.ts",
"dev:webpack": "rm -f ./assets/dist_webpack/* && webpack serve --config webpack.dev.js",
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/avalon/cards/lady of the lake.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Phase from '../phases/phases';
import Phase from '../../phases';

class LadyOfTheLake {
constructor(thisRoom) {
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/avalon/cards/ref of the rain.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Phase from '../phases/phases';
import Phase from '../../phases';

class RefOfTheLake {
constructor(thisRoom) {
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/avalon/cards/sire of the sea.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Phase from '../phases/phases';
import Phase from '../../phases';

class SireOfTheSea {
constructor(thisRoom) {
Expand Down
40 changes: 17 additions & 23 deletions src/gameplay/avalon/indexPhases.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
// This file helps us load in the roles from the folder
import fs from 'fs';
import path from 'path';
import Assassination from './phases/assassination';
import Lady from './phases/lady';
import Ref from './phases/ref';
import Sire from './phases/sire';

export const getPhases = function (thisRoom) {
const normalizedPath = path.join(__dirname, './phases');
const phases = {
[Assassination.phase.toLowerCase()]: Assassination,
[Lady.phase.toLowerCase()]: Lady,
[Ref.phase.toLowerCase()]: Ref,
[Sire.phase.toLowerCase()]: Sire,
};

const phases = {};
export const getPhases = function (thisRoom) {
const obj = {};

fs.readdirSync(normalizedPath).forEach((file) => {
// console.log(file);

// If it is a javascript file, add it
if (file.includes('.js') === true && !file.includes('.map')) {
// Trim .js at the end of the file name
name = file.replace('.js', '');

phases[name] = require(`./phases/${file}`).default;
}
});

for (var name in phases) {
if (phases.hasOwnProperty(name)) {
// Initialise it
obj[name] = new phases[name](thisRoom);
}
// No good way to map over an object, so we do this iteratively.
// Note this implementation leads to a limitation of one role per game.
// Not great...!
// TODO
for (const [phaseName, phaseClass] of Object.entries(phases)) {
obj[phaseName] = new phaseClass(thisRoom);
}

return obj;
Expand Down
6 changes: 4 additions & 2 deletions src/gameplay/avalon/phases/assassination.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
- Status message to display
*/
import usernamesIndexes from '../../../myFunctions/usernamesIndexes';
import Phase from '../phases/phases';
import Phase from '../../phases';

class Assassination {
static phase = 'Assassination';
phase = Phase.assassination;

constructor(thisRoom) {
this.thisRoom = thisRoom;

// The role that is the owner of this phase
this.role = 'Assassin';

this.phase = Phase.assassination;
this.showGuns = true;

this.finishedShot = false;
Expand Down
6 changes: 4 additions & 2 deletions src/gameplay/avalon/phases/lady.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
*/

import usernamesIndexes from '../../../myFunctions/usernamesIndexes';
import Phase from './phases';
import Phase from '../../phases';

class Lady {
static phase = Phase.lady;
phase = Phase.lady;

constructor(thisRoom) {
this.thisRoom = thisRoom;

this.phase = Phase.lady;
this.showGuns = false;

this.card = 'Lady of the Lake';
Expand Down
6 changes: 4 additions & 2 deletions src/gameplay/avalon/phases/ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
*/

import usernamesIndexes from '../../../myFunctions/usernamesIndexes';
import Phase from '../phases/phases';
import Phase from '../../phases';

class Ref {
static phase = Phase.ref;
phase = Phase.ref;

constructor(thisRoom) {
this.thisRoom = thisRoom;

this.phase = Phase.ref;
this.showGuns = false;

this.card = 'Ref of the Rain';
Expand Down
6 changes: 4 additions & 2 deletions src/gameplay/avalon/phases/sire.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
*/

import usernamesIndexes from '../../../myFunctions/usernamesIndexes';
import Phase from './phases';
import Phase from '../../phases';

class Sire {
static phase = Phase.sire;
phase = Phase.sire;

constructor(thisRoom) {
this.thisRoom = thisRoom;

this.phase = Phase.sire;
this.showGuns = false;

this.card = 'Sire of the Sea';
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/avalon/roles/assassin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Role, See } from '../../types';
import Game from '../../game';
import Phase from '../phases/phases';
import Phase from '../../phases';

class Assassin implements Role {
room: Game;
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/commonPhases/finished.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Phase from '../avalon/phases/phases';
import Phase from '../phases';

function Finished(thisRoom_) {
this.thisRoom = thisRoom_;
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/commonPhases/frozen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Number of targets allowed to be selected
- Status message to display
*/
import Phase from '../avalon/phases/phases';
import Phase from '../phases';

function Frozen(thisRoom_) {
this.thisRoom = thisRoom_;
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/commonPhases/paused.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Number of targets allowed to be selected
- Status message to display
*/
import Phase from '../avalon/phases/phases';
import Phase from '../phases';

function Paused(thisRoom_) {
this.thisRoom = thisRoom_;
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/commonPhases/pickingTeam.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import usernamesIndexes from '../../myFunctions/usernamesIndexes';
import Phase from '../avalon/phases/phases';
import Phase from '../phases';
import { MIN_PLAYERS } from '../game';

function PickingTeam(thisRoom_) {
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/commonPhases/votingMission.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import usernamesIndexes from '../../myFunctions/usernamesIndexes';
import Phase from '../avalon/phases/phases';
import Phase from '../phases';

function VotingMission(thisRoom_) {
this.thisRoom = thisRoom_;
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/commonPhases/votingTeam.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import usernamesIndexes from '../../myFunctions/usernamesIndexes';
import Phase from '../avalon/phases/phases';
import Phase from '../phases';

function VotingTeam(thisRoom_) {
this.thisRoom = thisRoom_;
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { modOrTOString } from '../modsadmins/modOrTO';

import { getRoomTypeFromString, roomCreationTypeEnum } from './roomTypes';
import { gameModeObj } from './gameModes';
import Phase from './avalon/phases/phases';
import Phase from './phases';

export const WAITING = 'Waiting';
export const MIN_PLAYERS = 5;
Expand Down
File renamed without changes.

0 comments on commit 7c5cfec

Please sign in to comment.