desktop: Allow specifying player version

This commit is contained in:
CUB3D 2022-12-29 21:44:20 +00:00 committed by Nathan Adams
parent c2ad376e2c
commit 8db909a7d4
2 changed files with 19 additions and 4 deletions

View File

@ -1917,6 +1917,7 @@ pub struct PlayerBuilder {
warn_on_unsupported_content: bool,
load_behavior: LoadBehavior,
spoofed_url: Option<String>,
player_version: Option<u8>,
}
impl PlayerBuilder {
@ -1952,6 +1953,7 @@ impl PlayerBuilder {
warn_on_unsupported_content: true,
load_behavior: LoadBehavior::Streaming,
spoofed_url: None,
player_version: None,
}
}
@ -2071,6 +2073,12 @@ impl PlayerBuilder {
self
}
// Configures the target player version.
pub fn with_player_version(mut self, version: Option<u8>) -> Self {
self.player_version = version;
self
}
/// Builds the player, wiring up the backends and configuring the specified settings.
pub fn build(self) -> Arc<Mutex<Player>> {
use crate::backend::*;
@ -2101,8 +2109,10 @@ impl PlayerBuilder {
.video
.unwrap_or_else(|| Box::new(null::NullVideoBackend::new()));
let player_version = self.player_version.unwrap_or(NEWEST_PLAYER_VERSION);
// Instantiate the player.
let fake_movie = Arc::new(SwfMovie::empty(NEWEST_PLAYER_VERSION));
let fake_movie = Arc::new(SwfMovie::empty(player_version));
let frame_rate = 12.0;
let player = Arc::new_cyclic(|self_ref| {
Mutex::new(Player {
@ -2141,7 +2151,7 @@ impl PlayerBuilder {
system: SystemProperties::default(),
transform_stack: TransformStack::new(),
instance_counter: 0,
player_version: NEWEST_PLAYER_VERSION,
player_version,
is_playing: self.autoplay,
needs_render: true,
warn_on_unsupported_content: self.warn_on_unsupported_content,
@ -2159,7 +2169,7 @@ impl PlayerBuilder {
GcRootData {
audio_manager: AudioManager::new(),
action_queue: ActionQueue::new(),
avm1: Avm1::new(gc_context, NEWEST_PLAYER_VERSION),
avm1: Avm1::new(gc_context, player_version),
avm2: Avm2::new(gc_context),
current_context_menu: None,
drag_object: None,

View File

@ -113,6 +113,10 @@ struct Opt {
/// Spoofs the root SWF URL provided to ActionScript.
#[clap(long, value_parser)]
spoof_url: Option<Url>,
/// The version of the player to emulate
#[clap(long, short)]
player_version: Option<u8>
}
#[cfg(feature = "render_trace")]
@ -281,7 +285,8 @@ impl App {
.with_warn_on_unsupported_content(!opt.dont_warn_on_unsupported_content)
.with_fullscreen(opt.fullscreen)
.with_load_behavior(opt.load_behavior)
.with_spoofed_url(opt.spoof_url.clone().map(|url| url.to_string()));
.with_spoofed_url(opt.spoof_url.clone().map(|url| url.to_string()))
.with_player_version(opt.player_version);
let player = builder.build();