Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
GigsD4X committed Apr 15, 2017
2 parents bb445fe + cdb577e commit 7c73f9b
Show file tree
Hide file tree
Showing 12 changed files with 57,199 additions and 40,754 deletions.
30 changes: 20 additions & 10 deletions AutomaticUpdating.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
local Tool = script.Parent;

function IsVersionOutdated()
-- Returns whether this version of Building Tools is out of date
function IsVersionOutdated(Version)
-- Returns whether the given version of Building Tools is out of date

-- Check most recent version number
local AssetInfo = Game:GetService('MarketplaceService'):GetProductInfo(142785488, Enum.InfoType.Asset);
local LatestMajorVersion, LatestMinorVersion, LatestPatchVersion = AssetInfo.Description:match '%[Version: ([0-9]+)%.([0-9]+)%.([0-9]+)%]';
local CurrentMajorVersion, CurrentMinorVersion, CurrentPatchVersion = Tool.Version.Value:match '([0-9]+)%.([0-9]+)%.([0-9]+)';
local CurrentMajorVersion, CurrentMinorVersion, CurrentPatchVersion = Version:match '([0-9]+)%.([0-9]+)%.([0-9]+)';

-- Convert version data into numbers
local LatestMajorVersion, LatestMinorVersion, LatestPatchVersion =
Expand All @@ -31,17 +31,27 @@ function IsVersionOutdated()
end;

-- Ensure tool mode is enabled, auto-updating is enabled, and version is outdated
if not (Tool:IsA 'Tool' and Tool.AutoUpdate.Value and IsVersionOutdated()) then
if not (Tool:IsA 'Tool' and Tool.AutoUpdate.Value and IsVersionOutdated(Tool.Version.Value)) then
return;
end;

-- Attempt to get latest copy of the asset
local LatestVersionId = Game:GetService('InsertService'):GetLatestAssetVersionAsync(142785488);
local Model = Game:GetService('InsertService'):LoadAssetVersion(LatestVersionId);
if Model and #Model:GetChildren() > 0 then
-- Use module to insert latest tool
local GetLatestTool = require(580330877);
if not GetLatestTool then
return;
end;

-- Get latest copy of tool
local NewTool = GetLatestTool();
if NewTool then

-- Get the tool
local NewTool = Model:GetChildren()[1];
-- Prevent update attempt loops since fetched version is now cached
NewTool.AutoUpdate.Value = false;

-- Cancel replacing current tool if fetched version is the same
if NewTool.Version.Value == Tool.Version.Value then
return;
end;

-- Detach update script from tool and save old tool parent
script.Parent = nil;
Expand Down
8 changes: 8 additions & 0 deletions BoundingBoxModule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ function BoundingBoxModule.StartBoundingBox(HandleAttachmentCallback)

end;

function BoundingBoxModule.GetBoundingBox()
-- Returns the current bounding box

-- Get and return bounding box
return BoundingBox;

end;

function UpdateBoundingBox()
-- Updates the bounding box to fit the selection's extents

Expand Down
89 changes: 89 additions & 0 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ function Enable(Mouse)
-- Use default mouse behavior
UserInputService.MouseBehavior = Enum.MouseBehavior.Default;

-- Disable mouse lock in tool mode
if Mode == 'Tool' then
SyncAPI:Invoke('SetMouseLockEnabled', false);
end;

-- Wait for UI to initialize asynchronously
while not UI do
wait(0.1);
Expand Down Expand Up @@ -198,6 +203,11 @@ function Disable()
-- Fire event
Disabling:fire();

-- Reenable mouse lock option in tool mode
if Mode == 'Tool' then
SyncAPI:Invoke('SetMouseLockEnabled', true);
end;

-- Hide UI
UI.Parent = script;

Expand Down Expand Up @@ -669,6 +679,85 @@ function ToggleSwitch(CurrentButtonName, SwitchContainer)
end;
end;

-- References to reduce indexing time
local GetConnectedParts = Instance.new('Part').GetConnectedParts;
local GetChildren = script.GetChildren;

function GetPartJoints(Part, Whitelist)
-- Returns any manual joints involving `Part`

local Joints = {};

-- Get joints stored inside `Part`
for Joint, JointParent in pairs(SearchJoints(Part, Part, Whitelist)) do
Joints[Joint] = JointParent;
end;

-- Get joints stored inside connected parts
for _, ConnectedPart in pairs(GetConnectedParts(Part)) do
for Joint, JointParent in pairs(SearchJoints(ConnectedPart, Part, Whitelist)) do
Joints[Joint] = JointParent;
end;
end;

-- Return all found joints
return Joints;

end;

-- Types of joints to assume should be preserved
local ManualJointTypes = Support.FlipTable { 'Weld', 'ManualWeld', 'ManualGlue', 'Motor', 'Motor6D' };

function SearchJoints(Haystack, Part, Whitelist)
-- Searches for and returns manual joints in `Haystack` involving `Part` and other parts in `Whitelist`

local Joints = {};

-- Search the haystack for joints involving `Part`
for _, Item in pairs(GetChildren(Haystack)) do

-- Check if this item is a manual, intentional joint
if ManualJointTypes[Item.ClassName] and
(Whitelist[Item.Part0] and Whitelist[Item.Part1]) then

-- Save joint and state if intentional
Joints[Item] = Item.Parent;

end;

end;

-- Return the found joints
return Joints;

end;

function RestoreJoints(Joints)
-- Restores the joints from the given `Joints` data

-- Restore each joint
for Joint, JointParent in pairs(Joints) do
Joint.Parent = JointParent;
end;

end;

function PreserveJoints(Part, Whitelist)
-- Preserves and returns intentional joints of `Part` connecting parts in `Whitelist`

-- Get the part's joints
local Joints = GetPartJoints(Part, Whitelist);

-- Save the joints from being broken
for Joint in pairs(Joints) do
Joint.Parent = nil;
end;

-- Return the joints
return Joints;

end;

-- Initialize the UI
InitializeUI();

Expand Down
5 changes: 5 additions & 0 deletions SelectionModule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ end;
function TrackSelectionChange(OldSelection)
-- Registers a history record for a change in the selection

-- Avoid overwriting history for selection actions
if History.Index ~= #History.Stack then
return;
end;

-- Add the history record
History.Add({

Expand Down
107 changes: 106 additions & 1 deletion SyncAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ Actions = {
end;
end;

-- Preserve joints
for Part, Change in pairs(ChangeSet) do
Change.Joints = PreserveJoints(Part, ChangeSet);
end;

-- Perform each change
for Part, Change in pairs(ChangeSet) do

Expand Down Expand Up @@ -266,6 +271,7 @@ Actions = {
-- Restore the parts' original states
for Part, Change in pairs(ChangeSet) do
Part:MakeJoints();
RestoreJoints(Change.Joints);
Part.Anchored = Change.InitialState.Anchored;
end;

Expand Down Expand Up @@ -371,6 +377,11 @@ Actions = {
end;
end;

-- Preserve joints
for Part, Change in pairs(ChangeSet) do
Change.Joints = PreserveJoints(Part, ChangeSet);
end;

-- Perform each change
for Part, Change in pairs(ChangeSet) do

Expand Down Expand Up @@ -398,6 +409,7 @@ Actions = {
-- Restore the parts' original states
for Part, Change in pairs(ChangeSet) do
Part:MakeJoints();
RestoreJoints(Change.Joints);
Part.Anchored = Change.InitialState.Anchored;
end;

Expand Down Expand Up @@ -1168,12 +1180,13 @@ Actions = {
local Offset = Part.CFrame:toObjectSpace(TargetPart.CFrame);

-- Create the weld
local Weld = Instance.new('Weld', Game.JointsService);
local Weld = Instance.new('Weld');
Weld.Name = 'BTWeld';
Weld.Part0 = TargetPart;
Weld.Part1 = Part;
Weld.C1 = Offset;
Weld.Archivable = true;
Weld.Parent = TargetPart;

-- Register the weld
CreatedInstances[Weld] = Weld;
Expand Down Expand Up @@ -1418,6 +1431,19 @@ Actions = {

end;

['SetMouseLockEnabled'] = function (Enabled)
-- Sets whether mouse lock is enabled for the current player

-- Offload action to server-side if API is running locally
if RunService:IsClient() and not RunService:IsStudio() then
return SyncAPI.ServerEndpoint:InvokeServer('SetMouseLockEnabled', Enabled);
end;

-- Set whether mouse lock is enabled
Player.DevEnableMouseLock = Enabled;

end;

};

function ArePartsSelectable(Parts)
Expand All @@ -1435,6 +1461,85 @@ function ArePartsSelectable(Parts)

end;

-- References to reduce indexing time
local GetConnectedParts = Instance.new('Part').GetConnectedParts;
local GetChildren = script.GetChildren;

function GetPartJoints(Part, Whitelist)
-- Returns any manual joints involving `Part`

local Joints = {};

-- Get joints stored inside `Part`
for Joint, JointParent in pairs(SearchJoints(Part, Part, Whitelist)) do
Joints[Joint] = JointParent;
end;

-- Get joints stored inside connected parts
for _, ConnectedPart in pairs(GetConnectedParts(Part)) do
for Joint, JointParent in pairs(SearchJoints(ConnectedPart, Part, Whitelist)) do
Joints[Joint] = JointParent;
end;
end;

-- Return all found joints
return Joints;

end;

-- Types of joints to assume should be preserved
local ManualJointTypes = Support.FlipTable { 'Weld', 'ManualWeld', 'ManualGlue', 'Motor', 'Motor6D' };

function SearchJoints(Haystack, Part, Whitelist)
-- Searches for and returns manual joints in `Haystack` involving `Part` and other parts in `Whitelist`

local Joints = {};

-- Search the haystack for joints involving `Part`
for _, Item in pairs(GetChildren(Haystack)) do

-- Check if this item is a manual, intentional joint
if ManualJointTypes[Item.ClassName] and
(Whitelist[Item.Part0] and Whitelist[Item.Part1]) then

-- Save joint and state if intentional
Joints[Item] = Item.Parent;

end;

end;

-- Return the found joints
return Joints;

end;

function RestoreJoints(Joints)
-- Restores the joints from the given `Joints` data

-- Restore each joint
for Joint, JointParent in pairs(Joints) do
Joint.Parent = JointParent;
end;

end;

function PreserveJoints(Part, Whitelist)
-- Preserves and returns intentional joints of `Part` connecting parts in `Whitelist`

-- Get the part's joints
local Joints = GetPartJoints(Part, Whitelist);

-- Save the joints from being broken
for Joint in pairs(Joints) do
Joint.Parent = nil;
end;

-- Return the joints
return Joints;

end;

-- Keep current player updated in tool mode
if ToolMode == 'Tool' then

Expand Down
Loading

0 comments on commit 7c73f9b

Please sign in to comment.