Add current concealed No-Field Truthtrance facts
This commit is contained in:
1 parent
24c38ebccd
commit
5509abf1e5
13 files changed
+797
-12
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
validateRicheseNoField,
|
||||
type NoFieldValue,
|
||||
type RicheseNoField,
|
||||
} from './richese-no-field';
|
||||
|
||||
export type NoFieldValueFact = {
|
||||
kind: 'noFieldValue';
|
||||
value: NoFieldValue;
|
||||
};
|
||||
|
||||
export function parseNoFieldValueFact(value: unknown): NoFieldValueFact {
|
||||
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
||||
throw new Error('Choose a current concealed No-Field printed-value fact.');
|
||||
const input = value as Record<string, unknown>;
|
||||
const keys = Object.keys(input);
|
||||
if (
|
||||
keys.length !== 2 ||
|
||||
!keys.includes('kind') ||
|
||||
!keys.includes('value') ||
|
||||
input.kind !== 'noFieldValue'
|
||||
)
|
||||
throw new Error('Choose only a current concealed No-Field printed-value fact.');
|
||||
if (input.value !== 0 && input.value !== 3 && input.value !== 5)
|
||||
throw new Error('Choose the printed No-Field value zero, three, or five.');
|
||||
return { kind: 'noFieldValue', value: input.value };
|
||||
}
|
||||
|
||||
/** Observe current concealed custody, never shipment history or materialized forces. */
|
||||
export function noFieldValueFactMatches(
|
||||
state: RicheseNoField | undefined,
|
||||
fact: NoFieldValueFact,
|
||||
): boolean {
|
||||
if (state === undefined) return false;
|
||||
validateRicheseNoField(state);
|
||||
if (state.deployed === null) return false;
|
||||
const token = state.tokens.find(
|
||||
(candidate) => candidate.id === state.deployed!.tokenId,
|
||||
)!;
|
||||
return token.value === fact.value;
|
||||
}
|
||||
|
||||
export function noFieldValueFactText(fact: NoFieldValueFact): string {
|
||||
return `you currently have a concealed No-Field with printed value ${fact.value}`;
|
||||
}
|
||||
Reference in new issue
Block a user