Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferences System #1007

Merged
merged 18 commits into from
Jul 15, 2024
Merged

Preferences System #1007

merged 18 commits into from
Jul 15, 2024

Conversation

LucaHaverty
Copy link
Contributor

@LucaHaverty LucaHaverty commented Jul 1, 2024

Description

A system to save and load player preferences including settings from the settings modal, robot controls, robot game piece manipulation configuration, field scoring zone data, and color themes. There are default preferences that will be used if a preference is not yet configured by the user.

Objectives

  • System for getting/settings preferences, including default preferences
  • Ability to save and load preferences to local storage
  • Integrate with the settings modal
  • Integrate with the robot controls modal
  • Saving and loading of robot specific preferences
  • Saving and loading of field specific preferences

Note

The goal of this PR is to build a system to load, modify, and save preferences, not to make the preferences themselves have an effect on gameplay. While you should be able to change like zoom sensitivity for example, it won't yet affect the actual camera movement. The only preferences that should fully work are robot controls and color themes.

Preferences List (all checked off have been implemented AND TESTED)

  • Global

    • Screen mode
    • Quality
    • Zoom sensitivity
    • Pitch sensitivity
    • Yaw sensitivity
    • Report analytics
    • Use metric
    • Render scoring zones
  • Robot Specific

    • Control scheme
    • Intake transform
    • Ejector transform and velocity
  • Field Specific

    • Scoring zones (location, alliance, points, destroy GP, persistent, parent obj)
    • Default robot spawn location

Testing Done

  • All controls that are checked off have been tested

How to add a global preference

  1. Add it to type GlobalPreference in PreferencesTypes.ts
export type GlobalPreference =
    | "ScreenMode"
    ...
    | "MyPreference"
  1. Assign it a default value in PreferenceTypes.ts
 export const DefaultGlobalPreferences: { [key: string]: Object } = {
    "ScreenMode": "Windowed",
    ...
    "MyPreference":  0.5,
}
  1. From anywhere, set the value by calling

PreferencesSystem.setGlobalPreference<number>("MyPreference", 2)

  1. From anywhere, get the value by calling. This is guaranteed to return a value, and will return the default value if it has not yet been assigned

PreferencesSystem.getGlobalPreference<number>("MyPreference")

Warning

Merge after #986

JIRA Issue

@LucaHaverty LucaHaverty self-assigned this Jul 1, 2024
@LucaHaverty LucaHaverty marked this pull request as ready for review July 8, 2024 17:07
@LucaHaverty LucaHaverty requested review from HunterBarclay and a team as code owners July 8, 2024 17:07
@LucaHaverty LucaHaverty requested review from PepperLola and removed request for a team July 8, 2024 17:07
@LucaHaverty
Copy link
Contributor Author

Access events from elsewhere by calling
PreferencesSystem.addEventListener((e) => { /* functionality here */ })

@LucaHaverty LucaHaverty requested a review from HunterBarclay July 8, 2024 22:36
@LucaHaverty LucaHaverty mentioned this pull request Jul 9, 2024
3 tasks
Copy link
Member

@HunterBarclay HunterBarclay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will definitely be shaped as it gets used more and more, but good for now

public constructor(mechanism: Mechanism, assemblyName: string) {
super(mechanism);
// Tracks the number of each specific mira file spawned
public static numberRobotsSpawned: { [key: string]: number } = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this and robotsSpawned be combined? Maybe a map from key to list of spawned robots? That might be a bit slower if we're iterating over robotsSpawned a lot but it would also mean the information would only be stored in one place and we don't have to maintain two separate places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An issue I see with this is if you spawn two robots for example 'mean machine [0]' and 'mean machine [1]', then remove only 'mean machine [0]', it needs to know that the robot still around is index 1 not 0. I can't think of an easy way around this, but let me know if you do.

@LucaHaverty LucaHaverty requested a review from a team as a code owner July 10, 2024 16:25
@LucaHaverty LucaHaverty requested review from a-crowell and Dhruv-0-Arora and removed request for a team July 10, 2024 16:25
@LucaHaverty LucaHaverty requested a review from PepperLola July 15, 2024 03:37
Copy link
Member

@BrandonPacewic BrandonPacewic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it. Nice work!

@HunterBarclay HunterBarclay merged commit 2441ae4 into dev Jul 15, 2024
12 checks passed
@HunterBarclay HunterBarclay deleted the haverty/1692/preferences branch July 15, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants