Auto-formatting for context classes.
This commit is contained in:
parent
ab7f41b924
commit
5fa8803f8c
@ -5,29 +5,29 @@ import { ContextVariableType } from "@spt-aki/context/ContextVariableType";
|
||||
import { LinkedList } from "@spt-aki/utils/collections/lists/LinkedList";
|
||||
|
||||
@injectable()
|
||||
export class ApplicationContext
|
||||
export class ApplicationContext
|
||||
{
|
||||
private variables = new Map<ContextVariableType, LinkedList<ContextVariable>>();
|
||||
private static holderMaxSize = 10;
|
||||
|
||||
/**
|
||||
* Called like:
|
||||
*
|
||||
* const registerPlayerInfo = this.applicationContext.getLatestValue(ContextVariableType.REGISTER_PLAYER_REQUEST).getValue<IRegisterPlayerRequestData>();
|
||||
*
|
||||
* const activePlayerSessionId = this.applicationContext.getLatestValue(ContextVariableType.SESSION_ID).getValue<string>();
|
||||
*
|
||||
* const matchInfo = this.applicationContext.getLatestValue(ContextVariableType.MATCH_INFO).getValue<IStartOfflineRaidRequestData>();
|
||||
* @param type
|
||||
* @returns
|
||||
* @examples
|
||||
*
|
||||
* const registerPlayerInfo = this.applicationContext.getLatestValue(ContextVariableType.REGISTER_PLAYER_REQUEST)
|
||||
* .getValue<IRegisterPlayerRequestData>();
|
||||
*
|
||||
* const activePlayerSessionId = this.applicationContext.getLatestValue(ContextVariableType.SESSION_ID)
|
||||
* .getValue<string>();
|
||||
*
|
||||
* const matchInfo = this.applicationContext.getLatestValue(ContextVariableType.MATCH_INFO)
|
||||
* .getValue<IStartOfflineRaidRequestData>();
|
||||
*/
|
||||
public getLatestValue(type: ContextVariableType): ContextVariable
|
||||
public getLatestValue(type: ContextVariableType): ContextVariable
|
||||
{
|
||||
if (this.variables.has(type))
|
||||
if (this.variables.has(type))
|
||||
{
|
||||
return this.variables.get(type)?.getTail()?.getValue();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -37,22 +37,27 @@ export class ApplicationContext
|
||||
{
|
||||
return this.variables.get(type).toList();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public addValue(type: ContextVariableType, value: any): void
|
||||
public addValue(type: ContextVariableType, value: any): void
|
||||
{
|
||||
let list: LinkedList<ContextVariable>;
|
||||
if (this.variables.has(type))
|
||||
{
|
||||
list = this.variables.get(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
list = new LinkedList<ContextVariable>();
|
||||
}
|
||||
|
||||
if (list.getSize() >= ApplicationContext.holderMaxSize)
|
||||
{
|
||||
list.removeFirst();
|
||||
}
|
||||
|
||||
list.add(new ContextVariable(value, type));
|
||||
this.variables.set(type, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,4 +27,4 @@ export class ContextVariable
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
export enum ContextVariableType
|
||||
{
|
||||
/** Logged in users session id */
|
||||
SESSION_ID = 0,
|
||||
/** Currently acive raid information */
|
||||
RAID_CONFIGURATION = 1,
|
||||
/** Timestamp when client first connected */
|
||||
CLIENT_START_TIMESTAMP = 2,
|
||||
/** When player is loading into map and loot is requested */
|
||||
REGISTER_PLAYER_REQUEST = 3
|
||||
}
|
||||
export enum ContextVariableType
|
||||
{
|
||||
SESSION_ID = 0, // Logged in users session id
|
||||
RAID_CONFIGURATION = 1, // Currently active raid information
|
||||
CLIENT_START_TIMESTAMP = 2, // Timestamp when client first connected
|
||||
REGISTER_PLAYER_REQUEST = 3, // When player is loading into map and loot is requested
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user