Skip to content

Commit

Permalink
Merge pull request #63 from kongsgaard/poe-zone-tracker-service
Browse files Browse the repository at this point in the history
Poe zone tracker service
  • Loading branch information
zach-herridge committed Dec 7, 2023
2 parents b4bcc45 + 99ea689 commit 77976f3
Show file tree
Hide file tree
Showing 14 changed files with 4,383 additions and 111 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ sage-secrets.yml
# Autogenerated files
src/echo-app/src/renderer/src/dev-plugins.ts

# Folder for tmp test data
src/echo-common/test/data/tmp/

*.DS_STORE
# CDK asset staging directory
*.cdk.staging
Expand Down
2 changes: 2 additions & 0 deletions src/echo-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/echo-app/src/renderer/src/echo-context-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PoeAccountService,
PoeCharacterService,
PoeClientLogService,
PoeZoneTrackerService,
PoeStashService,
SageValuationService
} from 'echo-common'
Expand All @@ -23,6 +24,7 @@ const POE_CLIENT_LOG_SERVICE = new PoeClientLogService()
const SAGE_VALUATION_SERVICE = new SageValuationService(ECHO_DIR, new ItemGroupingService())
const POE_STASH_SERVICE = new PoeStashService(ECHO_DIR, GGG_API, SAGE_VALUATION_SERVICE)
const POE_CHARCTERS_SERVICE = new PoeCharacterService(ECHO_DIR, GGG_API)
const POE_ZONE_TRACKER_SERVICE = new PoeZoneTrackerService(POE_CLIENT_LOG_SERVICE)

export function buildContext(contextSource: string): EchoContext {
return {
Expand All @@ -32,6 +34,7 @@ export function buildContext(contextSource: string): EchoContext {
plugins: ECHO_PLUGIN_SERVICE,
poeAccounts: POE_ACCOUNT_SERVICE,
poeClientLog: POE_CLIENT_LOG_SERVICE,
poeZoneTracker: POE_ZONE_TRACKER_SERVICE,
poeStash: POE_STASH_SERVICE,
poeValuations: SAGE_VALUATION_SERVICE,
poeCharacters: POE_CHARCTERS_SERVICE,
Expand Down
36 changes: 35 additions & 1 deletion src/echo-common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions src/echo-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
"require": "./src/index.ts"
},
"default": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts"
"import": "./dist/esm/src/index.js",
"require": "./dist/cjs/src/index.js",
"types": "./dist/cjs/src/index.d.ts"
}
},
"./components-v1": {
"development": {
"import": "./src/ui/components/v1/index.ts",
"require": "./src/ui/components/v1/index.ts",
"types": "./dist/ui/components/v1/index.d.ts"
"types": "./dist/cjs/src/ui/components/v1/index.d.ts"
},
"default": {
"import": "./dist/esm/ui/components/v1/index.js",
"require": "./dist/cjs/ui/components/v1/index.js",
"types": "./dist/ui/components/v1/index.d.ts"
"import": "./dist/esm/src/ui/components/v1/index.js",
"require": "./dist/cjs/src/ui/components/v1/index.js",
"types": "./dist/cjs/src/ui/components/v1/index.d.ts"
}
}
},
"main": "./dist/cjs/index.ts",
"main": "./dist/cjs/src/index.ts",
"files": [
"dist/",
"*.d.ts"
Expand All @@ -38,14 +38,17 @@
"jest-test": "npm run build && jest --detectOpenHandles ./test/*",
"lint": "eslint ./src --fix --resolve-plugins-relative-to ../sage-ts-tooling",
"prepublishOnly": "npm run build",
"test": "npm run build && node dist/cjs/poe-api-test.js"
"test": "npm run build && node dist/src/cjs/poe-api-test.js"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@jest/types": "^29.6.3",
"@types/jest": "^29.5.10",
"@types/node": "^20.9.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@types/tail": "^2.2.3",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.10.0",
"eslint": "^8.53.0",
Expand All @@ -57,7 +60,8 @@
"mock-fs": "^5.2.0",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"uuid": "^9.0.1"
},
"peerDependencies": {
"@heroicons/react": "^2.0.18",
Expand All @@ -83,6 +87,7 @@
"@radix-ui/react-tooltip": "^1.0.7",
"@react-rxjs/core": "^0.10.7",
"@react-rxjs/utils": "^0.9.7",
"@types/jest": "^29.5.10",
"@types/mock-fs": "^4.13.4",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/echo-common/src/echo-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PoeAccountService } from './poe-account-service'
import { PoeCharacterService } from './poe-character-service'
import { PoeClientLogService } from './poe-client-log-service'
import { PoeStashService } from './poe-stash-service'
import { PoeZoneTrackerService } from './poe-zone-tracker-service'
import { SageValuationService } from './sage-valuation-service'

export type EchoContext = {
Expand All @@ -17,6 +18,7 @@ export type EchoContext = {
poeCharacters: PoeCharacterService
poeClientLog: PoeClientLogService
poeStash: PoeStashService
poeZoneTracker: PoeZoneTrackerService
poeValuations: SageValuationService
subscriptions: Subscription[]
}
2 changes: 2 additions & 0 deletions src/echo-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PoeAccountService } from './poe-account-service'
import { PoeCharacterService } from './poe-character-service'
import { EchoPoeItem, PoeStashService } from './poe-stash-service'
import { PoeClientLogService, PoeZoneEntranceEvent } from './poe-client-log-service'
import { PoeZoneTrackerService } from './poe-zone-tracker-service'
import { EchoPluginConfigs, EchoPluginConfig } from './echo-plugin-config'
import { EchoDirService } from './echo-dir-service'
import { EchoContext } from './echo-context'
Expand All @@ -23,6 +24,7 @@ export {
PoeAccountService,
PoeCharacterService,
PoeClientLogService,
PoeZoneTrackerService,
EchoRouter,
EchoDirService,
validResults,
Expand Down
53 changes: 42 additions & 11 deletions src/echo-common/src/poe-client-log-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ export type PoeInstanceConnectionEvent = PoeClientLogTextEvent & {
server: string
}

export type PoeGeneratingAreaEvent = PoeClientLogTextEvent & {
type: 'GeneratingAreaEvent'
areaLevel: number
areaTag: string
seed: number
}

export type PoeNPCEventSubtype =
| 'EinharEncounterEvent'
| 'AlvaEncounterEvent'
| 'NikoEncounterEvent'
| 'CassiaEncounterEvent'
| 'JunEncounterEvent'
| 'DeleriumMirrorEvent'
| 'DeliriumMirrorEvent'
| 'HarvestEncounterEvent'
| 'ExpeditionTujenEncounterEvent'
| 'ExpeditionRogEncounterEvent'
Expand All @@ -51,6 +58,7 @@ export type PoeClientLogEvent =
| PoeInstanceConnectionEvent
| PoeNPCEncounterEvent
| PoeCharacterSlainEvent
| PoeGeneratingAreaEvent

interface PoeClientLogEventParser {
parse(raw: string): PoeClientLogEvent | undefined
Expand All @@ -59,12 +67,13 @@ interface PoeClientLogEventParser {
class ZoneEnteranceEventParser implements PoeClientLogEventParser {
parse(raw: string): PoeZoneEntranceEvent | undefined {
if (raw.includes('] : You have entered')) {
const split = raw.split(' ')
return {
type: 'ZoneEntranceEvent',
systemUptime: Number(raw.split(' ')[2]),
systemUptime: Number(split[2]),
raw: raw,
location: raw.slice(raw.indexOf('entered ') + 'entered '.length, -1),
time: new Date()
time: new Date(split[0] + ' ' + split[1])
}
}
return undefined
Expand All @@ -74,12 +83,31 @@ class ZoneEnteranceEventParser implements PoeClientLogEventParser {
class InstanceConnectionEventParser implements PoeClientLogEventParser {
parse(raw: string): PoeInstanceConnectionEvent | undefined {
if (raw.includes('] Connecting to instance server at')) {
const split = raw.split(' ')
return {
type: 'InstanceConnectionEvent',
raw: raw,
systemUptime: Number(raw.split(' ')[2]),
systemUptime: Number(split[2]),
server: raw.slice(raw.indexOf('at ') + 'at '.length, raw.length),
time: new Date()
time: new Date(split[0] + ' ' + split[1])
}
}
return undefined
}
}

class GeneratingAreaEventParser implements PoeClientLogEventParser {
parse(raw: string): PoeGeneratingAreaEvent | undefined {
if (raw.includes('] Generating level')) {
const split = raw.split(' ')
return {
type: 'GeneratingAreaEvent',
raw: raw,
systemUptime: Number(split[2]),
time: new Date(split[0] + ' ' + split[1]),
areaLevel: Number(split[9]),
areaTag: split[11].replaceAll('"', ''),
seed: Number(split[14])
}
}
return undefined
Expand All @@ -97,7 +125,7 @@ const NPCEncounterMap = new Map<string, PoeNPCEventSubtype>([

['] Sister Cassia:', 'CassiaEncounterEvent'],

['] Strange Voice:', 'DeleriumMirrorEvent'],
['] Strange Voice:', 'DeliriumMirrorEvent'],

['] Oshabi:', 'HarvestEncounterEvent'],

Expand All @@ -111,12 +139,13 @@ class NPCEncounterEventParser implements PoeClientLogEventParser {
parse(raw: string): PoeNPCEncounterEvent | undefined {
for (const [key, value] of NPCEncounterMap) {
if (raw.includes(key)) {
const split = raw.split(' ')
return {
type: 'NPCEncounterEvent',
subtype: value,
raw: raw,
systemUptime: Number(raw.split(' ')[2]),
time: new Date()
systemUptime: Number(split[2]),
time: new Date(split[0] + ' ' + split[1])
}
}
}
Expand All @@ -133,13 +162,14 @@ class CharacterSlainEventParser implements PoeClientLogEventParser {
const character = match == null ? null : match[1]

if (character) {
const split = raw.split(' ')
return {
type: 'CharacterSlainEvent',
raw: raw,
character: character,
isMyCharacter: false, // character === settingsService.currentCharacter ? true : false,
systemUptime: Number(raw.split(' ')[2]),
time: new Date()
systemUptime: Number(split[2]),
time: new Date(split[0] + ' ' + split[1])
}
} else if (raw.includes(' has been slain.')) {
console.debug('Something probably went wrong, should check that out!')
Expand All @@ -161,7 +191,8 @@ export class PoeClientLogService {
new ZoneEnteranceEventParser(),
new InstanceConnectionEventParser(),
new NPCEncounterEventParser(),
new CharacterSlainEventParser()
new CharacterSlainEventParser(),
new GeneratingAreaEventParser()
]

constructor(tail: Tail | null = null) {
Expand Down
Loading

0 comments on commit 77976f3

Please sign in to comment.