mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Hacking
This commit is contained in:
parent
1a2ee07d37
commit
4df3f7f1ff
12 changed files with 86 additions and 83 deletions
|
|
@ -50,4 +50,4 @@ fn main() {
|
|||
process::exit(1);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,4 +13,4 @@ pub fn init(project_path: &PathBuf) {
|
|||
process::exit(1);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,4 +2,4 @@ mod serve;
|
|||
mod init;
|
||||
|
||||
pub use self::serve::*;
|
||||
pub use self::init::*;
|
||||
pub use self::init::*;
|
||||
|
|
@ -33,4 +33,4 @@ pub fn serve(fuzzy_project_location: &Path) {
|
|||
// let web_config = WebConfig::from_session(server_id, port, &session);
|
||||
|
||||
// web::start(web_config);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,4 +18,4 @@ fn it_gives_unique_numbers() {
|
|||
let b = get_id();
|
||||
|
||||
assert!(a != b);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,6 @@ pub mod message_session;
|
|||
pub mod pathext;
|
||||
pub mod project;
|
||||
pub mod rbx;
|
||||
// pub mod web;
|
||||
pub mod web;
|
||||
pub mod web_util;
|
||||
pub mod roblox_studio;
|
||||
pub mod roblox_studio;
|
||||
|
|
@ -61,4 +61,4 @@ impl MessageSession {
|
|||
pub fn get_message_cursor(&self) -> i32 {
|
||||
self.messages.read().unwrap().len() as i32 - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,4 +24,4 @@ where
|
|||
} else {
|
||||
root.join(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use id::Id;
|
||||
|
|
@ -23,18 +22,44 @@ pub struct RbxInstance {
|
|||
/// Contains all other properties of an Instance.
|
||||
pub properties: HashMap<String, RbxValue>,
|
||||
|
||||
/// The unique ID of the instance
|
||||
id: Id,
|
||||
|
||||
/// All of the children of this instance. Order is relevant to preserve!
|
||||
pub children: Vec<Id>,
|
||||
children: Vec<Id>,
|
||||
|
||||
/// The parent of the instance, if there is one.
|
||||
pub parent: Option<Id>,
|
||||
parent: Option<Id>,
|
||||
}
|
||||
|
||||
// This seems like a really bad idea?
|
||||
// Why isn't there a blanket impl for this for all T?
|
||||
impl<'a> From<&'a RbxInstance> for Cow<'a, RbxInstance> {
|
||||
fn from(instance: &'a RbxInstance) -> Cow<'a, RbxInstance> {
|
||||
Cow::Borrowed(instance)
|
||||
pub struct Descendants<'a> {
|
||||
tree: &'a RbxTree,
|
||||
ids_to_visit: Vec<Id>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for Descendants<'a> {
|
||||
type Item = &'a RbxInstance;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
loop {
|
||||
let id = match self.ids_to_visit.pop() {
|
||||
Some(id) => id,
|
||||
None => break,
|
||||
};
|
||||
|
||||
match self.tree.get_instance(id) {
|
||||
Some(instance) => {
|
||||
for child_id in &instance.children {
|
||||
self.ids_to_visit.push(*child_id);
|
||||
}
|
||||
|
||||
return Some(instance);
|
||||
},
|
||||
None => continue,
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,20 +74,29 @@ impl RbxTree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_instance(&self, id: Id) -> Option<&RbxInstance> {
|
||||
self.instances.get(&id)
|
||||
}
|
||||
|
||||
pub fn get_all_instances(&self) -> &HashMap<Id, RbxInstance> {
|
||||
&self.instances
|
||||
}
|
||||
|
||||
pub fn insert_instance(&mut self, id: Id, instance: RbxInstance) {
|
||||
pub fn insert_instance(&mut self, instance: RbxInstance) {
|
||||
if let Some(parent_id) = instance.parent {
|
||||
if let Some(mut parent) = self.instances.get_mut(&parent_id) {
|
||||
if !parent.children.contains(&id) {
|
||||
parent.children.push(id);
|
||||
match self.instances.get_mut(&parent_id) {
|
||||
Some(mut parent) => {
|
||||
if !parent.children.contains(&instance.id) {
|
||||
parent.children.push(instance.id);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
panic!("Tree consistency error, parent {} was not present in tree.", parent_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.instances.insert(id, instance);
|
||||
self.instances.insert(instance.id, instance);
|
||||
}
|
||||
|
||||
pub fn delete_instance(&mut self, id: Id) -> Vec<Id> {
|
||||
|
|
@ -101,27 +135,10 @@ impl RbxTree {
|
|||
ids_deleted
|
||||
}
|
||||
|
||||
pub fn get_instance_and_descendants<'a, 'b, T>(&'a self, id: Id, output: &'b mut HashMap<Id, T>)
|
||||
where T: From<&'a RbxInstance>
|
||||
{
|
||||
let mut ids_to_visit = vec![id];
|
||||
|
||||
loop {
|
||||
let id = match ids_to_visit.pop() {
|
||||
Some(id) => id,
|
||||
None => break,
|
||||
};
|
||||
|
||||
match self.instances.get(&id) {
|
||||
Some(instance) => {
|
||||
output.insert(id, instance.into());
|
||||
|
||||
for child_id in &instance.children {
|
||||
ids_to_visit.push(*child_id);
|
||||
}
|
||||
},
|
||||
None => continue,
|
||||
}
|
||||
pub fn iter_descendants<'a>(&'a self, id: Id) -> Descendants<'a> {
|
||||
Descendants {
|
||||
tree: self,
|
||||
ids_to_visit: vec![id],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,37 +8,25 @@ use id::Id;
|
|||
use message_session::{MessageSession, Message};
|
||||
use project::Project;
|
||||
use rbx::RbxInstance;
|
||||
use rbx_session::RbxSession;
|
||||
use session::Session;
|
||||
// use rbx_session::RbxSession;
|
||||
// use session::Session;
|
||||
|
||||
/// The set of configuration the web server needs to start.
|
||||
pub struct WebConfig {
|
||||
pub port: u64,
|
||||
pub project: Project,
|
||||
pub server_id: u64,
|
||||
pub rbx_session: Arc<RwLock<RbxSession>>,
|
||||
// pub rbx_session: Arc<RwLock<RbxSession>>,
|
||||
pub message_session: MessageSession,
|
||||
}
|
||||
|
||||
impl WebConfig {
|
||||
pub fn from_session(server_id: u64, port: u64, session: &Session) -> WebConfig {
|
||||
WebConfig {
|
||||
port,
|
||||
server_id,
|
||||
project: session.project.clone(),
|
||||
rbx_session: session.get_rbx_session(),
|
||||
message_session: session.get_message_session(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ServerInfoResponse<'a> {
|
||||
pub server_id: &'a str,
|
||||
pub server_version: &'a str,
|
||||
pub protocol_version: u64,
|
||||
pub partitions: HashMap<String, Vec<String>>,
|
||||
// pub partitions: HashMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
@ -46,8 +34,8 @@ pub struct ServerInfoResponse<'a> {
|
|||
pub struct ReadAllResponse<'a> {
|
||||
pub server_id: &'a str,
|
||||
pub message_cursor: i32,
|
||||
pub instances: Cow<'a, HashMap<Id, RbxInstance>>,
|
||||
pub partition_instances: Cow<'a, HashMap<String, Id>>,
|
||||
// pub instances: Cow<'a, HashMap<Id, RbxInstance>>,
|
||||
// pub partition_instances: Cow<'a, HashMap<String, Id>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
@ -55,7 +43,7 @@ pub struct ReadAllResponse<'a> {
|
|||
pub struct ReadResponse<'a> {
|
||||
pub server_id: &'a str,
|
||||
pub message_cursor: i32,
|
||||
pub instances: HashMap<Id, Cow<'a, RbxInstance>>,
|
||||
// pub instances: HashMap<Id, Cow<'a, RbxInstance>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
@ -90,17 +78,17 @@ impl Server {
|
|||
(GET) (/api/rojo) => {
|
||||
// Get a summary of information about the server.
|
||||
|
||||
let mut partitions = HashMap::new();
|
||||
// let mut partitions = HashMap::new();
|
||||
|
||||
for partition in self.config.project.partitions.values() {
|
||||
partitions.insert(partition.name.clone(), partition.target.clone());
|
||||
}
|
||||
// for partition in self.config.project.partitions.values() {
|
||||
// partitions.insert(partition.name.clone(), partition.target.clone());
|
||||
// }
|
||||
|
||||
Response::json(&ServerInfoResponse {
|
||||
server_version: self.server_version,
|
||||
protocol_version: 2,
|
||||
server_id: &self.server_id,
|
||||
partitions: partitions,
|
||||
// partitions: partitions,
|
||||
})
|
||||
},
|
||||
|
||||
|
|
@ -157,15 +145,15 @@ impl Server {
|
|||
},
|
||||
|
||||
(GET) (/api/read_all) => {
|
||||
let rbx_session = self.config.rbx_session.read().unwrap();
|
||||
// let rbx_session = self.config.rbx_session.read().unwrap();
|
||||
|
||||
let message_cursor = self.config.message_session.get_message_cursor();
|
||||
|
||||
Response::json(&ReadAllResponse {
|
||||
server_id: &self.server_id,
|
||||
message_cursor,
|
||||
instances: Cow::Borrowed(rbx_session.tree.get_all_instances()),
|
||||
partition_instances: Cow::Borrowed(&rbx_session.partition_instances),
|
||||
// instances: Cow::Borrowed(rbx_session.tree.get_all_instances()),
|
||||
// partition_instances: Cow::Borrowed(&rbx_session.partition_instances),
|
||||
})
|
||||
},
|
||||
|
||||
|
|
@ -180,20 +168,20 @@ impl Server {
|
|||
Err(_) => return rouille::Response::text("Malformed ID list").with_status_code(400),
|
||||
};
|
||||
|
||||
let rbx_session = self.config.rbx_session.read().unwrap();
|
||||
// let rbx_session = self.config.rbx_session.read().unwrap();
|
||||
|
||||
let message_cursor = self.config.message_session.get_message_cursor();
|
||||
|
||||
let mut instances = HashMap::new();
|
||||
// let mut instances = HashMap::new();
|
||||
|
||||
for requested_id in &requested_ids {
|
||||
rbx_session.tree.get_instance_and_descendants(*requested_id, &mut instances);
|
||||
}
|
||||
// for requested_id in &requested_ids {
|
||||
// rbx_session.tree.get_instance_and_descendants(*requested_id, &mut instances);
|
||||
// }
|
||||
|
||||
Response::json(&ReadResponse {
|
||||
server_id: &self.server_id,
|
||||
message_cursor,
|
||||
instances,
|
||||
// instances,
|
||||
})
|
||||
},
|
||||
|
||||
|
|
@ -209,4 +197,4 @@ pub fn start(config: WebConfig) {
|
|||
let server = Server::new(config);
|
||||
|
||||
rouille::start_server(address, move |request| server.handle_request(request));
|
||||
}
|
||||
}
|
||||
|
|
@ -40,4 +40,4 @@ where
|
|||
{
|
||||
let body = read_json_text(&request)?;
|
||||
serde_json::from_str(&body).ok()?
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ extern crate librojo;
|
|||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use librojo::{
|
||||
|
|
@ -13,9 +13,7 @@ use librojo::{
|
|||
|
||||
lazy_static! {
|
||||
static ref TEST_PROJECTS_ROOT: PathBuf = {
|
||||
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
path.push("../test-projects");
|
||||
path
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("../test-projects")
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue