Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phira/locales/en-US/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ item-sfx = SFX Volume
item-bgm = BGM Volume
item-cali = Adjust Offset
item-preferred-sample-rate = Preferred Sample Rate
item-audio-buffer-size = Audio Buffer Size
item-show-acc = Real-Time Accuracy
item-show-avg-fps = Show AVG FPS
Expand Down
1 change: 1 addition & 0 deletions phira/locales/zh-CN/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ item-sfx = 音效音量
item-bgm = BGM 音量
item-cali = 调整延迟
item-preferred-sample-rate = 首选采样率
item-audio-buffer-size = 音频缓冲区大小
item-show-acc = 显示实时准度
item-show-avg-fps = 显示平均帧率
Expand Down
11 changes: 2 additions & 9 deletions phira/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,7 @@ pub fn set_chosen_file(file: String) {

#[cfg(target_env = "ohos")]
#[napi]
pub fn mark_import() {
pub fn mark_auto_import() {
use prpr::scene::CHOSEN_FILE;
CHOSEN_FILE.lock().unwrap().0 = Some("_import".to_owned());
}

#[cfg(target_env = "ohos")]
#[napi]
pub fn mark_import_respack() {
use prpr::scene::CHOSEN_FILE;
CHOSEN_FILE.lock().unwrap().0 = Some("_import_respack".to_owned());
CHOSEN_FILE.lock().unwrap().0 = Some("_import_auto".to_owned());
}
18 changes: 18 additions & 0 deletions phira/src/page/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ fn request_export() {
EXPORT_PICKER_PATH.lock().unwrap().replace(output_path_str);
}
EXPORT_CONFIG.lock().unwrap().replace(config);
} else if #[cfg(target_env = "ohos")] {
miniquad::native::call_request_callback(format!("{{\"action\":\"request_export\",\"filename\":\"{}\"}}", suggested_name));
} else {
if let Some(output_path) = rfd::FileDialog::new().set_title(tl!("multi-export-title")).set_file_name(&suggested_name).save_file() {
let config = File::create(&output_path).map(|file| ExportConfig {
Expand Down Expand Up @@ -542,6 +544,22 @@ extern "system" fn process_export_fd(env: jni::JNIEnv, _: jni::objects::JClass,
}));
}

#[cfg(target_env = "ohos")]
mod ohos_export {
use super::*;
use napi_derive_ohos::napi;
#[napi]
#[allow(dead_code)]
pub fn process_export_fd_ohos(fd: u32) {
use std::os::fd::FromRawFd;
let file = unsafe { File::from_raw_fd(fd as _) };
EXPORT_CONFIG.lock().unwrap().replace(Ok(ExportConfig {
file,
deleter: Box::new(|| Ok(())),
}));
}
}

impl Page for LibraryPage {
fn label(&self) -> Cow<'static, str> {
tl!("label")
Expand Down
26 changes: 22 additions & 4 deletions phira/src/page/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ struct GeneralList {

lang_btn: ChooseButton,

#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))]
fullscreen_btn: DRectButton,

cache_btn: DRectButton,
Expand Down Expand Up @@ -306,7 +306,7 @@ impl GeneralList {
.unwrap_or_default(),
),

#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))]
fullscreen_btn: DRectButton::new(),

cache_btn: DRectButton::new(),
Expand Down Expand Up @@ -364,7 +364,7 @@ impl GeneralList {
return Ok(Some(false));
}

#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))]
if self.fullscreen_btn.touch(touch, t) {
config.fullscreen_mode ^= true;

Expand Down Expand Up @@ -475,7 +475,7 @@ impl GeneralList {
self.lang_btn.render(ui, rr, t);
}

#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))]
item! {
render_title(ui, tl!("item-fullscreen"), None);
render_switch(ui, rr, t, &mut self.fullscreen_btn, config.fullscreen_mode);
Expand Down Expand Up @@ -537,6 +537,8 @@ struct AudioList {
cali_btn: DRectButton,
#[cfg(not(target_os = "android"))]
preferred_sample_rate_btn: DRectButton,
#[cfg(target_env = "ohos")]
audio_buffer_size_btn: DRectButton,
cali_task: LocalTask<Result<OffsetPage>>,
next_page: Option<NextPage>,
}
Expand All @@ -551,6 +553,8 @@ impl AudioList {
cali_btn: DRectButton::new(),
#[cfg(not(target_os = "android"))]
preferred_sample_rate_btn: DRectButton::new(),
#[cfg(target_env = "ohos")]
audio_buffer_size_btn: DRectButton::new(),

cali_task: None,
next_page: None,
Expand Down Expand Up @@ -593,6 +597,14 @@ impl AudioList {
config.preferred_sample_rate = options[(selected + 1) % options.len()];
return Ok(Some(true));
}
#[cfg(target_env = "ohos")]
if self.audio_buffer_size_btn.touch(touch, t) {
let options = [128u32, 256u32, 512u32];
let current = config.audio_buffer_size.unwrap_or(256);
let selected = options.iter().position(|&r| r == current).unwrap_or(1);
config.audio_buffer_size = Some(options[(selected + 1) % options.len()]);
return Ok(Some(true));
}
Ok(None)
}

Expand Down Expand Up @@ -650,6 +662,12 @@ impl AudioList {
render_title(ui, tl!("item-preferred-sample-rate"), None);
self.preferred_sample_rate_btn.render_text(ui, rr, t, format!("{} Hz", config.preferred_sample_rate), 0.5, false);
}
#[cfg(target_env = "ohos")]
item! {
render_title(ui, tl!("item-audio-buffer-size"), None);
let buf_size = config.audio_buffer_size.unwrap_or(256);
self.audio_buffer_size_btn.render_text(ui, rr, t, format!("{}", buf_size), 0.5, false);
}
(w, h)
}

Expand Down
13 changes: 13 additions & 0 deletions phira/src/scene/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,19 @@ impl Scene for MainScene {
}
if let Some((id, file)) = take_file() {
match id.as_str() {
"_import_auto" => {
let new_id = match File::open(&file).map(BufReader::new).map(zip::ZipArchive::new) {
Ok(Ok(zip)) => {
if zip.file_names().any(|name| name.ends_with("click.png")) {
"_import_respack"
} else {
"_import"
}
}
_ => "_import",
};
return_file(new_id.to_owned(), file);
}
"_import" => {
let export_info = (|| -> Result<Option<(ExportInfo, usize)>> {
let file = File::open(&file)?;
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Default for Config {
particle: true,
player_name: "Mivik".to_string(),
player_rks: 15.,
preferred_sample_rate: 44100,
preferred_sample_rate: if cfg!(target_env = "ohos") { 48000 } else { 44100 },
res_pack_path: None,
sample_count: 1,
show_acc: false,
Expand Down
6 changes: 3 additions & 3 deletions prpr/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ pub fn screen_aspect() -> f32 {
let vp = get_viewport();
vp.2 as f32 / vp.3 as f32
}

// This function is used to create in-game audio manager
pub fn create_audio_manger(config: &Config) -> Result<AudioManager> {
#[cfg(target_os = "android")]
{
Expand All @@ -404,8 +404,8 @@ pub fn create_audio_manger(config: &Config) -> Result<AudioManager> {
{
use sasa::backend::ohos::*;
AudioManager::new(OhosBackend::new(OhosSettings {
buffer_size: Some(256),
sample_rate: Some(config.preferred_sample_rate),
sample_rate: config.preferred_sample_rate.into(),
buffer_size: config.audio_buffer_size.or(Some(256)),
channels: 2,
}))
}
Expand Down
8 changes: 4 additions & 4 deletions prpr/src/judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub enum Judgement {
Miss,
}

#[cfg(any(not(closed), target_os = "windows", target_os = "linux"))]
#[cfg(any(not(closed), all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos"))))]
#[derive(Default)]
pub(crate) struct JudgeInner {
diffs: Vec<f32>,
Expand All @@ -162,7 +162,7 @@ pub(crate) struct JudgeInner {
num_of_notes: u32,
}

#[cfg(any(not(closed), target_os = "windows", target_os = "linux"))]
#[cfg(any(not(closed), all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos"))))]
impl JudgeInner {
pub fn new(num_of_notes: u32) -> Self {
Self {
Expand Down Expand Up @@ -247,9 +247,9 @@ impl JudgeInner {
}

#[rustfmt::skip]
#[cfg(all(closed, not(any(target_os = "windows", target_os = "linux"))))]
#[cfg(all(closed, not(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))))]
pub mod inner;
#[cfg(all(closed, not(any(target_os = "windows", target_os = "linux"))))]
#[cfg(all(closed, not(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))))]
use inner::*;

type Judgements = Vec<(f32, u32, u32, Result<Judgement, bool>)>;
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod ui;
pub mod log;

#[rustfmt::skip]
#[cfg(all(closed, not(any(target_os = "windows", target_os = "linux"))))]
#[cfg(all(closed, not(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))))]
pub mod inner;

pub use scene::Main;
Expand Down
15 changes: 6 additions & 9 deletions prpr/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,7 @@ pub fn request_input(id: impl Into<String>, mut config: InputBox) {
if config.prompt.is_none() {
config = config.prompt(ttl!("input-msg"));
}
cfg_if! {
if #[cfg(target_env = "ohos")] {
miniquad::native::call_request_callback(r#"{"action": "show_input_window"}"#.to_string());
} else {
show_inputbox(config, &*default_backend());
}
}
show_inputbox(config, &*default_backend());
}

pub fn take_input() -> Option<(String, String)> {
Expand All @@ -196,7 +190,10 @@ pub fn return_input(id: String, text: String) {

#[cfg(not(target_arch = "wasm32"))]
pub fn request_file(id: impl Into<String>) {
*CHOSEN_FILE.lock().unwrap() = (Some(id.into()), None);
let id: String = id.into();
#[cfg(target_env = "ohos")]
let is_photo = id == "avatar";
*CHOSEN_FILE.lock().unwrap() = (Some(id), None);
cfg_if! {
if #[cfg(target_os = "android")] {
unsafe {
Expand Down Expand Up @@ -299,7 +296,7 @@ pub fn request_file(id: impl Into<String>) {
.unwrap()
.presentViewController_animated_completion(&picker, true, None);
} else if #[cfg(target_env = "ohos")] {
miniquad::native::call_request_callback(r#"{"action": "chooseFile"}"#.to_string());
miniquad::native::call_request_callback(format!(r#"{{"action": "chooseFile", "isPhoto": {}}}"#, is_photo));
} else { // desktop
CHOSEN_FILE.lock().unwrap().1 = rfd::FileDialog::new().pick_file().map(|it| it.display().to_string());
}
Expand Down
6 changes: 3 additions & 3 deletions prpr/src/scene/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ use tracing::{debug, warn};
const PAUSE_CLICK_INTERVAL: f32 = 0.7;

#[rustfmt::skip]
#[cfg(all(closed, not(any(target_os = "windows", target_os = "linux"))))]
#[cfg(all(closed, not(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))))]
mod inner;
#[cfg(all(closed, not(any(target_os = "windows", target_os = "linux"))))]
#[cfg(all(closed, not(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))))]
use inner::*;

const WAIT_TIME: f32 = 0.5;
Expand Down Expand Up @@ -916,7 +916,7 @@ impl Scene for GameScene {
if t >= AFTER_TIME + 0.3 {
let mut record_data = None;
// TODO strengthen the protection
#[cfg(all(closed, not(any(target_os = "windows", target_os = "linux"))))]
#[cfg(all(closed, not(all(any(target_os = "windows", target_os = "linux"), not(target_env = "ohos")))))]
if let Some(upload_fn) = &self.upload_fn {
if !self.res.config.offline_mode && !self.res.config.autoplay() && self.res.config.speed >= 1.0 - 1e-3 {
if let Some(player) = &self.player {
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ impl<'a> From<(Option<f32>, &'a mut f32)> for LoadingParams<'a> {
}
}
}

// This function is used to create UI audio manager.
#[allow(clippy::blocks_in_conditions)]
fn build_audio() -> AudioManager {
match {
Expand Down
Loading