Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
- Avoid NERP runner log spam
- Improve null safety
- Replace dedicated cancel build event with go back button clicked
- Replace alias event remove selection with actual deselect all event
  • Loading branch information
Scarabol committed Jan 14, 2025
1 parent df09402 commit 94e5e0a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 46 deletions.
2 changes: 0 additions & 2 deletions src/event/EventKeyEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export enum EventKey {
COMMAND_TOOLTIP_CHANGE = 'command-tooltip-change',
COMMAND_TOOLTIP_HIDE = 'command-tooltip-hide',
COMMAND_PLAY_SOUND = 'command-play-sound',
COMMAND_REMOVE_SELECTION = 'command-remove-selection',
COMMAND_CREATE_POWER_PATH = 'command-create-power-path',
COMMAND_PLACE_FENCE = 'command-place-fence',
COMMAND_FENCE_BEAMUP = 'command-fence-beamup',
Expand All @@ -52,7 +51,6 @@ export enum EventKey {
COMMAND_TRAIN_RAIDER = 'command-train-raider',
COMMAND_RAIDER_DROP = 'command-raider-drop',
COMMAND_SELECT_BUILD_MODE = 'command-select-build-mode',
COMMAND_CANCEL_BUILD_MODE = 'command-cancel-build-mode',
COMMAND_CANCEL_CONSTRUCTION = 'command-cancel-construction',
COMMAND_VEHICLE_GET_MAN = 'command-vehicle-get-man',
COMMAND_VEHICLE_BEAMUP = 'command-vehicle-beamup',
Expand Down
4 changes: 1 addition & 3 deletions src/event/EventTypeMap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AdvanceAfterRewardsEvent, BuildingsChangedEvent, DeselectAll, FollowerSetCanvasEvent, FollowerSetLookAtEvent, GuiButtonBlinkEvent, GuiButtonClicked, InitRadarMap, RaidersAmountChangedEvent, RaiderTrainingCompleteEvent, SelectionChanged, SelectionFrameChangeEvent, SetSpaceToContinueEvent, ShowGameResultEvent, ShowMissionAdvisorEvent, ShowMissionBriefingEvent, ShowOptionsEvent, UpdateRadarEntityEvent, UpdateRadarSurface, UpdateRadarTerrain, VehicleUpgradeCompleteEvent } from './LocalEvents'
import { AirLevelChanged, CavernDiscovered, DynamiteExplosionEvent, GameResultEvent, JobCreateEvent, LevelSelectedEvent, MaterialAmountChanged, MonsterEmergeEvent, MonsterLaserHitEvent, NerpMessageEvent, NerpSuppressArrowEvent, OreFoundEvent, RequestedRaidersChanged, RequestedVehiclesChanged, RestartGameEvent, ShootLaserEvent, ToggleAlarmEvent, UpdatePriorities, UsedCrystalsChanged } from './WorldEvents'
import { CameraControl, CancelBuilding, CancelBuildMode, CancelSurfaceJobs, ChangeBuildingPowerState, ChangeCameraEvent, ChangeCursor, ChangePreferences, ChangeTooltip, CreateClearRubbleJob, CreateDrillJob, CreateDynamiteJob, CreatePowerPath, CreateReinforceJob, DropBirdScarer, HideTooltip, MakeRubble, PickTool, PlaceFence, PlaySoundEvent, RaiderBeamUp, RaiderDrop, RaiderEat, RaiderUpgrade, RemoveSelection, RepairBuilding, RepairLava, SelectBuildMode, TrainRaider, UpgradeBuilding, UpgradeVehicle, VehicleBeamUp, VehicleCallMan, VehicleDriverGetOut, VehicleLoad, VehicleUnload } from './GuiCommand'
import { CameraControl, CancelBuilding, CancelSurfaceJobs, ChangeBuildingPowerState, ChangeCameraEvent, ChangeCursor, ChangePreferences, ChangeTooltip, CreateClearRubbleJob, CreateDrillJob, CreateDynamiteJob, CreatePowerPath, CreateReinforceJob, DropBirdScarer, HideTooltip, MakeRubble, PickTool, PlaceFence, PlaySoundEvent, RaiderBeamUp, RaiderDrop, RaiderEat, RaiderUpgrade, RepairBuilding, RepairLava, SelectBuildMode, TrainRaider, UpgradeBuilding, UpgradeVehicle, VehicleBeamUp, VehicleCallMan, VehicleDriverGetOut, VehicleLoad, VehicleUnload } from './GuiCommand'
import { CrystalFoundEvent, GenericDeathEvent, GenericMonsterEvent, LandslideEvent, PowerDrainEvent, RaiderDiscoveredEvent, SlugEmergeEvent, UnderAttackEvent, WorldLocationEvent } from './WorldLocationEvent'

export class BaseEvent {
Expand Down Expand Up @@ -37,7 +37,6 @@ export interface DefaultEventMap {
'command-tooltip-change': ChangeTooltip
'command-tooltip-hide': HideTooltip
'command-play-sound': PlaySoundEvent
'command-remove-selection': RemoveSelection
'command-create-power-path': CreatePowerPath
'command-place-fence': PlaceFence
'command-fence-beamup': BaseEvent
Expand All @@ -57,7 +56,6 @@ export interface DefaultEventMap {
'command-train-raider': TrainRaider
'command-raider-drop': RaiderDrop
'command-select-build-mode': SelectBuildMode
'command-cancel-build-mode': CancelBuildMode
'command-cancel-construction': CancelBuilding
'command-vehicle-get-man': VehicleCallMan
'command-vehicle-beamup': VehicleBeamUp
Expand Down
12 changes: 0 additions & 12 deletions src/event/GuiCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ export class PlaySoundEvent extends BaseEvent {
}
}

export class RemoveSelection extends BaseEvent {
constructor() {
super(EventKey.COMMAND_REMOVE_SELECTION)
}
}

export class CancelBuildMode extends BaseEvent {
constructor() {
super(EventKey.COMMAND_CANCEL_BUILD_MODE)
}
}

export class SelectBuildMode extends BaseEvent {
entityType: EntityType

Expand Down
13 changes: 9 additions & 4 deletions src/game/GuiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class GuiManager {
EventBroker.subscribe(EventKey.COMMAND_SELECT_BUILD_MODE, (event: SelectBuildMode) => {
sceneMgr.setBuildModeSelection(event.entityType)
})
EventBroker.subscribe(EventKey.COMMAND_CANCEL_BUILD_MODE, () => {
EventBroker.subscribe(EventKey.GUI_GO_BACK_BUTTON_CLICKED, () => {
sceneMgr.setBuildModeSelection(undefined)
})
EventBroker.subscribe(EventKey.COMMAND_CANCEL_CONSTRUCTION, () => {
Expand Down Expand Up @@ -200,9 +200,6 @@ export class GuiManager {
EventBroker.subscribe(EventKey.COMMAND_PLAY_SOUND, (event: PlaySoundEvent) => {
SoundManager.playSound(event.sample, event.isVoice)
})
EventBroker.subscribe(EventKey.COMMAND_REMOVE_SELECTION, () => {
EventBroker.publish(new DeselectAll())
})
EventBroker.subscribe(EventKey.COMMAND_CHANGE_PREFERENCES, () => {
SaveGameManager.savePreferences()
SoundManager.setupSfxAudioTarget()
Expand Down Expand Up @@ -250,9 +247,17 @@ export class GuiManager {
if (event.viewMode === CameraViewMode.BIRD) {
worldMgr.sceneMgr.setActiveCamera(worldMgr.sceneMgr.cameraBird)
} else if (event.viewMode === CameraViewMode.FPV) {
if (!entity.sceneEntity.camFPVJoint) {
console.warn('Entity does not have FPV joint')
return
}
entity.sceneEntity.camFPVJoint.add(worldMgr.sceneMgr.cameraFPV)
worldMgr.sceneMgr.setActiveCamera(worldMgr.sceneMgr.cameraFPV)
} else if (event.viewMode === CameraViewMode.SHOULDER) {
if (!entity.sceneEntity.camShoulderJoint) {
console.warn('Entity does not have shoulder joint')
return
}
entity.sceneEntity.camShoulderJoint.add(worldMgr.sceneMgr.cameraShoulder)
worldMgr.sceneMgr.setActiveCamera(worldMgr.sceneMgr.cameraShoulder)
}
Expand Down
9 changes: 9 additions & 0 deletions src/game/Supervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ import { EventBroker } from '../event/EventBroker'
import { GameState } from './model/GameState'
import { SurfaceType } from './terrain/SurfaceType'

/**
* Tutorial01
* - Raider should pick up shovel to clear rubble, but not automatically start clearing it
* - Once job assigned by player, raider should continue and clear rubble
* Tutorial02
* - Raider should start drilling when drill job created
* Tutorial03
* - Raider should pick shovel and start clearing rubble
*/
export class Supervisor {
jobs: Job[] = []
priorityIndexList: PriorityIdentifier[] = []
Expand Down
10 changes: 1 addition & 9 deletions src/gui/main/BuildingPanel.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { CancelBuildMode, SelectBuildMode } from '../../event/GuiCommand'
import { SelectBuildMode } from '../../event/GuiCommand'
import { EntityType } from '../../game/model/EntityType'
import { Panel } from '../base/Panel'
import { IconSubPanel } from './IconSubPanel'
import { GameConfig } from '../../cfg/GameConfig'
import { EventBroker } from '../../event/EventBroker'
import { GuiButtonClicked } from '../../event/LocalEvents'
import { EventKey } from '../../event/EventKeyEnum'

export class BuildingPanel extends IconSubPanel {
constructor(onBackPanel: Panel) {
super(10, onBackPanel)
this.backBtn.onClick = () => {
this.publishEvent(new CancelBuildMode())
this.toggleState(() => onBackPanel.toggleState())
EventBroker.publish(new GuiButtonClicked(EventKey.GUI_GO_BACK_BUTTON_CLICKED))
}
this.addBuildMenuItem(EntityType.TOOLSTATION)
this.addBuildMenuItem(EntityType.TELEPORT_PAD)
this.addBuildMenuItem(EntityType.DOCKS)
Expand Down
5 changes: 2 additions & 3 deletions src/gui/main/select/SelectBasePanel.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { RemoveSelection } from '../../../event/GuiCommand'
import { Panel } from '../../base/Panel'
import { IconSubPanel } from '../IconSubPanel'
import { EventBroker } from '../../../event/EventBroker'
import { GuiButtonClicked } from '../../../event/LocalEvents'
import { DeselectAll, GuiButtonClicked } from '../../../event/LocalEvents'
import { EventKey } from '../../../event/EventKeyEnum'

export class SelectBasePanel extends IconSubPanel {
constructor(numOfItems: number, onBackPanel: Panel) {
super(numOfItems, onBackPanel)
this.backBtn.onClick = () => {
this.publishEvent(new RemoveSelection())
this.publishEvent(new DeselectAll())
EventBroker.publish(new GuiButtonClicked(EventKey.GUI_GO_BACK_BUTTON_CLICKED))
}
}
Expand Down
17 changes: 4 additions & 13 deletions src/nerp/NerpRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,12 @@ export class NerpRunner {
// 0 = 0x00 allow any click anywhere anytime
// 3 = 0x11 disallow invalid clicks
// 4095 = 0x111111111111 set all flags? (seen in Tutorial01 level)
if (value !== 0) { // holds for all known levels
if (value === 4095) {
// TODO Only used in tutorials
console.warn('NERP function "setTutorialFlags" not yet implemented', value)
} else {
} else if (value === 0) {
// TODO Reset all flags?
} else {
console.warn('NERP function "setTutorialFlags" not yet implemented', value)
}
}

Expand Down Expand Up @@ -527,18 +528,8 @@ export class NerpRunner {
EventBroker.publish(new MaterialAmountChanged())
}

/**
* Tutorial01
* - Raider should pick up shovel to clear rubble, but not automatically start clearing it
* - Once job assigned by player, raider should continue and clear rubble
* Tutorial02
* - Raider should start drilling when drill job created
* Tutorial03
* - Raider should pick shovel and start clearing rubble
*/
disallowAll() {
// TODO Only used in tutorials
console.warn('Disallow allow not yet implemented')
}

getPoweredPowerStationsBuilt() {
Expand Down

0 comments on commit 94e5e0a

Please sign in to comment.