Skip to content

Support Fields Having Pre Select Scoring Zones [AARD-1894] #1211

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

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

ryanzhangofficial
Copy link
Member

@ryanzhangofficial ryanzhangofficial commented Jul 11, 2025

Task

Allow users to choose and cache/export where scoring zones are positioned.
AARD-1894

Symptom

Benefits of having direct user editing: bulk edits and reuse, version control and diffs, schema validation

Solution

  • Include pre select scoring zones in-simulator as part of the new Developer Tool.
  • Create a framework for caching devtool keys
  • Allow users to export mira files with edited UserData and import them for use cases such as cleared cache
Screenshot 2025-07-11 150237 Screenshot 2025-07-11 104009

Verification

  • Added new tests in FieldMiraEditor.test.ts and all passed
  • Cached ScoringZonePreferences are loaded after refresh

@ryanzhangofficial ryanzhangofficial requested review from a team as code owners July 11, 2025 17:41
@ryanzhangofficial ryanzhangofficial self-assigned this Jul 11, 2025
@ryanzhangofficial ryanzhangofficial added ui/ux Relating to user interface, or in general, user experience mirabuf Relating to the mirabuf format labels Jul 11, 2025
Comment on lines +420 to +452
try {
// Re-encode the assembly with devtool changes
const updatedBuffer = mirabuf.Assembly.encode(assembly).finish()

// Update the cached buffer
const cache = miraType == MiraType.ROBOT ? backUpRobots : backUpFields
if (cache[id]) {
cache[id].buffer = updatedBuffer
}

// Update OPFS if available
if (canOPFS) {
const fileHandle = await (
miraType == MiraType.ROBOT ? robotFolderHandle : fieldFolderHandle
).getFileHandle(id, { create: false })
const writable = await fileHandle.createWritable()
await writable.write(updatedBuffer)
await writable.close()
}

World.analyticsSystem?.event("Devtool Cache Persist", {
key: id,
type: miraType == MiraType.ROBOT ? "robot" : "field",
assemblyName: assembly.info?.name ?? "unknown",
fileSize: updatedBuffer.byteLength,
})

return true
} catch (e) {
console.error("Failed to persist devtool changes", e)
World.analyticsSystem?.exception("Failed to persist devtool changes to cache")
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should try to put the try block around as small a section of fallible code as possible. It seems like the fallible function here is the event method call (obviously any file I/O is subject to failure as well, but since we're creating the directory, it shouldn't regularly fail), unless I'm missing something. So maybe we could more the try block to be just around the event method class.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would argue that most of the lines in the current try block is fallible. For example, const updatedBuffer = mirabuf.Assembly.encode(assembly).finish() if the assembly is malformed.

@rutmanz rutmanz changed the title Support Fields Having Pre Select Scoring Zones Support Fields Having Pre Select Scoring Zones [AARD-1894] Jul 11, 2025
Copy link
Member

@rutmanz rutmanz left a comment

Choose a reason for hiding this comment

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

I'm trying to test this but it doesn't actually seem to persist the changes? These are the steps I'm taking:

  1. Import field
  2. Add scoring zone
  3. Go to devtool editor and click "save" (I see the toast that says they've been persisted)
  4. Clear preferences (because scoring zone data is already scored here; I think part of this PR would also be ending the storage of scoring zones in the preferences cache so it can stay with the mirabuf file)
  5. Reload
  6. Import same field
  7. No scoring zones are present

I'm not seeing any console errors

@AlexD717
Copy link
Member

  1. Clear preferences (because scoring zone data is already scored here; I think part of this PR would also be ending the storage of scoring zones in the preferences cache so it can stay with the mirabuf file)

Wouldn't saving data back to the mira file require us to store the mira files for each individual users? The way I understood the PR (I might be wrong) the goal was to allow fields to come with pre-selected scoring zones. Meaning that in the exporter a new tab would be added saving this data to the mira file, that way when the user comes and tries to load a field all the scoring zones are already pre-configured.

@ryanzhangofficial
Copy link
Member Author

ryanzhangofficial commented Jul 11, 2025

I'm trying to test this but it doesn't actually seem to persist the changes? These are the steps I'm taking:

  1. Import field
  2. Add scoring zone
  3. Go to devtool editor and click "save" (I see the toast that says they've been persisted)
  4. Clear preferences (because scoring zone data is already scored here; I think part of this PR would also be ending the storage of scoring zones in the preferences cache so it can stay with the mirabuf file)
  5. Reload
  6. Import same field
  7. No scoring zones are present

I'm not seeing any console errors

Ah I didn't incorporate the "clear preferences" step on my interpretation of the caching deliverable of this ticket. The changes do persist after reloading if the preferences aren't cleared. However, I don't think it makes sense for the changes to still persist after preferences are cleared especially for default fields. I think your suggestion in AARD-1914 on making the edited mira files exportable makes a lot of sense though (currently working on it). The other route would to be make it similar to the custom input panel, but I think that's out of the scope for this ticket.

@rutmanz
Copy link
Member

rutmanz commented Jul 11, 2025

As the current behavior on dev is to save and restore scoring zones automatically, I don't know what feature this pull request would be adding if it doesn't load the scoring zones from the saved cached mirabuf files

@ryanzhangofficial
Copy link
Member Author

The issues should all be addressed.

Copy link
Member

@rutmanz rutmanz left a comment

Choose a reason for hiding this comment

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

it looks like you didn't update the type for DevtoolMiraData (it's still unknown), but other than that looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mirabuf Relating to the mirabuf format ui/ux Relating to user interface, or in general, user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants