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

[Refactor] Create global scene variable #4766

Open
wants to merge 19 commits into
base: beta
Choose a base branch
from

Conversation

DayKev
Copy link
Collaborator

@DayKev DayKev commented Oct 31, 2024

What are the changes the user will see?

N/A

Why am I making these changes?

Currently to access the active scene you need to awkwardly pass it around thorough various functions/etc, and if it's not already being passed to the context you're working in you have to refactor the function/etc to add a scene passaround parameter/whatever and then potentially update every instance of it throughout the code.

What are the changes from a developer perspective?

All the random scene function params, class fields, etc are obliterated removed and replaced with a single global scene variable.

How to test the changes?

Play the game, run the tests.

Checklist

  • I'm using beta as my base branch
  • There is no overlap with another PR?
  • The PR is self-contained and cannot be split into smaller PRs?
  • Have I provided a clear explanation of the changes?
  • [ ] Have I considered writing automated tests for the issue?
  • [ ] If I have text, did I make it translatable and add a key in the English locale file(s)?
  • Have I tested the changes (manually)?
    • Are all unit tests still passing? (npm run test)
  • [ ] Are the changes visual?
    • [ ] Have I provided screenshots/videos of the changes?

@DayKev DayKev added Help Wanted Extra attention is needed Refactor Rewriting existing code related labels Oct 31, 2024
@DayKev DayKev requested a review from a team as a code owner October 31, 2024 13:57
Copy link
Collaborator

@MokaStitcher MokaStitcher left a comment

Choose a reason for hiding this comment

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

Found the sound issue I think (see comment in evolution phase)
Haven't checked anything else yet. Did the ME tests pass because you skipped the ones that were failing for now?

src/phases/evolution-phase.ts Outdated Show resolved Hide resolved
src/phases/evolution-phase.ts Outdated Show resolved Hide resolved
src/phases/egg-hatch-phase.ts Outdated Show resolved Hide resolved
src/field/pokemon.ts Outdated Show resolved Hide resolved
src/field/pokemon.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@torranx torranx left a comment

Choose a reason for hiding this comment

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

Can you please update the "Why" section on the ff:

  • why can you say its easier development?
  • what does this solve?
  • why is this the approach we made (ie global variable vs using something from phaser's SceneManager (I'm not too knowledgeable on phaser but I've seen some scene getters on docs)?

I agree that it's🍝 to slap the BattleScene on everything but I just wanna understand this change doesn't turn out to be the same.

src/battle.ts Outdated Show resolved Hide resolved
@DayKev
Copy link
Collaborator Author

DayKev commented Nov 1, 2024

I sure love how impossible it is to batch apply suggestions to a large PR, thanks GitHub.

@DayKev
Copy link
Collaborator Author

DayKev commented Nov 1, 2024

Can you please update the "Why" section on the ff:

Yeah, I just wanted to get the PR up before sleeping so I could get some feedback (esp on the sound issue).

  • why can you say its easier development?
  • what does this solve?

Currently to access the scene you need to awkwardly pass it around thorough various functions/etc, and if it's not already being passed to the context you're working in you have to refactor the function/etc to add a scene passaround parameter/whatever and then potentially update every instance of it throughout the code.

  • why is this the approach we made (ie global variable vs using something from phaser's SceneManager (I'm not too knowledgeable on phaser but I've seen some scene getters on docs)?

I agree that it's🍝 to slap the BattleScene on everything but I just wanna understand this change doesn't turn out to be the same.

I'm not too familiar with Phaser's tool(s) that we have access to for this, and their documentation permalinks are broken when using Google as I've just realized when trying to look it up. If you know of a better way that'd be great. I went with what seemed like the simplest method.

@DayKev
Copy link
Collaborator Author

DayKev commented Nov 1, 2024

Found the sound issue I think (see comment in evolution phase) Haven't checked anything else yet. Did the ME tests pass because you skipped the ones that were failing for now?

Yeah I disabled them (for now) and marked them with // TODO: .... There was an issue that broke a bunch of tests (since a lot of ME tests are very similar), plus a strange intermittent(?) issue with the SelectModifierPhase tests and an issue I don't understand in the "bug superfan" ME test.

General ME tests issue: 55d1b14#diff-b25c954eb59b69c9bdf7245abdfcb9428f37a4d2b7c68bcf2177aab1810889d8R129

SMP issue: 55d1b14#diff-6dcfc99d6f0b54ca275b4778e9f553ec1ae6cbee7698442de4731ef524409df2R16

"bug superfan" ME issue: 55d1b14#diff-dfe138746b004afe72d3f75d913fc5a5c84a9d52879f12a11afb1200c4efd3d9R386

I tested the ME issues in-game and everything worked fine, so it's a test-specific issue, I'm just not sure what's going on.

Copy link
Collaborator

@MokaStitcher MokaStitcher left a comment

Choose a reason for hiding this comment

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

Stopping for now, but this should fix the bug superfan encounter issue at least (explanation in second comment bc I keep forgetting github doesn't organize them by line)

@DayKev
Copy link
Collaborator Author

DayKev commented Nov 11, 2024

New issue discovered: async bullshit!

broken stuff

image
image

broken.i18n.mp4
not all the stuff is broken though!

image

Some of the i18n just randomly doesn't load at the right time.

@PigeonBar
Copy link
Contributor

PigeonBar commented Nov 14, 2024

Take this with several grains of salt, but:

  1. The async malfunctioning seems to be caused by stuff being imported too early. Everything importing globalScene seems to cause battle-scene.ts to also need to import from settings.ts in a way that initializes its various objects before i18next is ready.
  2. The settings locales work correctly after I moved globalScene to a new file global-scene.ts using VSCode's refactor tools:
import BattleScene from "#app/battle-scene";

// BattleScene.name;

export let globalScene: BattleScene;

export function initGlobalScene(scene: BattleScene): void {
  globalScene = scene;
}
  1. This solution seems to solve the locales issue by delaying the imports in battle-scene.ts until they are truly needed. As further evidence, uncommenting the commented line causes locales to break again.

@DayKev
Copy link
Collaborator Author

DayKev commented Nov 14, 2024

Huh, I tried the opposite (making sure battle-scene.ts didn't import settings.ts) but I guess that could do it. I wonder if that'll fix anything else...

@DayKev
Copy link
Collaborator Author

DayKev commented Nov 14, 2024

Okay I think I found the issue with the SelectModifierPhase tests, the way they're mocking the set up is incorrect in some way. Using the standard test setup (game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]); etc) instead of whatever they're doing to manually run a SMPhase fixed the tests. Though two of them I couldn't get to work yet because making the UI do things in tests is hell...

@DayKev
Copy link
Collaborator Author

DayKev commented Nov 14, 2024

Well whatever, the two SMPhase tests I couldn't fix weren't actually testing the thing they were supposed to be testing anyway.

That just leaves the ME tests that were breaking upon reaching MysteryEncounterRewardsPhase...

@DayKev
Copy link
Collaborator Author

DayKev commented Nov 14, 2024

Everything is fixed!
🎉

@DayKev DayKev removed the Help Wanted Extra attention is needed label Nov 14, 2024
frutescens
frutescens previously approved these changes Nov 14, 2024
Copy link
Contributor

@frutescens frutescens left a comment

Choose a reason for hiding this comment

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

approving to bite the merge conflict bullet

@DayKev
Copy link
Collaborator Author

DayKev commented Nov 14, 2024

If only GitHub wasn't dumb and could fix these fake merge conflicts automatically instead of needing me to do it locally.

frutescens
frutescens previously approved these changes Nov 15, 2024
Copy link
Contributor

@frutescens frutescens left a comment

Choose a reason for hiding this comment

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

This is needed for cleaning up RNG too.

@DayKev DayKev requested a review from a team as a code owner December 4, 2024 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Rewriting existing code related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants