-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common): Adds the peek() method to PKProvider
Also finishes fixing unit tests for the Agent PK refactor and adds documentation re #104
- Loading branch information
Showing
12 changed files
with
228 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
/* | ||
* Contains the `Agent` primary key system. | ||
* | ||
* Copyright (c) Joseph R Cowman | ||
* Licensed under MIT License (see https://github.com/regal/regal) | ||
*/ | ||
|
||
import { buildPKProvider } from "../../common"; | ||
|
||
/** The set of reserved `Agent` primary keys. */ | ||
export const AGENT_RESERVED_KEYS = { | ||
/** Every `GameInstance` has this key. */ | ||
GAME_INSTANCE: 100, | ||
/** Before an `Agent` is activated, it has this key. */ | ||
INACTIVE: 99 | ||
}; | ||
|
||
export let STATIC_AGENT_PK_PROVIDER = buildPKProvider(AGENT_RESERVED_KEYS); | ||
/** The `Agent` `PKProvider` for static agents. */ | ||
export const STATIC_AGENT_PK_PROVIDER = buildPKProvider(AGENT_RESERVED_KEYS); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
/* | ||
* Contains various utilities for the Agents component. | ||
* | ||
* Copyright (c) Joseph R Cowman | ||
* Licensed under MIT License (see https://github.com/regal/regal) | ||
*/ | ||
|
||
import { PK } from "../../common"; | ||
import { Agent } from "../agent"; | ||
import { AGENT_RESERVED_KEYS, STATIC_AGENT_PK_PROVIDER } from "./agent-keys"; | ||
|
||
/** Shorthand for the `AGENT_RESERVED_KEYS.INACTIVE` primary key. */ | ||
export const getInactiveAgentPK = () => | ||
STATIC_AGENT_PK_PROVIDER.reserved(AGENT_RESERVED_KEYS.INACTIVE); | ||
|
||
export const isAgentActive = (id: PK<Agent>) => | ||
!getInactiveAgentPK().equals(id); | ||
|
||
/** Shorthand for the `AGENT_RESERVED_KEYS.GAME_INSTANCE` primary key. */ | ||
export const getGameInstancePK = () => | ||
STATIC_AGENT_PK_PROVIDER.reserved(AGENT_RESERVED_KEYS.GAME_INSTANCE); | ||
|
||
/** Determines whether an `Agent` has been activated, given its primary key. */ | ||
export const isAgentActive = (id: PK<Agent>) => | ||
!getInactiveAgentPK().equals(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.