Skip to content

Commit

Permalink
web: Make serde (more-)optional in core
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Jun 8, 2024
1 parent 89c7bc2 commit 7de966f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 26 deletions.
5 changes: 3 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ chrono = { workspace = true, features = ["clock"] }
web-time = "1.1.0"
encoding_rs = "0.8.34"
rand = { version = "0.8.5", features = ["std", "small_rng"], default-features = false }
serde = { workspace = true, features = ["derive"] }
serde = { workspace = true }
serde_json = { version = "1.0", features = ["preserve_order"] }
nellymoser-rs = { git = "https://github.com/ruffle-rs/nellymoser", rev = "754b1184037aa9952a907107284fb73897e26adc", optional = true }
regress = "0.10"
Expand Down Expand Up @@ -83,12 +83,13 @@ timeline_debug = []
mp3 = ["symphonia"]
nellymoser = ["nellymoser-rs"]
audio = ["dasp"]
known_stubs = ["linkme"]
known_stubs = ["linkme", "serde"]
default_compatibility_rules = []
egui = ["dep:egui", "dep:egui_extras", "png"]
jpegxr = ["dep:jpegxr", "lzma"]
default_font = []
test_only_as3 = []
serde = ["serde/derive"]

[build-dependencies]
build_playerglobal = { path = "build_playerglobal" }
10 changes: 5 additions & 5 deletions core/src/backend/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::socket::{ConnectionState, SocketAction, SocketHandle};
use crate::string::WStr;
use async_channel::{Receiver, Sender};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::fmt;
use std::fmt::Display;
Expand Down Expand Up @@ -57,18 +56,19 @@ pub enum SocketMode {

/// The handling mode of links opening a new website.
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum OpenURLMode {
/// Allow all links to open a new website.
#[serde(rename = "allow")]
#[cfg_attr(feature = "serde", serde(rename = "allow"))]
Allow,

/// A confirmation dialog opens with every link trying to open a new website.
#[serde(rename = "confirm")]
#[cfg_attr(feature = "serde", serde(rename = "confirm"))]
Confirm,

/// Deny all links to open a new website.
#[serde(rename = "deny")]
#[cfg_attr(feature = "serde", serde(rename = "deny"))]
Deny,
}

Expand Down
24 changes: 14 additions & 10 deletions core/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use serde::{Deserialize, Serialize};
use std::str::FromStr;

/// Controls whether the content is letterboxed or pillarboxed when the
Expand All @@ -7,19 +6,23 @@ use std::str::FromStr;
/// When letterboxed, black bars will be rendered around the exterior
/// margins of the content.
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename = "letterbox")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename = "letterbox")
)]
pub enum Letterbox {
/// The content will never be letterboxed.
#[serde(rename = "off")]
#[cfg_attr(feature = "serde", serde(rename = "off"))]
Off,

/// The content will only be letterboxed if the content is running fullscreen.
#[serde(rename = "fullscreen")]
#[cfg_attr(feature = "serde", serde(rename = "fullscreen"))]
Fullscreen,

/// The content will always be letterboxed.
#[serde(rename = "on")]
#[cfg_attr(feature = "serde", serde(rename = "on"))]
On,
}

Expand All @@ -41,17 +44,18 @@ impl FromStr for Letterbox {

/// The networking API access mode of the Ruffle player.
/// This setting is only used on web.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum NetworkingAccessMode {
/// All networking APIs are permitted in the SWF file.
#[serde(rename = "all")]
#[cfg_attr(feature = "serde", serde(rename = "all"))]
All,

/// The SWF file may not call browser navigation or browser interaction APIs.
///
/// The APIs getURL(), navigateToURL(), fscommand() and ExternalInterface.call()
/// are prevented in this mode.
#[serde(rename = "internal")]
#[cfg_attr(feature = "serde", serde(rename = "internal"))]
Internal,

/// The SWF file may not call browser navigation or browser interaction APIs
Expand All @@ -65,6 +69,6 @@ pub enum NetworkingAccessMode {
/// URLStream.load() and XMLSocket.connect() are prevented in this mode.
///
/// This mode is not implemented yet.
#[serde(rename = "none")]
#[cfg_attr(feature = "serde", serde(rename = "none"))]
None,
}
6 changes: 3 additions & 3 deletions core/src/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::i18n::core_text;
use fluent_templates::LanguageIdentifier;
use gc_arena::Collect;
use ruffle_render::quality::StageQuality;
use serde::Serialize;

#[derive(Collect, Default)]
#[collect(no_drop)]
Expand Down Expand Up @@ -123,10 +122,11 @@ impl<'gc> ContextMenuState<'gc> {
}
}

#[derive(Clone, Serialize)]
#[derive(Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct ContextMenuItem {
pub enabled: bool,
#[serde(rename = "separatorBefore")]
#[cfg_attr(feature = "serde", serde(rename = "separatorBefore"))]
pub separator_before: bool,
pub checked: bool,
pub caption: String,
Expand Down
4 changes: 2 additions & 2 deletions core/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::display_object::InteractiveObject;
use serde::Deserialize;
use swf::ClipEventFlag;

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -341,7 +340,8 @@ impl<'gc> ClipEvent<'gc> {
}

/// Control inputs to a text field
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub enum TextControlCode {
MoveLeft,
MoveLeftWord,
Expand Down
4 changes: 2 additions & 2 deletions core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ use ruffle_render::commands::CommandList;
use ruffle_render::quality::StageQuality;
use ruffle_render::transform::TransformStack;
use ruffle_video::backend::VideoBackend;
use serde::Deserialize;
use std::cell::RefCell;
use std::collections::{HashMap, VecDeque};
use std::ops::DerefMut;
Expand Down Expand Up @@ -2787,7 +2786,8 @@ fn run_mouse_pick<'gc>(
}

#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub enum PlayerRuntime {
#[default]
FlashPlayer,
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version.workspace = true
workspace = true

[dependencies]
ruffle_core = { path = "../../core", features = ["deterministic", "timeline_debug", "avm_debug", "audio", "mp3", "default_font"] }
ruffle_core = { path = "../../core", features = ["deterministic", "timeline_debug", "avm_debug", "audio", "mp3", "default_font", "serde"] }
ruffle_render = { path = "../../render", features = ["serde"] }
ruffle_input_format = { path = "../input-format" }
ruffle_socket_format = { path = "../socket-format" }
Expand Down
2 changes: 1 addition & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ futures = { workspace = true }

[dependencies.ruffle_core]
path = "../core"
features = ["audio", "mp3", "nellymoser", "default_compatibility_rules", "default_font"]
features = ["audio", "mp3", "nellymoser", "default_compatibility_rules", "default_font", "serde"]

[dependencies.web-sys]
version = "0.3.69"
Expand Down

0 comments on commit 7de966f

Please sign in to comment.