mirror of
https://github.com/CompeyDev/lune-packaging.git
synced 2025-01-10 04:39:08 +00:00
Add tests for reading & writing roblox place & model files
This commit is contained in:
parent
34e417e57b
commit
afdde26a18
6 changed files with 71 additions and 11 deletions
|
@ -241,7 +241,7 @@ impl Document {
|
||||||
let mut dom = WeakDom::new(DomInstanceBuilder::new("ROOT"));
|
let mut dom = WeakDom::new(DomInstanceBuilder::new("ROOT"));
|
||||||
|
|
||||||
for data_model_child in i.get_children() {
|
for data_model_child in i.get_children() {
|
||||||
data_model_child.into_external_dom(&mut dom);
|
data_model_child.clone_into_external_dom(&mut dom);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
@ -266,7 +266,7 @@ impl Document {
|
||||||
let mut dom = WeakDom::new(DomInstanceBuilder::new("ROOT"));
|
let mut dom = WeakDom::new(DomInstanceBuilder::new("ROOT"));
|
||||||
|
|
||||||
for instance in v {
|
for instance in v {
|
||||||
instance.into_external_dom(&mut dom);
|
instance.clone_into_external_dom(&mut dom);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
|
@ -99,17 +99,19 @@ impl Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Transfers an instance to an external weak dom.
|
Clones an instance to an external weak dom.
|
||||||
|
|
||||||
This will place the instance as a child of the
|
This will place the instance as a child of the
|
||||||
root of the weak dom, and return its referent.
|
root of the weak dom, and return its referent.
|
||||||
*/
|
*/
|
||||||
pub fn into_external_dom(self, external_dom: &mut WeakDom) -> DomRef {
|
pub fn clone_into_external_dom(self, external_dom: &mut WeakDom) -> DomRef {
|
||||||
|
let cloned = self.clone_instance();
|
||||||
|
|
||||||
let mut dom = INTERNAL_DOM
|
let mut dom = INTERNAL_DOM
|
||||||
.try_write()
|
.try_write()
|
||||||
.expect("Failed to get write access to document");
|
.expect("Failed to get write access to document");
|
||||||
|
|
||||||
let internal_dom_ref = self.dom_ref;
|
let internal_dom_ref = cloned.dom_ref;
|
||||||
let external_root_ref = external_dom.root_ref();
|
let external_root_ref = external_dom.root_ref();
|
||||||
|
|
||||||
dom.transfer(internal_dom_ref, external_dom, external_root_ref);
|
dom.transfer(internal_dom_ref, external_dom, external_root_ref);
|
||||||
|
@ -589,12 +591,7 @@ impl Instance {
|
||||||
datatype_table.set(
|
datatype_table.set(
|
||||||
"new",
|
"new",
|
||||||
lua.create_function(|lua, class_name: String| {
|
lua.create_function(|lua, class_name: String| {
|
||||||
if class_name == data_model::CLASS_NAME {
|
if class_exists(&class_name) {
|
||||||
Err(LuaError::RuntimeError(format!(
|
|
||||||
"Failed to create Instance - '{}' class is restricted",
|
|
||||||
class_name
|
|
||||||
)))
|
|
||||||
} else if class_exists(&class_name) {
|
|
||||||
Instance::new_orphaned(class_name).to_lua(lua)
|
Instance::new_orphaned(class_name).to_lua(lua)
|
||||||
} else {
|
} else {
|
||||||
Err(LuaError::RuntimeError(format!(
|
Err(LuaError::RuntimeError(format!(
|
||||||
|
|
20
tests/roblox/files/readModelFile.luau
Normal file
20
tests/roblox/files/readModelFile.luau
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
local fs = require("@lune/fs") :: any
|
||||||
|
local roblox = require("@lune/roblox") :: any
|
||||||
|
|
||||||
|
local modelDirs = {}
|
||||||
|
for _, dirName in fs.readDir("tests/roblox/rbx-test-files/places") do
|
||||||
|
table.insert(modelDirs, "tests/roblox/rbx-test-files/places/" .. dirName)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, modelDir in modelDirs do
|
||||||
|
local modelBinary = roblox.readModelFile(modelDir .. "/binary.rbxl")
|
||||||
|
local modelXml = roblox.readModelFile(modelDir .. "/xml.rbxlx")
|
||||||
|
|
||||||
|
for _, modelInstance in modelBinary do
|
||||||
|
assert(modelInstance:IsA("Instance"))
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, modelInstance in modelXml do
|
||||||
|
assert(modelInstance:IsA("Instance"))
|
||||||
|
end
|
||||||
|
end
|
18
tests/roblox/files/readPlaceFile.luau
Normal file
18
tests/roblox/files/readPlaceFile.luau
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
local fs = require("@lune/fs") :: any
|
||||||
|
local roblox = require("@lune/roblox") :: any
|
||||||
|
|
||||||
|
local placeDirs = {}
|
||||||
|
for _, dirName in fs.readDir("tests/roblox/rbx-test-files/places") do
|
||||||
|
table.insert(placeDirs, "tests/roblox/rbx-test-files/places/" .. dirName)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, placeDir in placeDirs do
|
||||||
|
local placeBinary = roblox.readPlaceFile(placeDir .. "/binary.rbxl")
|
||||||
|
local placeXml = roblox.readPlaceFile(placeDir .. "/xml.rbxlx")
|
||||||
|
|
||||||
|
assert(placeBinary.ClassName == "DataModel")
|
||||||
|
assert(placeXml.ClassName == "DataModel")
|
||||||
|
|
||||||
|
assert(placeBinary:IsA("ServiceProvider"))
|
||||||
|
assert(placeXml:IsA("ServiceProvider"))
|
||||||
|
end
|
10
tests/roblox/files/writeModelFile.luau
Normal file
10
tests/roblox/files/writeModelFile.luau
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
local roblox = require("@lune/roblox") :: any
|
||||||
|
local Instance = roblox.Instance
|
||||||
|
|
||||||
|
local instances = {
|
||||||
|
Instance.new("Model"),
|
||||||
|
Instance.new("Part"),
|
||||||
|
}
|
||||||
|
|
||||||
|
roblox.writeModelFile("bin/temp-model.rbxm", instances)
|
||||||
|
roblox.writeModelFile("bin/temp-model.rbxmx", instances)
|
15
tests/roblox/files/writePlaceFile.luau
Normal file
15
tests/roblox/files/writePlaceFile.luau
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
local roblox = require("@lune/roblox") :: any
|
||||||
|
local Instance = roblox.Instance
|
||||||
|
|
||||||
|
local game = Instance.new("DataModel")
|
||||||
|
|
||||||
|
local workspace = game:GetService("Workspace")
|
||||||
|
|
||||||
|
local model = Instance.new("Model")
|
||||||
|
local part = Instance.new("Part")
|
||||||
|
|
||||||
|
part.Parent = model
|
||||||
|
model.Parent = workspace
|
||||||
|
|
||||||
|
roblox.writePlaceFile("bin/temp-place.rbxl", game)
|
||||||
|
roblox.writePlaceFile("bin/temp-place.rbxlx", game)
|
Loading…
Reference in a new issue