Update rbx-dom (#1023)

This commit is contained in:
Micah
2025-04-02 11:32:27 -07:00
committed by GitHub
parent 0d6ff8ef8a
commit 833320de64
30 changed files with 8815 additions and 2249 deletions

View File

@@ -2,6 +2,7 @@ use std::{collections::BTreeMap, path::Path};
use anyhow::Context;
use memofs::{IoResultExt, Vfs};
use rbx_dom_weak::ustr;
use serde::Serialize;
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
@@ -30,7 +31,7 @@ pub fn snapshot_csv(
let mut snapshot = InstanceSnapshot::new()
.name(name)
.class_name("LocalizationTable")
.properties([("Contents".to_owned(), table_contents.into())])
.property(ustr("Contents"), table_contents)
.metadata(
InstanceMetadata::new()
.instigating_source(path)

View File

@@ -2,6 +2,7 @@ use std::path::Path;
use anyhow::Context;
use memofs::{IoResultExt, Vfs};
use rbx_dom_weak::ustr;
use crate::{
lua_ast::{Expression, Statement},
@@ -23,14 +24,12 @@ pub fn snapshot_json(
let as_lua = json_to_lua(value).to_string();
let properties = [("Source".to_owned(), as_lua.into())];
let meta_path = path.with_file_name(format!("{}.meta.json", name));
let mut snapshot = InstanceSnapshot::new()
.name(name)
.class_name("ModuleScript")
.properties(properties)
.property(ustr("Source"), as_lua)
.metadata(
InstanceMetadata::new()
.instigating_source(path)

View File

@@ -2,7 +2,10 @@ use std::{borrow::Cow, collections::HashMap, path::Path, str};
use anyhow::Context;
use memofs::Vfs;
use rbx_dom_weak::types::{Attributes, Ref};
use rbx_dom_weak::{
types::{Attributes, Ref},
HashMapExt as _, Ustr, UstrMap,
};
use serde::Deserialize;
use crate::{
@@ -68,7 +71,7 @@ struct JsonModel {
name: Option<String>,
#[serde(alias = "ClassName")]
class_name: String,
class_name: Ustr,
#[serde(skip_serializing_if = "Option::is_none")]
id: Option<String>,
@@ -82,10 +85,10 @@ struct JsonModel {
#[serde(
alias = "Properties",
default = "HashMap::new",
default = "UstrMap::new",
skip_serializing_if = "HashMap::is_empty"
)]
properties: HashMap<String, UnresolvedValue>,
properties: UstrMap<UnresolvedValue>,
#[serde(default = "HashMap::new", skip_serializing_if = "HashMap::is_empty")]
attributes: HashMap<String, UnresolvedValue>,
@@ -93,7 +96,7 @@ struct JsonModel {
impl JsonModel {
fn into_snapshot(self) -> anyhow::Result<InstanceSnapshot> {
let name = self.name.unwrap_or_else(|| self.class_name.clone());
let name = self.name.unwrap_or_else(|| self.class_name.to_owned());
let class_name = self.class_name;
let mut children = Vec::with_capacity(self.children.len());
@@ -101,7 +104,7 @@ impl JsonModel {
children.push(child.into_snapshot()?);
}
let mut properties = HashMap::with_capacity(self.properties.len());
let mut properties = UstrMap::with_capacity(self.properties.len());
for (key, unresolved) in self.properties {
let value = unresolved.resolve(&class_name, &key)?;
properties.insert(key, value);
@@ -122,7 +125,7 @@ impl JsonModel {
snapshot_id: Ref::none(),
metadata: Default::default(),
name: Cow::Owned(name),
class_name: Cow::Owned(class_name),
class_name,
properties,
children,
})

View File

@@ -1,7 +1,7 @@
use std::{collections::HashMap, path::Path, str};
use std::{path::Path, str};
use memofs::{IoResultExt, Vfs};
use rbx_dom_weak::types::Enum;
use rbx_dom_weak::{types::Enum, ustr, HashMapExt as _, UstrMap};
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
@@ -42,12 +42,12 @@ pub fn snapshot_lua(
let contents = vfs.read_to_string_lf_normalized(path)?;
let contents_str = contents.as_str();
let mut properties = HashMap::with_capacity(2);
properties.insert("Source".to_owned(), contents_str.into());
let mut properties = UstrMap::with_capacity(2);
properties.insert(ustr("Source"), contents_str.into());
if let Some(run_context) = run_context {
properties.insert(
"RunContext".to_owned(),
ustr("RunContext"),
Enum::from_u32(run_context.to_owned()).into(),
);
}

View File

@@ -1,7 +1,7 @@
use std::{borrow::Cow, collections::HashMap, path::PathBuf};
use std::{collections::HashMap, path::PathBuf};
use anyhow::{format_err, Context};
use rbx_dom_weak::types::Attributes;
use rbx_dom_weak::{types::Attributes, Ustr, UstrMap};
use serde::{Deserialize, Serialize};
use crate::{resolution::UnresolvedValue, snapshot::InstanceSnapshot, RojoRef};
@@ -23,7 +23,7 @@ pub struct AdjacentMetadata {
pub ignore_unknown_instances: Option<bool>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub properties: HashMap<String, UnresolvedValue>,
pub properties: UstrMap<UnresolvedValue>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub attributes: HashMap<String, UnresolvedValue>,
@@ -117,13 +117,13 @@ pub struct DirectoryMetadata {
pub ignore_unknown_instances: Option<bool>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub properties: HashMap<String, UnresolvedValue>,
pub properties: UstrMap<UnresolvedValue>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub attributes: HashMap<String, UnresolvedValue>,
#[serde(skip_serializing_if = "Option::is_none")]
pub class_name: Option<String>,
pub class_name: Option<Ustr>,
#[serde(skip)]
pub path: PathBuf,
@@ -161,7 +161,7 @@ impl DirectoryMetadata {
));
}
snapshot.class_name = Cow::Owned(class_name);
snapshot.class_name = class_name;
}
Ok(())

View File

@@ -1,8 +1,11 @@
use std::{borrow::Cow, collections::HashMap, path::Path};
use std::{borrow::Cow, path::Path};
use anyhow::{bail, Context};
use memofs::Vfs;
use rbx_dom_weak::types::{Attributes, Ref};
use rbx_dom_weak::{
types::{Attributes, Ref},
ustr, HashMapExt as _, Ustr, UstrMap,
};
use rbx_reflection::ClassTag;
use crate::{
@@ -88,14 +91,10 @@ pub fn snapshot_project_node(
) -> anyhow::Result<Option<InstanceSnapshot>> {
let project_folder = project_path.parent().unwrap();
let class_name_from_project = node
.class_name
.as_ref()
.map(|name| Cow::Owned(name.clone()));
let mut class_name_from_path = None;
let name = Cow::Owned(instance_name.to_owned());
let mut properties = HashMap::new();
let mut properties = UstrMap::new();
let mut children = Vec::new();
let mut metadata = InstanceMetadata::new().context(context);
@@ -136,7 +135,7 @@ pub fn snapshot_project_node(
let class_name_from_inference = infer_class_name(&name, parent_class);
let class_name = match (
class_name_from_project,
node.class_name,
class_name_from_path,
class_name_from_inference,
&node.path,
@@ -249,7 +248,7 @@ pub fn snapshot_project_node(
_ => {}
}
properties.insert(key.clone(), value);
properties.insert(*key, value);
}
if !node.attributes.is_empty() {
@@ -304,7 +303,7 @@ pub fn snapshot_project_node(
}))
}
fn infer_class_name(name: &str, parent_class: Option<&str>) -> Option<Cow<'static, str>> {
fn infer_class_name(name: &str, parent_class: Option<&str>) -> Option<Ustr> {
// If className wasn't defined from another source, we may be able
// to infer one.
@@ -317,18 +316,18 @@ fn infer_class_name(name: &str, parent_class: Option<&str>) -> Option<Cow<'stati
let descriptor = rbx_reflection_database::get().classes.get(name)?;
if descriptor.tags.contains(&ClassTag::Service) {
return Some(Cow::Owned(name.to_owned()));
return Some(ustr(name));
}
} else if parent_class == "StarterPlayer" {
// StarterPlayer has two special members with their own classes.
if name == "StarterPlayerScripts" || name == "StarterCharacterScripts" {
return Some(Cow::Owned(name.to_owned()));
return Some(ustr(name));
}
} else if parent_class == "Workspace" {
// Workspace has a special Terrain class inside it
if name == "Terrain" {
return Some(Cow::Owned(name.to_owned()));
return Some(ustr(name));
}
}

View File

@@ -2,6 +2,7 @@ use std::path::Path;
use anyhow::Context;
use memofs::{IoResultExt, Vfs};
use rbx_dom_weak::ustr;
use crate::{
lua_ast::{Expression, Statement},
@@ -23,14 +24,12 @@ pub fn snapshot_toml(
let as_lua = toml_to_lua(value).to_string();
let properties = [("Source".to_owned(), as_lua.into())];
let meta_path = path.with_file_name(format!("{}.meta.json", name));
let mut snapshot = InstanceSnapshot::new()
.name(name)
.class_name("ModuleScript")
.properties(properties)
.property(ustr("Source"), as_lua)
.metadata(
InstanceMetadata::new()
.instigating_source(path)

View File

@@ -1,6 +1,7 @@
use std::{path::Path, str};
use memofs::{IoResultExt, Vfs};
use rbx_dom_weak::ustr;
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
@@ -15,14 +16,12 @@ pub fn snapshot_txt(
let contents = vfs.read_to_string(path)?;
let contents_str = contents.as_str();
let properties = [("Value".to_owned(), contents_str.into())];
let meta_path = path.with_file_name(format!("{}.meta.json", name));
let mut snapshot = InstanceSnapshot::new()
.name(name)
.class_name("StringValue")
.properties(properties)
.property(ustr("Value"), contents_str)
.metadata(
InstanceMetadata::new()
.instigating_source(path)