Skip to content

Commit

Permalink
transaction visuals resource param
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonBurke committed Feb 13, 2024
1 parent 670bd07 commit f65301f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/international/flags/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ export class FlagManager {

private incomingTransactions(flagName: string, flagNameParts: string[]) {
const flag = Game.flags[flagName]
const roomName = flagNameParts[1] || flag.pos.roomName
const roomName = flag.pos.roomName
const room = Game.rooms[roomName]
if (!room) {
flag.setColor(COLOR_RED)
return
}

const resourceType = flagNameParts[1] as ResourceConstant | undefined

flag.setColor(COLOR_GREEN)

const headers = ['sender', '', 'receiver', 'resource', 'amount', 'ticks since']
Expand All @@ -68,6 +70,10 @@ export class FlagManager {
const roomFromMemory = Memory.rooms[transaction.from] || ({} as RoomMemory)
const roomToMemory = Memory.rooms[transaction.to] || ({} as RoomMemory)

if (resourceType !== undefined && transaction.resourceType !== resourceType) {
continue
}

data.push([
transaction.from +
' (' +
Expand Down Expand Up @@ -118,13 +124,15 @@ export class FlagManager {

private outgoingTransactions(flagName: string, flagNameParts: string[]) {
const flag = Game.flags[flagName]
const roomName = flagNameParts[1] || flag.pos.roomName
const roomName = flag.pos.roomName
const room = Game.rooms[roomName]
if (!room) {
flag.setColor(COLOR_RED)
return
}

const resourceType = flagNameParts[1] as ResourceConstant | undefined

flag.setColor(COLOR_GREEN)

const headers = ['sender', '', 'receiver', 'resource', 'amount', 'ticks since']
Expand All @@ -135,6 +143,10 @@ export class FlagManager {
const roomFromMemory = Memory.rooms[transaction.from] || ({} as RoomMemory)
const roomToMemory = Memory.rooms[transaction.to] || ({} as RoomMemory)

if (resourceType !== undefined && transaction.resourceType !== resourceType) {
continue
}

data.push([
transaction.from +
' (' +
Expand Down
20 changes: 9 additions & 11 deletions src/room/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export class RoomManager {
const sourcePaths: RoomPosition[][] = []

for (let i = 0; i < packedRemoteSourceHarvestPositions.length; i += 1) {

const positions = packedRemoteSourceHarvestPositions[i]
const origin = unpackPosAt(positions, 0)

Expand Down Expand Up @@ -264,7 +263,6 @@ export class RoomManager {
const sourcePaths: RoomPosition[][] = []

for (let i = 0; i < packedRemoteSourceHarvestPositions.length; i += 1) {

const positions = packedRemoteSourceHarvestPositions[i]
const origin = unpackPosAt(positions, 0)

Expand Down Expand Up @@ -468,20 +466,20 @@ export class RoomManager {
if (this._remoteSources) return this._remoteSources

const sourceIDs = this.room.memory[RoomMemoryKeys.remoteSources]
if (sourceIDs) {
this._remoteSources = []
if (!sourceIDs) {
throw Error('No remote sources ' + this.room.name)
}

for (let i = 0; i < sourceIDs.length; i++) {
const source = findObjectWithID(sourceIDs[i])
this._remoteSources = []

source.remoteIndex = i
this._remoteSources.push(source)
}
for (let i = 0; i < sourceIDs.length; i++) {
const source = findObjectWithID(sourceIDs[i])

return this._remoteSources
source.remoteIndex = i
this._remoteSources.push(source)
}

throw Error('No remote sources ' + this.room.name)
return this._remoteSources
}

_sourceHarvestPositions: RoomPosition[][]
Expand Down

0 comments on commit f65301f

Please sign in to comment.