-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
199 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/FigmaImportAssistant/Main/CorrectionHandler/AppImportInterpreter.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
local AppImportInterpreter = {} | ||
|
||
local HttpService = game:GetService("HttpService") | ||
|
||
local function ReadRecursive(ParentTable) | ||
local ChildTable = { | ||
Root = {}, | ||
} | ||
|
||
for _, Child in ipairs(ParentTable) do | ||
local Interpretation = { | ||
Size = { | ||
X = Child.width, | ||
Y = Child.height | ||
}, | ||
|
||
Position = { | ||
X = Child.x, | ||
Y = Child.y, | ||
}, | ||
|
||
AnchorPoint = { | ||
X = 0, | ||
Y = 0 | ||
}, | ||
|
||
Name = Child.name or "AUTOIMPORT", | ||
Image = "", | ||
Stroke = Child.strokeWeight or 0, | ||
Oblique = 0, | ||
|
||
-- Unique data from import | ||
Type = if Child.opacity == 0 and Child.strokeWeight == 0 then "Frame" else "ImageLabel" | ||
} | ||
|
||
if Child.children then | ||
Interpretation.Children = ReadRecursive(Child.children) | ||
else | ||
Interpretation.Children = {} | ||
end | ||
|
||
table.insert(ChildTable.Root, Interpretation) | ||
end | ||
|
||
-- if ParentTable.children then | ||
-- ChildTable.Children = ReadRecursive(ParentTable.children) | ||
-- end | ||
|
||
return ChildTable | ||
end | ||
|
||
function AppImportInterpreter:InterpretJSONData(JSONData : string) | ||
local Data = HttpService:JSONDecode(JSONData) | ||
local Interpretation = ReadRecursive(Data) | ||
|
||
return Interpretation | ||
end | ||
|
||
return AppImportInterpreter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/FigmaImportAssistant/Main/CorrectionHandler/Creator.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
local Creator = {} | ||
|
||
local Applicator = require(script.Parent.Applicator) | ||
|
||
local function CreateRecursive(Parent, Data : {}) | ||
for _, Child in Data.Root do | ||
local Object = Instance.new(Child.Type) | ||
Object.ClipsDescendants = Child.clipsContent or true | ||
Object.BackgroundTransparency = 1 | ||
Object.Parent = Parent | ||
|
||
Applicator:ApplyChangesFromData(Object, Child) | ||
|
||
if Child.Children then | ||
CreateRecursive(Object, Child.Children) | ||
end | ||
end | ||
end | ||
|
||
function Creator:CreateFromData(SelectedInstance, Data : {}) | ||
CreateRecursive(SelectedInstance, Data) | ||
end | ||
|
||
return Creator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
local CorrectionHandler = {} | ||
|
||
local SelectionService = game:GetService("Selection") | ||
|
||
local Interface = require(script.Parent.Interface) | ||
local Utility = require(script.Parent.Utility) | ||
local AppImportInterpreter = require(script.AppImportInterpreter) | ||
local Creator = require(script.Creator) | ||
local Applicator = require(script.Applicator) | ||
|
||
local SelectedInstance = nil | ||
|
||
function CorrectionHandler:Init() | ||
Interface:OnApply(function(Data) | ||
if SelectedInstance then | ||
Applicator:ApplyChangesFromData(SelectedInstance, Data) | ||
end | ||
end) | ||
|
||
SelectionService.SelectionChanged:Connect(function() | ||
local Selected = SelectionService:Get() | ||
local SelectedCount = Utility.GetDictionaryLength(Selected) | ||
|
||
if SelectedCount == 1 then | ||
SelectedInstance = Selected[1] | ||
else | ||
SelectedInstance = nil | ||
end | ||
|
||
if SelectedInstance and not SelectedInstance:IsA("GuiObject") and not SelectedInstance:IsA("ScreenGui") then | ||
SelectedInstance = nil | ||
end | ||
|
||
Interface:OnSelection(SelectedInstance) | ||
end) | ||
end | ||
|
||
function CorrectionHandler:BuildFromImportData(ImportDataJSON : string) | ||
local InterpretedData = AppImportInterpreter:InterpretJSONData(ImportDataJSON) | ||
|
||
if InterpretedData and #InterpretedData > 0 then | ||
Creator:CreateFromData(InterpretedData) | ||
end | ||
end | ||
|
||
return CorrectionHandler |
12 changes: 12 additions & 0 deletions
12
src/FigmaImportAssistant/Main/Interface/Build/ImportInputs.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"AutoImportData" : { | ||
"PlaceholderText": "Import Data", | ||
"Type": "string" | ||
}, | ||
|
||
"AutoImportButton" : { | ||
"Text": "Auto Import", | ||
"Name": "AutoImportButton", | ||
"Type": "BaseButton" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters