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:**
```typescript
createDummyContract(type: string): void;
createDummyContract(type: string): string;
```
## Parameters
@ -20,7 +20,9 @@ createDummyContract(type: string): void;
**Returns:**
void
string
Filename of the contract.
## Remarks

@ -47,13 +47,15 @@ export function generateRandomContractOnHome(): void {
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}'`);
const serv = Player.getHomeComputer();
const contractFn = getRandomFilename(serv);
const contract = new CodingContract(contractFn, problemType, null);
serv.addContract(contract);
return contractFn;
};
interface IGenerateContractParams {

@ -81,7 +81,7 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
},
createDummyContract: (ctx) => (_type) => {
const type = helpers.string(ctx, "type", _type);
generateDummyContract(type);
return generateDummyContract(type);
},
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.
*
* @param type - Type of contract to generate
* @returns Filename of the contract.
*/
createDummyContract(type: string): void;
createDummyContract(type: string): string;
/**
* List all contract types.