-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: initial commit for visibility listeners
- Loading branch information
1 parent
be905c8
commit 7426244
Showing
6 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { TabMasterManager } from "../../state/TabMasterManager"; | ||
import { SteamController } from "./SteamController"; | ||
|
||
|
||
export class VisibilityListenersController { | ||
private tabMasterManager: TabMasterManager; | ||
private steamController: SteamController; | ||
|
||
// The number of connected controllers, including the SteamDeck itself. | ||
private numberOfControllers = 1; | ||
private controllerListSub!: Unregisterer; | ||
|
||
/** | ||
* Creates a new VisibilityListenersController. | ||
* @param tabMasterManager The plugin's state manager. | ||
* @param steamController The plugin's SteamController. | ||
*/ | ||
constructor(tabMasterManager: TabMasterManager, steamController: SteamController) { | ||
this.tabMasterManager = tabMasterManager; | ||
this.steamController = steamController; | ||
|
||
this.initializeListeners(); | ||
} | ||
|
||
private initializeListeners() { | ||
// * Initialize player count listener. | ||
this.controllerListSub = this.registerForLocalPlayerCountChanges(this.controllerListCallback); | ||
|
||
|
||
// TODO: other listeners here. | ||
} | ||
|
||
private controllerListCallback(previousNumPlayers: number, currentNumPlayers: number): void { | ||
// * check if deck should be included, if so, decrease both by one | ||
// ! TabGroups should take priority. If the group is set to override visibility changes, only update tabs in that group, otherwise, check all. | ||
|
||
// * check visible tab group | ||
const visibleTabGroup = null; // hard coded value for default, will change once there is a way to get this info | ||
const tabs = this.tabMasterManager.getTabs(); | ||
let tabsToCheck = [...tabs.visibleTabsList, ...tabs.hiddenTabsList]; | ||
|
||
if (visibleTabGroup.overrideVisibilityChanges) { | ||
// TODO: set tabs to check to be the tabs in the tabGroup. | ||
} | ||
|
||
// * loop over tabs. | ||
for (const tab of tabsToCheck) { | ||
// TODO: tabs now need a property for visibility listeners | ||
} | ||
} | ||
|
||
/** | ||
* Registers a callback for local player count changes. | ||
* @param callback The callback to run when controllers change. | ||
* @returns A function to call to unregister the callback. | ||
*/ | ||
private registerForLocalPlayerCountChanges(callback: (previousNumPlayers: number, currentNumPlayers: number) => void): Unregisterer { | ||
return this.steamController.registerForControllerListChanges((controllers: ControllerInfo[]) => { | ||
if (controllers.length !== this.numberOfControllers) { | ||
const previousNumPlayers = this.numberOfControllers; | ||
this.numberOfControllers = controllers.length; | ||
|
||
callback(previousNumPlayers, this.numberOfControllers); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Function to run when cleaning up the plugin. | ||
*/ | ||
destroy(): void { | ||
if (this.controllerListSub) this.controllerListSub.unregister(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { IconType } from "react-icons/lib"; | ||
import { FaUserFriends } from "react-icons/fa"; | ||
|
||
export type VisibilityListenerType = 'local player count'; | ||
|
||
type LocalPlayerCountParams = { playerCount: number, includeSteamdeck: boolean } | ||
|
||
export type VisibilityListenerParams<T extends VisibilityListenerType> = | ||
T extends 'local player count' ? LocalPlayerCountParams : | ||
never; | ||
|
||
/** | ||
* Dictionary of default VisibilityListener params. | ||
*/ | ||
export const VisibilityListenerParamsDefaults: { [key in VisibilityListenerType]: VisibilityListenerParams<key> } = { | ||
"local player count": { playerCount: 2, includeSteamdeck: false } | ||
} | ||
|
||
/** | ||
* Dictionary of descriptions for each VisibilityListener. | ||
*/ | ||
export const VisibilityListenerDescriptions: { [visbilityListenerType in VisibilityListenerType]: string } = { | ||
"local player count": "Change tab visibility based on the number of local players." | ||
} | ||
|
||
/** | ||
* Dictionary of icons for each VisibilityListener. | ||
*/ | ||
export const VisibilityListenerIcons: { [visbilityListenerType in VisibilityListenerType]: IconType } = { | ||
"local player count": FaUserFriends, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Types for SteamClient.Input | ||
|
||
type Input = { | ||
/** | ||
* Registers a callback for changes in the list of active controllers. | ||
* @param callback The callback to run when controller list changes. | ||
* @returns A function to call to unregister the callback. | ||
*/ | ||
RegisterForControllerListChanges(callback: (controllerListChanges: ControllerInfo[]) => void): Unregisterer; | ||
} | ||
|
||
enum ControllerType { | ||
None = -1, | ||
Unknown = 0, | ||
UnknownSteamController = 1, | ||
SteamController = 2, // Codename Gordon | ||
SteamControllerV2 = 3, // Codename Headcrab | ||
SteamControllerNeptune = 4, // Steam Deck | ||
FrontPanelBoard = 20, | ||
Generic = 30, | ||
XBox360Controller = 31, | ||
XBoxOneController = 32, | ||
PS3Controller = 33, | ||
PS4Controller = 34, | ||
WiiController = 35, | ||
AppleController = 36, | ||
AndroidController = 37, | ||
SwitchProController = 38, | ||
SwitchJoyConLeft = 39, | ||
SwitchJoyConRight = 40, | ||
SwitchJoyConPair = 41, | ||
SwitchProGenericInputOnlyController = 42, | ||
MobileTouch = 43, | ||
SwitchProXInputSwitchController = 44, | ||
PS5Controller = 45, | ||
XboxEliteController = 46, | ||
LastController = 47, // Unverified | ||
PS5EdgeController = 48, | ||
GenericKeyboard = 400, | ||
GenericMouse = 800, | ||
} | ||
|
||
interface ControllerInfo { | ||
strName: string; | ||
eControllerType: ControllerType; | ||
nXInputIndex: number; | ||
nControllerIndex: number; | ||
eRumblePreference: number; // ControllerRumbleSetting | ||
bWireless: boolean; | ||
unUniqueID: number; | ||
unVendorID: number; | ||
unProductID: number; | ||
unCapabilities: number; | ||
strFirmwareBuildTime: string; | ||
strSerialNumber: string; | ||
strChipID: string; | ||
nLEDColorR: number; | ||
nLEDColorG: number; | ||
nLEDColorB: number; | ||
flLEDBrightness: number; | ||
flLEDSaturation: number; | ||
nTurnOnSound: number; | ||
nTurnOffSound: number; | ||
nLStickDeadzone: number; | ||
nRStickDeadzone: number; | ||
nLHapticStrength: number; | ||
nRHapticStrength: number; | ||
flLPadPressureCurve: number; | ||
flRPadPressureCurve: number; | ||
bHaptics: boolean; | ||
bSWAntiDrift: boolean; | ||
flGyroStationaryTolerance: number; | ||
flAccelerometerStationaryTolerance: number; | ||
bRemoteDevice: boolean; | ||
bNintendoLayout: boolean; | ||
bUseReversedLayout: boolean; | ||
ActiveAccount: ActiveAccount | undefined; | ||
vecAltAccounts: any[]; // The type for this property might need to be more specific based on the actual data structure | ||
} |