Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: l10n panic, relogin hint(#351) #355

Merged
merged 2 commits into from
Aug 16, 2024
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/home.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ not-opened = Not available yet
not-logged-in = Not logged in

failed-to-update = Failed to update user info
note-try-login-again = Note: Please try login again

update = v{ $version } Update
update-desc =
Expand Down
1 change: 1 addition & 0 deletions phira/locales/zh-CN/home.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ not-opened = 功能尚未开启
not-logged-in = 未登录

failed-to-update = 加载用户信息失败
note-try-login-again = 提示: 请尝试重新登录

update = v{ $version } 更新
update-desc =
Expand Down
4 changes: 3 additions & 1 deletion phira/src/client/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ impl<T: Object + 'static> Ptr<T> {
{
let map = obtain_map_cache::<T>();
let mut guard = map.lock().unwrap();
let Some(actual_map) = guard.downcast_mut::<ObjectMap::<T>>() else { unreachable!() };
let Some(actual_map) = guard.downcast_mut::<ObjectMap<T>>() else {
unreachable!()
};
if let Some(value) = actual_map.get(&self.id) {
return Ok(Arc::clone(value));
}
Expand Down
2 changes: 1 addition & 1 deletion phira/src/client/model/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Object, Ptr, User, File};
use super::{File, Object, Ptr, User};
use chrono::{DateTime, Utc};
use serde::Deserialize;

Expand Down
2 changes: 1 addition & 1 deletion phira/src/mp/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ impl MPPanel {
let o = -(cn as f32 * (w + pad) - pad) / 2.;
for j in 0..cn {
let r = Rect::new(j as f32 * w + o, i as f32 * h, w, h);
let Some(user) = iter.next() else { unreachable!() };
let Some(user) = iter.next() else { unreachable!() };
ui.avatar(r.x + 0.07, r.center().y, 0.05, t, UserManager::opt_avatar(user.id, &self.icon_user));
ui.text(user.name)
.pos(r.x + 0.14, r.center().y)
Expand Down
2 changes: 1 addition & 1 deletion phira/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub struct ChartItem {
pub info: BriefChartInfo,
pub local_path: Option<String>,
pub illu: Illustration,
pub chart_type: ChartType
pub chart_type: ChartType,
}

#[derive(Clone, Copy)]
Expand Down
2 changes: 1 addition & 1 deletion phira/src/page/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl Page for HomePage {
let _ = save_data();
sync_data();
}
show_error(err.context(tl!("failed-to-update")));
show_error(err.context(tl!("failed-to-update") + "\n" + tl!("note-try-login-again")));
}
Ok(val) => {
get_data_mut().me = Some(val);
Expand Down
6 changes: 2 additions & 4 deletions phira/src/page/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
use anyhow::{anyhow, Result};
use macroquad::prelude::*;
use prpr::{
ext::{semi_black, JoinToString, RectExt, SafeTexture, ScaleType, LocalTask, poll_future},
ext::{poll_future, semi_black, JoinToString, LocalTask, RectExt, SafeTexture, ScaleType},
scene::{request_file, request_input, return_input, show_error, show_message, take_input, NextScene},
task::Task,
ui::{button_hit, DRectButton, RectButton, Ui},
Expand Down Expand Up @@ -362,9 +362,7 @@ impl Page for LibraryPage {
}
if self.tabs.selected_mut().view.clicked_special {
let icons = Arc::clone(&self.icons);
self.next_page_task = Some(Box::pin(async move {
Ok(NextPage::Overlay(Box::new(CollectionPage::new(icons).await?)))
}));
self.next_page_task = Some(Box::pin(async move { Ok(NextPage::Overlay(Box::new(CollectionPage::new(icons).await?))) }));
self.tabs.selected_mut().view.clicked_special = false;
}
if let Some(task) = &mut self.next_page_task {
Expand Down
3 changes: 2 additions & 1 deletion phira/src/page/respack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ use prpr::{
use sasa::{AudioManager, PlaySfxParams, Sfx};
use serde_yaml::Error;
use std::{
borrow::Cow,
fs::File,
path::{Path, PathBuf},
sync::{
atomic::{AtomicBool, Ordering},
Arc,
}, borrow::Cow,
},
};

fn build_emitter(pack: &ResourcePack) -> Result<ParticleEmitter> {
Expand Down
10 changes: 8 additions & 2 deletions phira/src/page/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ use crate::{
use anyhow::Result;
use macroquad::prelude::*;
use prpr::{
core::BOLD_FONT,
ext::{poll_future, semi_white, LocalTask, RectExt, SafeTexture},
l10n::{LanguageIdentifier, LANG_IDENTS, LANG_NAMES},
scene::{request_input, return_input, show_error, take_input},
ui::{DRectButton, Scroll, Slider, Ui}, core::BOLD_FONT,
ui::{DRectButton, Scroll, Slider, Ui},
};
use std::{borrow::Cow, net::ToSocketAddrs, sync::atomic::Ordering};

Expand Down Expand Up @@ -186,7 +187,12 @@ fn render_settings(ui: &mut Ui, mut r: Rect, icon: &SafeTexture) -> (f32, f32) {

let text = tl!("about-content", "version" => env!("CARGO_PKG_VERSION"));
let (first, text) = text.split_once('\n').unwrap();
let tr = ui.text(first).pos(ct.x, ir.bottom() + 0.03).anchor(0.5, 0.).size(0.6).draw_using(&BOLD_FONT);
let tr = ui
.text(first)
.pos(ct.x, ir.bottom() + 0.03)
.anchor(0.5, 0.)
.size(0.6)
.draw_using(&BOLD_FONT);

let r = ui
.text(text.trim())
Expand Down
16 changes: 11 additions & 5 deletions phira/src/scene/chapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,17 @@ impl Scene for ChapterScene {
line_length: 6.,
offset: dir
.read("offset")
.map(|d| f32::from_be_bytes(d.get(0..4).map(|first4| {
let mut result = <[u8;4]>::default();
result.copy_from_slice(first4);
result
}).unwrap_or_default()))
.map(|d| {
f32::from_be_bytes(
d.get(0..4)
.map(|first4| {
let mut result = <[u8; 4]>::default();
result.copy_from_slice(first4);
result
})
.unwrap_or_default(),
)
})
.unwrap_or_default(),
tip: None,
tags: Vec::new(),
Expand Down
2 changes: 1 addition & 1 deletion phira/src/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{anim::Anim, Result};
use macroquad::prelude::*;
use prpr::{
ext::{semi_black, RectExt},
ui::{rounded_rect_shadow, RectButton, ShadowConfig, Ui, button_hit},
ui::{button_hit, rounded_rect_shadow, RectButton, ShadowConfig, Ui},
};
use std::borrow::Cow;

Expand Down
4 changes: 2 additions & 2 deletions prpr/src/core/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub struct JudgeLine {
pub ctrl_obj: RefCell<CtrlObject>,
pub kind: JudgeLineKind,
/// Height Animation, decribes the `height` of the line at a specific time
///
///
/// The `height` here can be considered as the absolute 'y' coordinate of the notes attached to this line, which is calculated by
/// ∫ v(t) dt, where v(t) is the speed of the line at time t.
pub height: AnimFloat,
Expand All @@ -113,7 +113,7 @@ pub struct JudgeLine {
pub parent: Option<usize>,
pub z_index: i32,
/// Whether to show notes below the line, here below is defined in the time axis, which means the note should already be judged
///
///
/// TODO: Not sure
pub show_below: bool,
pub attach_ui: Option<UIElement>,
Expand Down
4 changes: 3 additions & 1 deletion prpr/src/judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ impl Judge {
let t = time_of(touch);
let mut closest = (None, X_DIFF_MAX, LIMIT_BAD, LIMIT_BAD + (X_DIFF_MAX / NOTE_WIDTH_RATIO_BASE - 1.).max(0.) * DIST_FACTOR);
for (line_id, ((line, pos), (idx, st))) in chart.lines.iter_mut().zip(pos.iter()).zip(self.notes.iter_mut()).enumerate() {
let Some(pos) = pos[id] else { continue; };
let Some(pos) = pos[id] else {
continue;
};
for id in &idx[*st..] {
let note = &mut line.notes[*id as usize];
if !matches!(note.judge, JudgeStatus::NotJudged | JudgeStatus::PreJudge) {
Expand Down
31 changes: 19 additions & 12 deletions prpr/src/l10n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use once_cell::sync::Lazy;
pub use unic_langid::{langid, LanguageIdentifier};

use fluent::{FluentArgs, FluentError};
use fluent_syntax::ast::Pattern;
use fluent_syntax::ast::{Message, Pattern};
use lru::LruCache;
use std::{
borrow::Cow,
Expand Down Expand Up @@ -164,18 +164,25 @@ impl L10nLocal {
self.generation = gen;
self.cache.clear();
}
let (id, pattern) = self.cache.get_or_insert(key.clone(), || {
let guard = GLOBAL.order.lock().unwrap();
if let Some((id, message)) = guard
.iter()
.filter_map(|id| self.bundles.inner[*id].get_message(&key).map(|msg| (*id, msg)))
.next()
{
return (id, message.value().unwrap());
if let Some((id, pattern)) = {
let get_result = self.cache.get(&key);
if get_result.is_none() {
let guard = GLOBAL.order.lock().unwrap();
guard
.iter()
.filter_map(|id| self.bundles.inner[*id].get_message(&key).map(|msg| (*id, msg)))
.next()
.map(|(id, message)| (id, message.value().unwrap()))
.map(|val| self.cache.get_or_insert(key.clone(), || val))
} else {
get_result
}
panic!("no translation found for {key}");
});
unsafe { std::mem::transmute(self.bundles.inner[*id].format_pattern(pattern, args, errors)) }
} {
unsafe { std::mem::transmute(self.bundles.inner[*id].format_pattern(pattern, args, errors)) }
} else {
warn!("no translation found for {key}, returning key");
key
}
}

pub fn format<'s>(&mut self, key: impl Into<Cow<'static, str>>, args: Option<&'s FluentArgs<'s>>) -> Cow<'s, str> {
Expand Down
4 changes: 2 additions & 2 deletions prpr/src/parse/pec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ pub fn parse_pec(source: &str, extra: ChartExtra) -> Result<Chart> {
offset = Some(it.take_f32()? / 1000. - 0.15);
} else {
let Some(cmd) = it.next() else {
return Ok(());
};
return Ok(());
};
let cs: Vec<_> = cmd.chars().collect();
if cs.len() > 2 {
ptl!(bail "unknown-command", "cmd" => cmd);
Expand Down
12 changes: 1 addition & 11 deletions prpr/src/scene/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,7 @@ impl LoadingScene {
if info.tip.is_none() {
info.tip = Some(crate::config::TIPS.choose(&mut thread_rng()).unwrap().to_owned());
}
let future = Box::pin(GameScene::new(
mode,
info.clone(),
config,
fs,
player,
background.clone(),
illustration.clone(),
upload_fn,
update_fn,
));
let future = Box::pin(GameScene::new(mode, info.clone(), config, fs, player, background.clone(), illustration.clone(), upload_fn, update_fn));
let charter = Regex::new(r"\[!:[0-9]+:([^:]*)\]").unwrap().replace_all(&info.charter, "$1").to_string();

Ok(Self {
Expand Down
4 changes: 3 additions & 1 deletion prpr/src/ui/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ impl Scroll {
}

pub fn touch(&mut self, touch: &Touch, t: f32) -> bool {
let Some(matrix) = self.matrix else { return false; };
let Some(matrix) = self.matrix else {
return false;
};
let pt = touch.position;
let pt = matrix.transform_point(&Point::new(pt.x, pt.y));
if touch.phase == TouchPhase::Started && (pt.x < 0. || pt.y < 0. || pt.x > self.size.0 || pt.y > self.size.1) {
Expand Down