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: blocking send and ui text tags #467

Merged
merged 2 commits into from
Oct 22, 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
37 changes: 36 additions & 1 deletion lib/src/godot_classes/dcl_ui_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ impl DclUiText {

self.base_mut().set_vertical_alignment(vert_align);
self.base_mut().set_horizontal_alignment(hor_align);
self.base_mut().set_text(new_value.value.clone().into());
self.base_mut()
.set_text(clone_removing_tags(new_value.value.as_str()).into());
self.base_mut()
.set_justification_flags(JustificationFlag::NONE);

Expand All @@ -149,3 +150,37 @@ impl DclUiText {
}
}
}

// temporary fix for removing <b>, </b>, <i>, </i> tags until is supportid
// this is a clone() with avoiding .replace
fn clone_removing_tags(input: &str) -> String {
let mut result = String::with_capacity(input.len());
let mut skip = false;

let mut chars = input.chars().peekable();
while let Some(c) = chars.next() {
if c == '<' {
if let Some(&next_char) = chars.peek() {
if next_char == 'b'
|| next_char == 'i'
|| (next_char == '/' && chars.nth(1) == Some('b'))
|| (next_char == '/' && chars.nth(1) == Some('i'))
{
// Skip until closing '>'
skip = true;
}
}
}

if c == '>' && skip {
skip = false;
continue;
}

if !skip {
result.push(c);
}
}

result
}
11 changes: 4 additions & 7 deletions lib/src/scene_runner/components/audio_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,20 @@ pub fn update_audio_stream(
.set_muted(muted_by_current_scene);

if next_value.playing.unwrap_or(true) {
let _ = audio_stream_data
.1
.command_sender
.blocking_send(AVCommand::Play);
let _ = audio_stream_data.1.command_sender.try_send(AVCommand::Play);
} else {
let _ = audio_stream_data
.1
.command_sender
.blocking_send(AVCommand::Pause);
.try_send(AVCommand::Pause);
}
}
AudioUpdateMode::ChangeAudio => {
if let Some(audio_stream_data) = godot_entity_node.audio_stream.as_ref() {
let _ = audio_stream_data
.1
.command_sender
.blocking_send(AVCommand::Dispose);
.try_send(AVCommand::Dispose);
}

let mut audio_stream_node = node_3d.get_node_or_null("AudioStream".into()).expect(
Expand Down Expand Up @@ -163,7 +160,7 @@ pub fn update_audio_stream(
let _ = audio_stream_data
.1
.command_sender
.blocking_send(AVCommand::Dispose);
.try_send(AVCommand::Dispose);
}

node.audio_stream = None;
Expand Down
19 changes: 1 addition & 18 deletions lib/src/scene_runner/components/ui/scene_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ fn update_layout(
.compute_layout_with_measure(
root_node,
size,
|size, available, node_id, node_context, _style| match node_context {
|size, available, _node_id, node_context, _style| match node_context {
Some(ContextNode::UiText(wrapping, text_node)) => {
let Some(font) = text_node.get_theme_font("font".into()) else {
return taffy::Size::ZERO;
Expand Down Expand Up @@ -220,15 +220,6 @@ fn update_layout(
},
};

tracing::debug!(
"text node {:?}, wrapping {:?}, size: {:?}, font_rect {:?}, available {:?}",
node_id,
*wrapping,
size,
font_rect,
available
);

taffy::Size { width, height }
}
None => taffy::Size::ZERO,
Expand Down Expand Up @@ -265,14 +256,6 @@ fn update_layout(
});
let is_hidden = taffy.style(*key_node).unwrap().display == taffy::style::Display::None;
control.set_visible(!is_hidden);

tracing::debug!(
"node {:?}, entity: {:?}, location: {:?}, size: {:?}",
key_node,
entity,
layout.location,
layout.size
);
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/src/scene_runner/components/video_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ pub fn update_video_player(
let _ = video_player_data
.video_sink
.command_sender
.blocking_send(AVCommand::Play);
.try_send(AVCommand::Play);
} else {
let _ = video_player_data
.video_sink
.command_sender
.blocking_send(AVCommand::Pause);
.try_send(AVCommand::Pause);
}

let _ = video_player_data
.video_sink
.command_sender
.blocking_send(AVCommand::Repeat(next_value.r#loop.unwrap_or(false)));
.try_send(AVCommand::Repeat(next_value.r#loop.unwrap_or(false)));
}
VideoUpdateMode::ChangeVideo => {
if let Some(video_player_data) =
Expand All @@ -131,7 +131,7 @@ pub fn update_video_player(
let _ = video_player_data
.video_sink
.command_sender
.blocking_send(AVCommand::Dispose);
.try_send(AVCommand::Dispose);
}

let mut video_player_node = node_3d.get_node_or_null("VideoPlayer".into()).expect(
Expand Down Expand Up @@ -282,7 +282,7 @@ pub fn update_video_player(
let _ = video_player_data
.video_sink
.command_sender
.blocking_send(AVCommand::Dispose);
.try_send(AVCommand::Dispose);
}

node.video_player_data = None;
Expand Down
Loading