AllPoland / ArcViewer

Open source, overengineered 3D Beat Saber map previewer and replay viewer
https://allpoland.github.io/ArcViewer/
GNU General Public License v3.0
65 stars 15 forks source link

Add single-argument overload for `LoadMapInput` #64

Closed GG3Hahn closed 4 months ago

GG3Hahn commented 5 months ago

I was getting annoyed with BeatSaver initializing a new ArcViewer frame every time I want to preview a map (and be stuck loading for 5+ seconds), so I thought "surely there must be a way to reuse one instance". As it turns out, you are able to call gameInstance.SendMessage from the browser window context to execute C# methods on GameObjects. SendMessage however only allows for one parameter. Apparently the existing LoadMapInput variant with the optional bool isn't compiled in the same way an overload would be and always takes 2 parameters in the assembly, so a change like this would be necessary for my desired interop.

With this patch you can use

gameInstance.SendMessage('Preview', 'LoadMapInput', '849a') // or any other map ID / URL

to set the map. This also works with <iframe>s as long as ArcViewer is hosted on the same origin.

AllPoland commented 4 months ago

That optional bool parameter is actually vestigial, turns out. Not exactly sure why I originally added it, but I've just made a separate commit that removes it. That commit also fixes some potential undefined behavior when trying to load a new map outside of map select.

Closing this since the feature has been added