Skip to content

Commit

Permalink
Make JSON Model format consistent with Meta File format
Browse files Browse the repository at this point in the history
  • Loading branch information
hoontee committed Dec 1, 2023
1 parent d32f929 commit 0333792
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
Binary file modified Lync/Plugin.rbxm
Binary file not shown.
15 changes: 9 additions & 6 deletions Lync/RobloxPluginSource/Plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,14 @@ local function setScriptSourceLive(container: LuaSourceContainer, lua: string)
end

local function buildJsonModel(target: any, data: any)
if data.Children then
for _, childData in data.Children do
local newInstance = Instance.new(childData.ClassName or "Folder")
if childData.Name then
newInstance.Name = childData.Name
data.Properties = data.properties
data.Attributes = data.attributes
data.Tags = data.tags
if data.children then
for _, childData in data.children do
local newInstance = Instance.new(childData.className or "Folder")
if childData.name then
newInstance.Name = childData.name
end
buildJsonModel(newInstance, childData)
newInstance.Parent = target
Expand Down Expand Up @@ -654,7 +657,7 @@ local function buildPath(path: string)
if success then
local json = HttpService:JSONDecode(result)
if createInstance then
local newInstance = Instance.new(json.ClassName or "Folder")
local newInstance = Instance.new(json.className or "Folder")
newInstance.Name = name
newInstance.Parent = target
target = newInstance
Expand Down
30 changes: 15 additions & 15 deletions Lync/validator/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ function scan(json, root, localPath) {
let failed = false

for (const key in json) {
if (key == 'Name') {
if (typeof json.Name != 'string') {
console.error(jsonError(localPath, root, json, 'Name'), yellow('Must be a string'))
if (key == 'name') {
if (typeof json.name != 'string') {
console.error(jsonError(localPath, root, json, 'name'), yellow('Must be a string'))
failed = true
}

} else if (key == 'ClassName') {
if (typeof json.ClassName != 'string') {
console.error(jsonError(localPath, root, json, 'ClassName'), yellow('Must be a string'))
} else if (key == 'className') {
if (typeof json.className != 'string') {
console.error(jsonError(localPath, root, json, 'className'), yellow('Must be a string'))
failed = true
}

} else if (key == 'Properties') {
if (!(typeof json.Properties == 'object' && !Array.isArray(json.Properties))) {
console.error(jsonError(localPath, root, json, 'Properties'), yellow('Must be an object'))
} else if (key == 'properties') {
if (!(typeof json.properties == 'object' && !Array.isArray(json.properties))) {
console.error(jsonError(localPath, root, json, 'properties'), yellow('Must be an object'))
failed = true
} else {
for (const property in json.Properties) {
if (typeof json.Properties[property] == 'object' && Array.isArray(json.Properties[property]) && json.Properties[property].length > 1) {
for (const property in json.properties) {
if (typeof json.properties[property] == 'object' && Array.isArray(json.properties[property]) && json.properties[property].length > 1) {
console.error(jsonError(localPath, root, json, property), yellow('Array with size > 1; check property syntax'))
failed = true
}
}
}

} else if (key == 'Children') {
if (!(typeof json.Children == 'object' && Array.isArray(json.Children))) {
console.error(jsonError(localPath, root, json, 'Children') , yellow('Must be an array'))
} else if (key == 'children') {
if (!(typeof json.children == 'object' && Array.isArray(json.children))) {
console.error(jsonError(localPath, root, json, 'children') , yellow('Must be an array'))
failed = true
} else {
for (const child of json.Children) {
for (const child of json.children) {
const scanFailed = scan(child, root, localPath)
failed = failed || scanFailed
}
Expand Down
20 changes: 9 additions & 11 deletions Sample Project/Assets/Workspace/TestModel.model.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"ClassName": "Model",
"Properties": {
"Scale": 2
},
"Children": [
"name": "Money",
"className": "Model",
"children": [
{
"Name": "RootPart",
"ClassName": "Part",
"Properties": {
"Size": ["Vector3.new(2, 2, 2)"]
"className": "Part",
"properties": {
"BrickColor": [ "BrickColor.new(\"Bright green\")" ],
"Size": [ "Vector3.new(1, 0.4, 2)" ]
}
},
{
"Name": "SendMoney",
"ClassName": "RemoteEvent"
"name": "CollectMoney",
"className": "RemoteEvent"
}
]
}

0 comments on commit 0333792

Please sign in to comment.