本文整理汇总了TypeScript中src/utils.isObject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isObject函数的具体用法?TypeScript isObject怎么用?TypeScript isObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isObject函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: stateUpdated
/**
* Invoked when the state updates.
*
* @param current - The current (most) game state, will be this.next if this.current is undefined.
* @param next - The next (most) game state, will be this.current if this.next is undefined.
* @param delta - The current (most) delta, which explains what happened.
* @param nextDelta - The the next (most) delta, which explains what happend.
*/
public stateUpdated(
current: Immutable<IUnitState>,
next: Immutable<IUnitState>,
delta: Immutable<Delta>,
nextDelta: Immutable<Delta>,
): void {
super.stateUpdated(current, next, delta, nextDelta);
// <<-- Creer-Merge: state-updated -->>
// update the Unit based off its states
this.attackingTile = undefined;
if (nextDelta.type === "ran" && nextDelta.data.run.caller.id === this.id) {
if (nextDelta.data.returned) {
const { run } = nextDelta.data;
const tile = this.game.gameObjects[String(
isObject(run.args.tile) && run.args.tile.id,
)];
switch (run.functionName) {
case "attack":
this.attackingTile = tile && (tile as Tile).getNextMostState();
}
}
}
// <<-- /Creer-Merge: state-updated -->>
}
开发者ID:siggame,项目名称:Viseur,代码行数:34,代码来源:unit.ts
示例2: deserialize
export function deserialize<T extends unknown>(data: T, game?: BaseGame): T {
if (isObject(data)) {
// TODO: check for game object reference?
const result: UnknownObject = Array.isArray(data) ? [] : {};
for (const key of (Object.keys(data))) {
result[key] = deserialize((data as UnknownObject)[key], game);
}
return result as T;
}
return data;
}
开发者ID:siggame,项目名称:Viseur,代码行数:14,代码来源:serializer.ts
示例3: serialize
export function serialize(
data: unknown,
): string | number | { [key: string]: string | number } {
// Then no need to serialize it, it's already json serializable as a
// string, number, boolean, null, etc.
if (!isObject(data)) {
return data as string | number;
}
if (data.id) {
// No need to serialize this whole game object,
// just send an object reference
return { id: String(data.id) };
}
const serialized: UnknownObject = Array.isArray(data) ? [] : {};
for (const key of Object.keys(data)) {
if (isSerializable(data, key)) {
serialized[key] = serialize(data[key]);
}
}
return serialized as { [key: string]: string | number };
}
开发者ID:siggame,项目名称:Viseur,代码行数:24,代码来源:serializer.ts
示例4: isSerializable
export function isSerializable(obj: object, key: string): boolean {
return isObject(obj) && objectHasProperty(obj, key);
}
开发者ID:siggame,项目名称:Viseur,代码行数:3,代码来源:serializer.ts
示例5: requireGameResource
/** The expected interface all games must export from their interface. */
interface IGameExport {
/** The Namespace that contains all data to initiate a game from. */
namespace: IBaseGameNamespace;
}
// require all images in the build
/** Requires a resource in a game's resources directory. */
export const requireGameResource = require.context("./", true, /^(.*(\.(png|jpe?g)$))[^.]*$/im);
for (const key of requireGameResource.keys()) {
requireGameResource(key);
}
const games: {[gameName: string]: IBaseGameNamespace | undefined} = {};
const req = require.context("./", true, /\.\/([^\/]+)\/index.ts/); // match ./*/index.ts, but only 1 directory.
for (const key of req.keys()) {
const required = req(key) as IGameExport;
if (!required || !isObject(required) || !isObject(required.namespace)) {
throw new Error(`Game "${key}" does not export the expected interface!`);
}
const { namespace } = required;
if (namespace.Game) {
games[namespace.Game.gameName] = namespace;
}
}
/** All the game namespaces that can be loaded by this instance */
export const GAMES = Object.freeze(games);
开发者ID:siggame,项目名称:Viseur,代码行数:30,代码来源:index.ts
注:本文中的src/utils.isObject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论