Skip to content

Commit

Permalink
- fixed ide errors
Browse files Browse the repository at this point in the history
- fixed #1
- added crash screen to web version
  • Loading branch information
RealRTTV committed Apr 3, 2024
1 parent e91cfcb commit 2161b6d
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 117 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ native-dialog = "0.7.0"
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2.91"
wasm-bindgen-futures = "0.4.41"
console_error_panic_hook = "0.1.7"
web-sys = { version = "=0.3.67", features = ["console", "Document", "Window", "Element", "Clipboard", "DateTimeValue", "HtmlElement", "HtmlDocument", "HtmlTextAreaElement", "Blob", "HtmlAreaElement", "Url"] }
2 changes: 1 addition & 1 deletion src/bookmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Bookmarks {
}

/// # Safety
/// `inner` must be sorted least to greatest, i.e. it is up to the caller to assure `inner.is_sorted()`
/// `inner` must be sorted least to greatest, i.e.; it is up to the caller to assure `inner.is_sorted()`
#[inline]
pub unsafe fn from_raw(inner: Vec<Bookmark>) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn get_predicate(args: &mut Vec<String>) -> SearchPredicate {
}

fn file_size(path: impl AsRef<Path>) -> Option<u64> {
File::open(path).ok().and_then(|file| file.metadata().ok()).map(|metadata| metadata.len() as u64)
File::open(path).ok().and_then(|file| file.metadata().ok()).map(|metadata| metadata.len())
}

fn increment_progress_bar(completed: &AtomicU64, size: u64, total: u64, action: &str) {
Expand Down
2 changes: 2 additions & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum TextColor {
TreeString,
TreeKey,
TreePrimitive,
Custom(u32),
}

impl TextColor {
Expand All @@ -43,6 +44,7 @@ impl TextColor {
Self::TreeString => 0x7FE9AC,
Self::TreeKey => 0x6EADE2,
Self::TreePrimitive => 0xD19A66,
Self::Custom(value) => value & 0xFFFFFF,
}
}
}
6 changes: 3 additions & 3 deletions src/element_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl ElementAction {
if !open_file(&path.display().to_string()) { break 'm; }
*_subscription = Some(FileUpdateSubscription {
subscription_type,
indices,
indices: indices.clone(),
rx,
watcher,
tab_uuid: _tab_uuid,
Expand Down Expand Up @@ -248,7 +248,7 @@ impl ElementAction {
break 'm;
};
if let Ok(mut file) = OpenOptions::new().write(true).create(true).open(&path) {
if let Some(key) = key
if let Some(key) = key.as_deref()
&& element.id() != NbtChunk::ID
{
if write!(&mut file, "{key}: ").is_err() { break 'm; }
Expand All @@ -259,7 +259,7 @@ impl ElementAction {
if !open_file(&path.display().to_string()) { break 'm; }
*_subscription = Some(FileUpdateSubscription {
subscription_type: FileUpdateSubscriptionType::Snbt,
indices,
indices: indices.clone(),
rx,
watcher,
tab_uuid: _tab_uuid,
Expand Down
28 changes: 13 additions & 15 deletions src/elements/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ impl Clone for NbtRegion {
fn clone(&self) -> Self {
unsafe {
let (map, chunks) = &*self.chunks;
let boxx = alloc(Layout::new::<(Vec<u16>, [NbtElement; 32 * 32])>()).cast::<(Vec<u16>, [NbtElement; 32 * 32])>();
let mapp = alloc(Layout::array::<u16>(map.len()).unwrap_unchecked()).cast::<u16>();
let chunkss = alloc(Layout::array::<NbtElement>(32 * 32).unwrap_unchecked()).cast::<NbtElement>();
map.as_ptr().copy_to_nonoverlapping(mapp, map.len());
let box_ptr = alloc(Layout::new::<(Vec<u16>, [NbtElement; 32 * 32])>()).cast::<(Vec<u16>, [NbtElement; 32 * 32])>();
let map_ptr = alloc(Layout::array::<u16>(map.len()).unwrap_unchecked()).cast::<u16>();
let chunks_ptr = alloc(Layout::array::<NbtElement>(32 * 32).unwrap_unchecked()).cast::<NbtElement>();
map.as_ptr().copy_to_nonoverlapping(map_ptr, map.len());
for n in 0..1024 {
chunkss.add(n).write(chunks.get_unchecked(n).clone());
chunks_ptr.add(n).write(chunks.get_unchecked(n).clone());
}
boxx.write((
Vec::from_raw_parts(mapp, map.len(), map.len()),
chunkss.cast::<[NbtElement; 32 * 32]>().read(),
box_ptr.write((
Vec::from_raw_parts(map_ptr, map.len(), map.len()),
chunks_ptr.cast::<[NbtElement; 32 * 32]>().read(),
));

Self {
chunks: Box::from_raw(boxx),
chunks: Box::from_raw(box_ptr),
height: self.height,
true_height: self.true_height,
max_depth: self.max_depth,
Expand Down Expand Up @@ -337,7 +337,7 @@ impl NbtRegion {
///
/// * `value` must be variant `NbtElement::Chunk`
///
/// * `self.map` must not contain a chunk in this `pos` already
/// * `self.map` must not contain a chunk in this `pos` yet
///
/// * `pos` is between 0..=1023
#[inline]
Expand Down Expand Up @@ -450,7 +450,6 @@ impl NbtRegion {
|key, value| key.parse::<u8>().ok() == x.parse::<u8>().ok() && value.is_some_and(|value| value.parse::<u8>().ok() == z.parse::<u8>().ok()),
true,
);
// first check required so this don't render when it's the only selected
let y2 = y.saturating_sub(remaining_scroll * 16);
if y2 != ctx.selected_y && y2 >= HEADER_SIZE && ctx.key_duplicate_error {
ctx.red_line_numbers[1] = y2;
Expand Down Expand Up @@ -745,10 +744,10 @@ impl Clone for NbtChunk {
#[inline]
fn clone(&self) -> Self {
unsafe {
let boxx = alloc(Layout::new::<NbtCompound>()).cast::<NbtCompound>();
boxx.write(self.inner.deref().clone());
let box_ptr = alloc(Layout::new::<NbtCompound>()).cast::<NbtCompound>();
box_ptr.write(self.inner.deref().clone());
Self {
inner: Box::from_raw(boxx),
inner: Box::from_raw(box_ptr),
last_modified: self.last_modified,
compression: self.compression,
x: self.x,
Expand Down Expand Up @@ -859,7 +858,6 @@ impl NbtChunk {
let mut y = ctx.y_offset;
for (name, value) in self.children() {
ctx.check_for_key_duplicate(|text, _| text == name, false);
// first check required so this don't render when it's the only selected
if y.saturating_sub(*remaining_scroll * 16) != ctx.selected_y && y.saturating_sub(*remaining_scroll * 16) >= HEADER_SIZE && ctx.key_duplicate_error {
ctx.red_line_numbers[1] = y.saturating_sub(*remaining_scroll * 16);
ctx.draw_error_underline(
Expand Down
10 changes: 4 additions & 6 deletions src/elements/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ impl Clone for NbtCompound {
#[allow(clippy::cast_ptr_alignment)]
fn clone(&self) -> Self {
unsafe {
let boxx = alloc(Layout::new::<CompoundMap>()).cast::<CompoundMap>();
boxx.write(self.entries.deref().clone());
let box_ptr = alloc(Layout::new::<CompoundMap>()).cast::<CompoundMap>();
box_ptr.write(self.entries.deref().clone());
Self {
entries: Box::from_raw(boxx),
entries: Box::from_raw(box_ptr),
height: self.height,
true_height: self.true_height,
max_depth: self.max_depth,
Expand Down Expand Up @@ -285,7 +285,6 @@ impl NbtCompound {
let mut y = ctx.y_offset;
for (name, value) in self.children() {
ctx.check_for_key_duplicate(|text, _| text == name, false);
// first check required so this don't render when it's the only selected
if y.saturating_sub(remaining_scroll * 16) != ctx.selected_y && y.saturating_sub(remaining_scroll * 16) >= HEADER_SIZE && ctx.key_duplicate_error {
ctx.red_line_numbers[1] = y.saturating_sub(remaining_scroll * 16);
ctx.draw_error_underline(
Expand Down Expand Up @@ -487,7 +486,6 @@ impl NbtCompound {
let mut y = ctx.y_offset;
for (name, value) in self.children() {
ctx.check_for_key_duplicate(|text, _| text == name, false);
// first check required so this don't render when it's the only selected
if y.saturating_sub(*remaining_scroll * 16) != ctx.selected_y && y.saturating_sub(*remaining_scroll * 16) >= HEADER_SIZE && ctx.key_duplicate_error {
ctx.red_line_numbers[1] = y.saturating_sub(*remaining_scroll * 16);
ctx.draw_error_underline(
Expand Down Expand Up @@ -1012,7 +1010,7 @@ impl CompoundMap {
};
let mut new_bookmarks = Box::<[Bookmark]>::new_uninit_slice(bookmarks[true_line_number..true_line_number + true_height].len());
let mut new_bookmarks_len = 0;
// yeah, it's hacky but there's not much else I *can* do. plus: it works extremely well.
// yeah, it's hacky... but there's not much else I *can* do. plus: it works extremely well.
for (idx, entry) in self.entries.iter_mut().enumerate() {
entry.hash = idx as u64;
}
Expand Down
Loading

0 comments on commit 2161b6d

Please sign in to comment.