Skip to content

Commit

Permalink
General fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
DervexDev committed Apr 8, 2024
1 parent 561cfd5 commit e138d58
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
ref: main

- name: Update Changelog
uses: thomaseizinger/keep-a-changelog-new-release@v2
uses: thomaseizinger/keep-a-changelog-new-release@v3
with:
tag: ${{ github.ref_name }}

Expand Down
6 changes: 5 additions & 1 deletion src/core/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use rbx_dom_weak::types::{Ref, Variant};
use serde::Serialize;
use std::collections::HashMap;

use super::snapshot::Snapshot;
use super::{meta::Meta, snapshot::Snapshot};

#[derive(Debug, Clone, Serialize)]
pub struct AddedSnapshot {
pub id: Ref,
pub meta: Meta,
pub parent: Ref,
pub name: String,
pub class: String,
Expand All @@ -17,6 +18,7 @@ pub struct AddedSnapshot {
#[derive(Debug, Clone, Serialize)]
pub struct UpdatedSnapshot {
pub id: Ref,
pub meta: Option<Meta>,
pub name: Option<String>,
pub class: Option<String>,
pub properties: Option<HashMap<String, Variant>>,
Expand All @@ -29,6 +31,7 @@ impl UpdatedSnapshot {
name: None,
class: None,
properties: None,
meta: None,
}
}

Expand Down Expand Up @@ -61,6 +64,7 @@ impl Changes {
class: snapshot.class,
properties: snapshot.properties,
children: snapshot.children,
meta: snapshot.meta,
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/core/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,14 @@ impl Context {
}
}

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Meta {
/// Instance source that is guaranteed to exist
#[serde(skip)]
pub source: Source,
/// Project context
#[serde(skip)]
pub context: Context,
/// Whether to keep unknown child instances
pub keep_unknowns: bool,
Expand Down
20 changes: 10 additions & 10 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
fs::File,
io::BufWriter,
path::{Path, PathBuf},
sync::{Arc, Mutex},
sync::{Arc, Mutex, MutexGuard},
};

use self::{
Expand Down Expand Up @@ -85,18 +85,14 @@ impl Core {
lock!(self.project).port
}

pub fn game_id(&self) -> Option<u64> {
lock!(self.project).game_id
}

pub fn place_ids(&self) -> Vec<u64> {
lock!(self.project).place_ids.clone()
}

pub fn queue(&self) -> Arc<Queue> {
self.queue.clone()
}

pub fn project(&self) -> MutexGuard<'_, Project> {
lock!(self.project)
}

/// Create snapshot of the tree
pub fn snapshot(&self) -> Snapshot {
let tree = lock!(self.tree);
Expand All @@ -105,14 +101,16 @@ impl Core {
let mut snapshot_children = vec![];

for child in children {
let meta = tree.get_meta(*child).unwrap();
let child = tree.get_instance(*child).unwrap();

let snapshot = Snapshot::new()
.with_id(child.referent())
.with_name(&child.name)
.with_class(&child.class)
.with_properties(child.properties.clone())
.with_children(walk(child.children(), tree));
.with_children(walk(child.children(), tree))
.with_meta(meta.clone());

snapshot_children.push(snapshot);
}
Expand All @@ -121,13 +119,15 @@ impl Core {
}

let root = tree.root();
let meta = tree.get_meta(root.referent()).unwrap();

Snapshot::new()
.with_id(root.referent())
.with_name(&root.name)
.with_class(&root.class)
.with_properties(root.properties.clone())
.with_children(walk(tree.root().children(), &tree))
.with_meta(meta.clone())
}

/// Build the tree into a file, either XML or binary
Expand Down
15 changes: 12 additions & 3 deletions src/core/processor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crossbeam_channel::select;
use log::{debug, error, info, trace};
use log::{debug, error, info, trace, warn};
use rbx_dom_weak::types::Ref;
use std::{
sync::{Arc, Mutex},
Expand All @@ -16,7 +16,7 @@ use super::{
use crate::{
argon_error, lock, messages,
middleware::{new_snapshot, project::snapshot_node},
project::Project,
project::{Project, ProjectDetails},
stats, util,
vfs::{Vfs, VfsEvent},
BLACKLISTED_PATHS,
Expand Down Expand Up @@ -79,7 +79,16 @@ impl Handler {
debug!("Project file was modified. Reloading project..");

match lock!(self.project).reload() {
Ok(()) => info!("Project reloaded"),
Ok(project) => {
info!("Project reloaded");

let details = messages::SyncDetails(ProjectDetails::from(project));

match self.queue.push(details, None) {
Ok(()) => trace!("Project details synced"),
Err(err) => warn!("Failed to sync project details: {}", err),
}
}
Err(err) => error!("Failed to reload project: {}", err),
}
} else if let VfsEvent::Delete(_) = event {
Expand Down
1 change: 0 additions & 1 deletion src/core/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use super::meta::Meta;
#[derive(Clone, Serialize)]
pub struct Snapshot {
pub id: Ref,
#[serde(skip)]
pub meta: Meta,

// Roblox related
Expand Down
8 changes: 2 additions & 6 deletions src/messages.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use derive_from_one::FromOne;
use serde::Serialize;

use crate::core::changes::Changes;
use crate::{core::changes::Changes, project::ProjectDetails};

#[derive(Debug, Clone, Serialize, FromOne)]
pub enum Message {
Expand All @@ -14,11 +14,7 @@ pub enum Message {
pub struct SyncChanges(pub Changes);

#[derive(Debug, Clone, Serialize)]
pub struct SyncDetails {
pub name: String,
pub game_id: Option<u64>,
pub place_ids: Option<Vec<u64>>,
}
pub struct SyncDetails(pub ProjectDetails);

#[derive(Debug, Clone, Serialize)]
pub struct ExecuteCode {
Expand Down
24 changes: 22 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ impl Project {
Ok(project)
}

pub fn reload(&mut self) -> Result<()> {
pub fn reload(&mut self) -> Result<&Self> {
let new = Self::load(&self.path)?;

drop(mem::replace(self, new));

Ok(())
Ok(self)
}

pub fn is_place(&self) -> bool {
Expand Down Expand Up @@ -139,3 +139,23 @@ pub fn resolve(path: PathBuf) -> Result<PathBuf> {
Ok(path.join("default.project.json"))
}
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProjectDetails {
version: String,
name: String,
game_id: Option<u64>,
place_ids: Vec<u64>,
}

impl From<&Project> for ProjectDetails {
fn from(project: &Project) -> Self {
Self {
version: env!("CARGO_PKG_VERSION").to_owned(),
name: project.name.clone(),
game_id: project.game_id,
place_ids: project.place_ids.clone(),
}
}
}
21 changes: 4 additions & 17 deletions src/server/details.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
use actix_msgpack::MsgPackResponseBuilder;
use actix_web::{get, web::Data, HttpResponse, Responder};
use serde::Serialize;
use std::sync::Arc;
use std::{ops::Deref, sync::Arc};

use crate::core::Core;
use crate::{core::Core, project::ProjectDetails};

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct Response {
version: String,
name: String,
game_id: Option<u64>,
place_ids: Vec<u64>,
}
struct Response(ProjectDetails);

#[get("/details")]
async fn main(core: Data<Arc<Core>>) -> impl Responder {
let response = Response {
version: env!("CARGO_PKG_VERSION").to_string(),
name: core.name(),
game_id: core.game_id(),
place_ids: core.place_ids(),
};

HttpResponse::Ok().msgpack(response)
HttpResponse::Ok().msgpack(Response(ProjectDetails::from(core.project().deref())))
}
1 change: 0 additions & 1 deletion src/server/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct Request {
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct Response(Option<Message>);

#[get("/read")]
Expand Down
1 change: 0 additions & 1 deletion src/server/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::sync::Arc;
use crate::core::{snapshot::Snapshot, Core};

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct Response(Snapshot);

#[get("/snapshot")]
Expand Down

0 comments on commit e138d58

Please sign in to comment.