mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-05 15:17:48 +02:00
MISC: Refactor coding contracts for type safety (#1653)
* MISC: Refactor coding contracts for type safety This refactor does three things without any behavior changes: * Adds type safety by introducing generic type parameters to the coding contract definitions, so they can use concrete types instead of "unknown". This also eliminates a bunch of boilerplate casts. * Removes the unneeded CodingContractType class. We can use the metadata type directly. * Introduces a new hidden state to coding contracts. Instead of generating and storing the data (which is what is shown to the user as the problem's input), the state is stored instead. This allows problems to (for instance) generate the answer up-front, and check the solution directly against the answer, instead of needing to embed a solver in the problem (which can then easily be ripped from the source code). For compatibility, state == data by default. I plan to make use of this feature in a followup, but it is unused currently.
This commit is contained in:
@@ -56,7 +56,7 @@ export function CodingContractModal(): React.ReactElement {
|
||||
|
||||
const contractType = CodingContractTypes[contract.c.type];
|
||||
const description = [];
|
||||
for (const [i, value] of contractType.desc(contract.c.data).split("\n").entries())
|
||||
for (const [i, value] of contractType.desc(contract.c.getData()).split("\n").entries())
|
||||
description.push(<span key={i} dangerouslySetInnerHTML={{ __html: value + "<br />" }}></span>);
|
||||
return (
|
||||
<Modal open={contract !== null} onClose={close}>
|
||||
|
||||
Reference in New Issue
Block a user