feat: added sandbox
config
This commit is contained in:
parent
ef80004f4b
commit
d6434a201c
8 changed files with 77 additions and 3 deletions
|
@ -37,10 +37,11 @@ config = ["dep:serde", "dep:serde_json", "dep:enum-ordinalize"]
|
|||
components = ["dep:wincompatlib", "dep:lazy_static"]
|
||||
game = ["components", "config"]
|
||||
discord-rpc = ["dep:discord-rich-presence"]
|
||||
sandbox = []
|
||||
|
||||
# Genshin-specific features
|
||||
environment-emulation = []
|
||||
fps-unlocker = ["dep:md-5"]
|
||||
|
||||
all = ["states", "config", "components", "game", "discord-rpc", "environment-emulation", "fps-unlocker"]
|
||||
all = ["states", "config", "components", "game", "discord-rpc", "sandbox", "environment-emulation", "fps-unlocker"]
|
||||
default = ["all"]
|
||||
|
|
|
@ -11,6 +11,7 @@ SDK based on [anime-game-core](https://github.com/an-anime-team/anime-game-core)
|
|||
| Manage components (list wine/dxvk versions, etc) | `components` |
|
||||
| Run the game | `game` |
|
||||
| Use Discord RPC when the game is running | `discord-rpc` |
|
||||
| Run the game in `bwrap` sandbox | `sandbox` |
|
||||
|
||||
## Anime Game specific features
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@ pub mod dxvk;
|
|||
pub mod wine;
|
||||
pub mod gamescope;
|
||||
|
||||
#[cfg(feature = "sandbox")]
|
||||
pub mod sandbox;
|
||||
|
||||
pub mod prelude {
|
||||
pub use super::resolution::Resolution;
|
||||
pub use super::repairer::Repairer;
|
||||
|
@ -19,4 +22,7 @@ pub mod prelude {
|
|||
|
||||
pub use super::wine::prelude::*;
|
||||
pub use super::gamescope::prelude::*;
|
||||
|
||||
#[cfg(feature = "sandbox")]
|
||||
pub use super::sandbox::Sandbox;
|
||||
}
|
||||
|
|
49
src/config/schema_blanks/sandbox.rs
Normal file
49
src/config/schema_blanks/sandbox.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Sandbox {
|
||||
pub enabled: bool,
|
||||
pub private: Vec<String>
|
||||
}
|
||||
|
||||
impl Default for Sandbox {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
private: vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&JsonValue> for Sandbox {
|
||||
fn from(value: &JsonValue) -> Self {
|
||||
let default = Self::default();
|
||||
|
||||
Self {
|
||||
enabled: match value.get("enabled") {
|
||||
Some(value) => value.as_bool().unwrap_or(default.enabled),
|
||||
None => default.enabled
|
||||
},
|
||||
|
||||
private: match value.get("private") {
|
||||
Some(value) => match value.as_array() {
|
||||
Some(values) => {
|
||||
let mut private = Vec::new();
|
||||
|
||||
for value in values {
|
||||
if let Some(server) = value.as_str() {
|
||||
private.push(server.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
private
|
||||
},
|
||||
None => default.private
|
||||
},
|
||||
None => default.private
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ impl ConfigExt for Config {
|
|||
|
||||
#[inline]
|
||||
fn deserialize_schema<T: AsRef<str>>(schema: T) -> anyhow::Result<Self::Schema> {
|
||||
Ok(serde_json::from_str(schema.as_ref())?)
|
||||
Ok(Self::Schema::from(&serde_json::from_str(schema.as_ref())?))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
#[cfg(feature = "sandbox")]
|
||||
use crate::config::schema_blanks::sandbox::Sandbox;
|
||||
|
||||
#[cfg(feature = "components")]
|
||||
use crate::components::wine::Version as WineVersion;
|
||||
|
||||
|
@ -33,6 +36,9 @@ pub struct Schema {
|
|||
pub launcher: Launcher,
|
||||
pub game: Game,
|
||||
|
||||
#[cfg(feature = "sandbox")]
|
||||
pub sandbox: Sandbox,
|
||||
|
||||
#[cfg(feature = "components")]
|
||||
pub components: Components,
|
||||
|
||||
|
@ -54,6 +60,11 @@ impl From<&JsonValue> for Schema {
|
|||
None => default.game
|
||||
},
|
||||
|
||||
sandbox: match value.get("sandbox") {
|
||||
Some(value) => Sandbox::from(value),
|
||||
None => default.sandbox
|
||||
},
|
||||
|
||||
components: match value.get("components") {
|
||||
Some(value) => Components::from(value),
|
||||
None => default.components
|
||||
|
|
|
@ -31,7 +31,7 @@ impl ConfigExt for Config {
|
|||
|
||||
#[inline]
|
||||
fn deserialize_schema<T: AsRef<str>>(schema: T) -> anyhow::Result<Self::Schema> {
|
||||
Ok(serde_json::from_str(schema.as_ref())?)
|
||||
Ok(Self::Schema::from(&serde_json::from_str(schema.as_ref())?))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
#[cfg(feature = "sandbox")]
|
||||
use crate::config::schema_blanks::sandbox::Sandbox;
|
||||
|
||||
#[cfg(feature = "components")]
|
||||
use crate::components::wine::Version as WineVersion;
|
||||
|
||||
|
@ -33,6 +36,9 @@ pub struct Schema {
|
|||
pub launcher: Launcher,
|
||||
pub game: Game,
|
||||
|
||||
#[cfg(feature = "sandbox")]
|
||||
pub sandbox: Sandbox,
|
||||
|
||||
#[cfg(feature = "components")]
|
||||
pub components: Components,
|
||||
|
||||
|
|
Loading…
Reference in a new issue