feat: Implement general and nation turn commands with command specifications
- Added command specifications for various general turn commands including talent scouting, appointments, and military actions. - Introduced command specifications for nation turn commands such as assignments and declarations of war. - Created a command environment interface to encapsulate command-related parameters. - Developed a command profile loader to manage default and custom command profiles. - Established a reserved turn action context to facilitate command execution with necessary context data. - Updated the default command profile JSON to include new commands and their configurations.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import {
|
||||
DEFAULT_TURN_COMMAND_PROFILE,
|
||||
parseTurnCommandProfile,
|
||||
type TurnCommandProfile,
|
||||
} from '@sammo-ts/logic';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const REPO_ROOT = path.resolve(__dirname, '..', '..', '..', '..');
|
||||
const DEFAULT_PROFILE_PATH = path.resolve(
|
||||
REPO_ROOT,
|
||||
'resources',
|
||||
'turn-commands',
|
||||
'default.json'
|
||||
);
|
||||
|
||||
export interface TurnCommandProfileOptions {
|
||||
filePath?: string;
|
||||
}
|
||||
|
||||
const readCommandProfile = async (filePath: string): Promise<TurnCommandProfile> => {
|
||||
const raw = await fs.readFile(filePath, 'utf8');
|
||||
return parseTurnCommandProfile(JSON.parse(raw) as unknown);
|
||||
};
|
||||
|
||||
export const loadTurnCommandProfile = async (
|
||||
options?: TurnCommandProfileOptions
|
||||
): Promise<TurnCommandProfile> => {
|
||||
const filePath =
|
||||
options?.filePath ?? process.env.TURN_COMMANDS_PATH ?? DEFAULT_PROFILE_PATH;
|
||||
try {
|
||||
return await readCommandProfile(filePath);
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
||||
return DEFAULT_TURN_COMMAND_PROFILE;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user