CONTRACTS: createDummyContract returns filename (#1129)

This commit is contained in:
Bart Kuijper 2024-03-02 05:12:04 +01:00 committed by GitHub
parent 4c7f192645
commit 6a3d22d7bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 5 deletions

@ -9,7 +9,7 @@ Generate a dummy contract.
**Signature:** **Signature:**
```typescript ```typescript
createDummyContract(type: string): void; createDummyContract(type: string): string;
``` ```
## Parameters ## Parameters
@ -20,7 +20,9 @@ createDummyContract(type: string): void;
**Returns:** **Returns:**
void string
Filename of the contract.
## Remarks ## Remarks

@ -47,13 +47,15 @@ export function generateRandomContractOnHome(): void {
serv.addContract(contract); serv.addContract(contract);
} }
export const generateDummyContract = (problemType: string): void => { export const generateDummyContract = (problemType: string): string => {
if (!CodingContractTypes[problemType]) throw new Error(`Invalid problem type: '${problemType}'`); if (!CodingContractTypes[problemType]) throw new Error(`Invalid problem type: '${problemType}'`);
const serv = Player.getHomeComputer(); const serv = Player.getHomeComputer();
const contractFn = getRandomFilename(serv); const contractFn = getRandomFilename(serv);
const contract = new CodingContract(contractFn, problemType, null); const contract = new CodingContract(contractFn, problemType, null);
serv.addContract(contract); serv.addContract(contract);
return contractFn;
}; };
interface IGenerateContractParams { interface IGenerateContractParams {

@ -81,7 +81,7 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
}, },
createDummyContract: (ctx) => (_type) => { createDummyContract: (ctx) => (_type) => {
const type = helpers.string(ctx, "type", _type); const type = helpers.string(ctx, "type", _type);
generateDummyContract(type); return generateDummyContract(type);
}, },
getContractTypes: () => () => codingContractTypesMetadata.map((c) => c.name), getContractTypes: () => () => codingContractTypesMetadata.map((c) => c.name),
}; };

@ -3577,8 +3577,9 @@ export interface CodingContract {
* Generate a dummy contract on the home computer with no reward. Used to test various algorithms. * Generate a dummy contract on the home computer with no reward. Used to test various algorithms.
* *
* @param type - Type of contract to generate * @param type - Type of contract to generate
* @returns Filename of the contract.
*/ */
createDummyContract(type: string): void; createDummyContract(type: string): string;
/** /**
* List all contract types. * List all contract types.