Skip to content

Commit

Permalink
feat(agent): Start implementing new Agent model [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
jcowman2 committed Sep 28, 2018
1 parent 73afb40 commit 9d408a8
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/new-agents/agent-model.ts
@@ -0,0 +1,56 @@
import { RegalError } from "../error";
import GameInstance from "../game-instance";
import {
addAgentToStaticRegistry,
getNextStaticAgentId,
getStaticAgentProperty,
isContextStatic
} from "./todo";

const agentReservedProperties = ["id", "game", "isActivated"];

const AGENT_PROXY_HANDLER = {
get(target: Agent, property: PropertyKey) {
if (agentReservedProperties.includes(property.toString())) {
return Reflect.get(target, property);
}

if (!target.isActivated) {
throw new RegalError(
"The agent has not been activated; that property is not accessible."
);
}

let value = target.game.agents.getAgentProperty(target.id, property);

if (
value === undefined &&
!target.game.agents.agentPropertyWasDeleted(target.id, property)
) {
value = getStaticAgentProperty(target.id, property);
}

return value;
},

set(target: Agent, property: PropertyKey, value: any): boolean {
// todo
return true;
}
};

export class Agent {
public id: number;
public game: GameInstance;
public isActivated: boolean;

constructor() {
this.isActivated = false;

if (isContextStatic()) {
this.id = getNextStaticAgentId();
addAgentToStaticRegistry(this);
}
return new Proxy({} as Agent, AGENT_PROXY_HANDLER);
}
}
20 changes: 20 additions & 0 deletions src/new-agents/todo.ts
@@ -0,0 +1,20 @@
import { Agent } from "./agent-model";

export const isContextStatic = () => {
return true;
};

export const getNextStaticAgentId = () => {
return 1;
};

export const addAgentToStaticRegistry = (agent: Agent) => {
return;
};

export const getStaticAgentProperty = (
id: number,
property: PropertyKey
): any => {
return;
};

0 comments on commit 9d408a8

Please sign in to comment.