Skip to content

Commit

Permalink
update paths for core
Browse files Browse the repository at this point in the history
  • Loading branch information
Greegko committed Jul 19, 2021
1 parent e15897e commit 97ce204
Show file tree
Hide file tree
Showing 84 changed files with 222 additions and 208 deletions.
10 changes: 7 additions & 3 deletions packages/core/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import 'reflect-metadata';
export * from './src/modules';
export * from './src/models';
export { createGameInstance, CreateGameInstance, GameConfig, GameConfigProvides } from './src/lib/create-game-instance';

export * from './src/modules/public-api';
export * from './src/models/public-api';
export * from './src/core/public-api';
export * from './src/create-game-instance';
export * from './src/create-inversify-container';
export * from './src/game-config';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommandSystem } from "../lib/command-system";
import { CommandSystem } from "@core/command";

export interface CommandHandler {
init(e: CommandSystem): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { injectable } from 'inversify';
import { forEach } from 'ramda';
import { CommandHandler } from '../models';
import { CommandHandler } from './command-handler';

export interface CommandSystem {
on(commandType: string, callback: Function): void;
Expand All @@ -23,4 +23,4 @@ export class CommandSystem {
execute(commandType: string, args?: any) {
this.subscribers[commandType](args);
}
}
}
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/core/src/core/command/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './command';
export * from './command-handler';
export * from './command-system';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventSystem } from "../lib/event-system";
import { EventSystem } from "./event-system";

export interface EventHandler {
init(e: EventSystem): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { injectable } from 'inversify';
import { forEach } from 'ramda';
import { EventHandler } from '../models';
import { EventHandler } from './event-handler';

export interface EventSystem {
on(eventType: string, callback: Function): void;
Expand All @@ -26,4 +26,4 @@ export class EventSystem {
fire(eventType: string, args?: any): void {
forEach(callback => callback(args), this.subscribers[eventType] || []);
}
}
}
2 changes: 2 additions & 0 deletions packages/core/src/core/event/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './event-handler';
export * from './event-system';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, interfaces } from "inversify";
import { forEach, pipe, propOr, juxt } from 'ramda';
import { Module, ModulActivity, ModulStore, ProvideClass, ProvideValue } from "../models";
import { Module, ModulActivity, ModulStore, ProvideClass, ProvideValue } from "@core/module";

export type ApplyModule = (container: Container) => (module: Module) => void;

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/core/module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './module';
export * from './apply-module';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IStore } from "./store";
import { CommandHandler } from './command-handler';
import { EventHandler } from './event-handler';
import { IActivityHandler } from "../modules/activity/interfaces";
import { IStore } from "@core/store";
import { CommandHandler } from '@core/command';
import { EventHandler } from '@core/event';
import { IActivityHandler } from "@modules/activity";

export interface ProvideClass { new(...args: any[]): any; }
export interface ProvideValue { provide: string; value: any }
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/core/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './module';
export * from './store';
export * from './command';
export * from './command';
export * from './event';
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { assoc, merge, dissoc, prop, omit } from 'ramda';
import { generate } from 'shortid';
import { IEntityStore, EntityStoreState, EntityUpdater } from '../models';
import { injectable } from 'inversify';

export type EntityUpdater<T> = (entity: T) => Partial<T>;

export type EntityStoreState<Entity extends { id: EntityID }, EntityID extends string = string> = { [key: string]: Entity };
export interface IEntityStore<Entity extends { id: EntityID }, EntityID extends string = string> {
getState(): EntityStoreState<Entity, EntityID>;
init(state: EntityStoreState<Entity, EntityID>): void;
get(id: EntityID): Entity;
add(entity: Entity): Entity;
update(entityId: EntityID, entity: Partial<Entity>): void;
update(entityId: EntityID, updater: EntityUpdater<Entity>): void;
remove(entityId: EntityID): void;
}

@injectable()
export class EntityStore<Entity extends { id: EntityID }, EntityID extends string = string> implements IEntityStore<Entity, EntityID> {
private state: EntityStoreState<Entity, EntityID> = {};
Expand Down Expand Up @@ -45,4 +57,4 @@ export class EntityStore<Entity extends { id: EntityID }, EntityID extends strin
remove(entityId: EntityID): void {
this.state = dissoc(entityId, this.state);
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { assoc, prop } from 'ramda';
import { IObjectStore } from "../models";
import { injectable } from 'inversify';

export interface IObjectStore<T extends object> {
getState(): T;
init(state: T): void;

get(prop: keyof T): T[keyof T];
set(prop: keyof T, value: T[keyof T]): void;
}

@injectable()
export class ObjectStore<T extends object> implements IObjectStore<T> {
private state: T = {} as T;
Expand All @@ -25,4 +32,4 @@ export class ObjectStore<T extends object> implements IObjectStore<T> {
update<P extends keyof T>(property: P, updater: (value: T[P]) => T[P]) {
this.state = assoc(property as string, updater(prop(property as string, this.state)), this.state);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { Module } from "../models";
import * as modules from '../modules';
import { GameInstance, GameState } from "../modules/game/interfaces";
import { createInvesifyContainer } from './create-inversify-container';
import { GameInstance, GameState } from "@modules/game";
import { forEach, forEachObjIndexed } from 'ramda';
import { applyModule } from "./apply-module";
import { Skill } from "../modules";
import { applyModule } from "@core/module";

import { createInvesifyContainer } from './create-inversify-container';
import * as modules from './modules/public-api';
import { Skill } from "./modules/skill";
import { GameConfig } from './game-config';

export interface GameConfigProvides {
available_skills: Skill[];
}

export interface GameConfig {
modules: Module[];
provides: GameConfigProvides;
}

export type CreateGameInstance = <S extends GameState>(config?: Partial<GameConfig>) => GameInstance<S>;

const coreModules = [
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/game-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@core/module';
import { GameConfigProvides } from "./create-game-instance";

export interface GameConfig {
modules: Module[];
provides: GameConfigProvides;
}
9 changes: 0 additions & 9 deletions packages/core/src/models/index.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/core/src/models/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './resource';
export * from './item';
export * from './effect';
export * from './loot';
12 changes: 0 additions & 12 deletions packages/core/src/models/store/entity-store.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/core/src/models/store/object-store.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/modules/activity/activity-manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { inject, injectable } from 'inversify';
import { forEach, values, assoc } from 'ramda';
import { PartyService } from '@modules/party';
import { GetActivityHandlerByName, PartyActivity, ActivityType, PartyActivityStartArgs } from './interfaces';
import { ActivityStore } from './activity-store';
import { PartyService } from '../party';

@injectable()
export class ActivityManager {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/activity/activity-module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from "../../models";
import { Module } from "@core/module";
import { ActivityManager } from "./activity-manager";
import { ActivityStore } from './activity-store';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/activity/activity-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityStore } from "../../lib/entity-store";
import { EntityStore } from "@core/store";
import { ActivityID, PartyActivity } from "./interfaces";

export class ActivityStore extends EntityStore<PartyActivity, ActivityID> { };
6 changes: 3 additions & 3 deletions packages/core/src/modules/battle/battle-activity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { mergeDeepWith, add } from 'ramda';
import { inject, injectable } from 'inversify';
import { PartyService, PartyID } from "../party";
import { IActivityHandler, Activity } from '../activity';
import { PartyService, PartyID } from "@modules/party";
import { IActivityHandler, Activity } from '@modules/activity';
import { BattleService } from './battle-service';
import { BattleID } from './interfaces';
import { calculateLoot } from './lib';
import { mergeDeepWith, add } from 'ramda';

export type BattleState = { battleId: BattleID };
export type BattleStartArgs = { partyId: PartyID, involvedPartyId: PartyID };
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/battle/battle-module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '../../models';
import { Module } from '@core/module';
import { BattleService } from "./battle-service";
import { BattleStore } from "./battle-store";
import { BattleActivity } from './battle-activity';
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/modules/battle/battle-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { injectable, inject } from 'inversify';
import { PartyService, PartyID } from '../party';
import { EffectService } from '../skill';
import { PartyService, PartyID } from '@modules/party';
import { EffectService } from '@modules/skill';
import { Battle } from './battle';
import { BattleID, BattleStoreState } from './interfaces';
import { BattleStore } from './battle-store';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/battle/battle-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { injectable } from 'inversify';
import { EntityStore } from '@core/store';
import { BattleStoreState, BattleID } from './interfaces';
import { EntityStore } from '../../lib/entity-store';

@injectable()
export class BattleStore extends EntityStore<BattleStoreState, BattleID> { }
10 changes: 5 additions & 5 deletions packages/core/src/modules/battle/battle.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { all, complement, prop, map, chain, concat, pipe, contains, forEach, mergeAll } from 'ramda';
import { isAlive, UnitID } from '../unit';
import { EffectService, isPartyEffect } from '../skill';
import { Effect } from '../../models';
import { Unit } from '../unit';

import { EffectService, isPartyEffect } from '@modules/skill';
import { Effect } from '@models/effect';
import { Unit, isAlive, UnitID } from '@modules/unit';
import { sample } from '@lib/sample';
import { BattleStats, BattleParty, BattleUnit, BattleState } from './interfaces';
import { calculateBattleStats } from './lib';
import { sample } from '../../lib/sample';

export class Battle {
private battleState: BattleState;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/modules/battle/interfaces/battle-party.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UnitID } from "../../unit/interfaces";
import { Effect } from '../../../models';
import { UnitID } from "@modules/unit";
import { Effect } from '@models/effect';

export interface BattleParty {
unitIds: UnitID[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Unit, UnitID } from '../../unit/interfaces';
import { Unit, UnitID } from '@modules/unit';
import { BattleParty } from './battle-party';

export interface BattleState {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PartyID } from "../../party/interfaces";
import { PartyID } from "@modules/party";
import { BattleID } from "./battle-id";

export type BattleStoreState = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/battle/interfaces/battle-unit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UnitID } from "../../unit/interfaces";
import { UnitID } from "@modules/unit";
import { BattleStats } from './battle-stats';

export interface BattleUnit {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/modules/battle/lib/apply-effect.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Effect } from '../../../models';
import { Effect } from '@models/effect';
import { BattleStats } from '../interfaces';
import { getEffectProperty } from './get-effect-property';

export function applyEffect(acc: BattleStats, effect: Effect): BattleStats {
let prop = getEffectProperty(effect);

if(!prop) return acc;
if (!prop) return acc;

if(effect.isPercentage){
if (effect.isPercentage) {
acc[prop] *= effect.value;
} else {
acc[prop] += effect.value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sortBy, prop, reduce } from 'ramda';
import { Effect } from '../../../models';
import { Effect } from '@models/effect';
import { BattleStats } from '../interfaces';
import { applyEffect } from './apply-effect';

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/modules/battle/lib/calculate-loot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Loot } from "../../../models";
import { Unit } from "../../unit";
import { Loot } from "@models/loot";
import { Unit } from "@modules/unit";
import { sum } from 'ramda';

export function calculateLoot(units: Unit[]): Loot {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Effect, unitEffectPropertyMap } from '../../../models';
import { Effect, unitEffectPropertyMap } from '@models/effect';
import { BattleStats } from '../interfaces';

export function getEffectProperty(effect: Effect): keyof BattleStats {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { injectable, inject } from 'inversify';
import { CommandSystem } from "../../../lib/command-system";
import { BlacksmithCommand, UpgradeItemCommandArgs } from './blacksmith-command';
import { EffectTarget, AttackEffectType, ItemID } from '../../../models';
import { append, evolve } from 'ramda';
import { UnitID, UnitService } from '../../unit';
import { getItem } from '../../../models/stash';
import { VillageStashService } from '../../village';

import { CommandSystem } from "@core/command";
import { EffectTarget, AttackEffectType } from '@models/effect';
import { ItemID } from '@models/item';
import { UnitID, UnitService } from '@modules/unit';
import { getItem } from '@models/stash';
import { VillageStashService } from '@modules/village';
import { BlacksmithCommand, UpgradeItemCommandArgs } from './blacksmith-command';

@injectable()
export class BlacksmithCommandHandler {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ItemID, Command } from '../../../models';
import { UnitID } from "../../unit";
import { Command } from '@core/command';
import { ItemID } from '@models/item';
import { UnitID } from "@modules/unit";

export enum BlacksmithCommand {
UpgradeItem = 'blacksmith/upgrade-item'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/buildings/buildings-module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from "../../models";
import { Module } from "@core/module";
import { BlacksmithCommandHandler } from "./blacksmith";

export const buildingsModule: Module = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/config/config-module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from "../../models";
import { Module } from "@core/module";

export const configModule: Module = {
provides: [{ provide: 'availableSkills', value: [] }]
Expand Down
Loading

0 comments on commit 97ce204

Please sign in to comment.