mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-22 13:45:16 +00:00
Upgrade to rbx_dom_weak 2.0 (#377)
* Mostly mechanical port bits * Almost there * It builds again! * Turn on all the code again * Tests compiling but not passing * Stub work for value resolution * Implement resolution minus enums and derived properties * Implement property descriptor resolution * Update referent snapshots * Update unions test project Using a place file instead of a model yields better error messages in Roblox Studio. * Add easy shortcut to testing with local rbx-dom * Update rbx-dom * Add enum resolution * Update init.meta.json to use UnresolvedValue * Expand value resolution support, add test * Filter SharedString values from web API * Add 'property' builder method to InstanceSnapshot * Change InstanceSnapshot/InstanceBuilder boundary * Fix remove_file crash * rustfmt * Update to latest rbx_dom_lua * Update dependencies, including rbx_dom_weak * Update to latest rbx-dom * Update dependencies * Update rbx-dom, fixing more bugs * Remove experimental warning on binary place builds * Remove unused imports
This commit is contained in:
committed by
GitHub
parent
b84aab0960
commit
59ef5f05ea
@@ -2,7 +2,10 @@
|
||||
|
||||
use std::{borrow::Cow, collections::HashMap};
|
||||
|
||||
use rbx_dom_weak::{RbxId, RbxTree, RbxValue};
|
||||
use rbx_dom_weak::{
|
||||
types::{Ref, Variant},
|
||||
WeakDom,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::InstanceMetadata;
|
||||
@@ -11,11 +14,12 @@ use super::InstanceMetadata;
|
||||
///
|
||||
// Possible future improvements:
|
||||
// - Use refcounted/interned strings
|
||||
// - Replace use of RbxValue with a sum of RbxValue + borrowed value
|
||||
// - Replace use of Variant with a sum of Variant + borrowed value
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct InstanceSnapshot {
|
||||
// FIXME: Don't use Option<Ref> anymore!
|
||||
/// A temporary ID applied to the snapshot that's used for Ref properties.
|
||||
pub snapshot_id: Option<RbxId>,
|
||||
pub snapshot_id: Option<Ref>,
|
||||
|
||||
/// Rojo-specific metadata associated with the instance.
|
||||
pub metadata: InstanceMetadata,
|
||||
@@ -27,7 +31,7 @@ pub struct InstanceSnapshot {
|
||||
pub class_name: Cow<'static, str>,
|
||||
|
||||
/// All other properties of the instance, weakly-typed.
|
||||
pub properties: HashMap<String, RbxValue>,
|
||||
pub properties: HashMap<String, Variant>,
|
||||
|
||||
/// The children of the instance represented as more snapshots.
|
||||
///
|
||||
@@ -61,7 +65,16 @@ impl InstanceSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn properties(self, properties: impl Into<HashMap<String, RbxValue>>) -> Self {
|
||||
pub fn property<K, V>(mut self, key: K, value: V) -> Self
|
||||
where
|
||||
K: Into<String>,
|
||||
V: Into<Variant>,
|
||||
{
|
||||
self.properties.insert(key.into(), value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn properties(self, properties: impl Into<HashMap<String, Variant>>) -> Self {
|
||||
Self {
|
||||
properties: properties.into(),
|
||||
..self
|
||||
@@ -75,6 +88,13 @@ impl InstanceSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn snapshot_id(self, snapshot_id: Option<Ref>) -> Self {
|
||||
Self {
|
||||
snapshot_id,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metadata(self, metadata: impl Into<InstanceMetadata>) -> Self {
|
||||
Self {
|
||||
metadata: metadata.into(),
|
||||
@@ -82,15 +102,13 @@ impl InstanceSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_tree(tree: &RbxTree, id: RbxId) -> Self {
|
||||
let instance = tree
|
||||
.get_instance(id)
|
||||
.expect("instance did not exist in tree");
|
||||
pub fn from_tree(tree: &WeakDom, id: Ref) -> Self {
|
||||
let instance = tree.get_by_ref(id).expect("instance did not exist in tree");
|
||||
|
||||
let children = instance
|
||||
.get_children_ids()
|
||||
.children()
|
||||
.iter()
|
||||
.cloned()
|
||||
.copied()
|
||||
.map(|id| Self::from_tree(tree, id))
|
||||
.collect();
|
||||
|
||||
@@ -98,7 +116,7 @@ impl InstanceSnapshot {
|
||||
snapshot_id: Some(id),
|
||||
metadata: InstanceMetadata::default(),
|
||||
name: Cow::Owned(instance.name.clone()),
|
||||
class_name: Cow::Owned(instance.class_name.clone()),
|
||||
class_name: Cow::Owned(instance.class.clone()),
|
||||
properties: instance.properties.clone(),
|
||||
children,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user