Skip to content

Commit

Permalink
More misc changes
Browse files Browse the repository at this point in the history
- Made material table image path smaller
- Make use of if-then-else
- Removed assert for localization.
  • Loading branch information
mkargus committed Jan 20, 2024
1 parent a652049 commit 958218e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Components/Header.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local useTheme = require(Plugin.Hooks.useTheme)

local function Header(props, hooks)
local theme = useTheme(hooks)
local Height = props.IsSearchEnabled and 60 or 28
local Height = if props.IsSearchEnabled then 60 else 28

return Roact.createElement('Frame', {
BackgroundColor3 = theme:GetColor(Enum.StudioStyleGuideColor.Titlebar),
Expand Down
4 changes: 3 additions & 1 deletion src/Components/MaterialPanel/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local TERRAIN_TEXTURE_PATH = 'rbxasset://textures/TerrainTools/'

local Plugin = script.Parent.Parent

local Roact = require(Plugin.Packages.Roact)
Expand Down Expand Up @@ -27,7 +29,7 @@ local function MaterialPanel(props, hooks)
if string.find(string.lower(item.enum.Name), string.lower(SearchTerm), 1, true) then
assetsToDisplay[item.enum.Name] = Roact.createElement(MaterialItem, {
Id = item.enum,
Image = item.img
Image = TERRAIN_TEXTURE_PATH..item.img
})

numberAssets += 1
Expand Down
15 changes: 7 additions & 8 deletions src/Components/Outline.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local CoreGui = game:GetService('CoreGui')

local Plugin = script.Parent.Parent

local Roact = require(Plugin.Packages.Roact)
Expand All @@ -13,16 +15,13 @@ local useEventConnection = require(Plugin.Hooks.useEventConnection)

local function IsLockedPartAllowed(Part)
local setting = Settings:Get('IgnoreLockedParts')
if setting then
return setting == Part.Locked
else
return false
end

return if setting then setting == Part.Locked else false
end

local function GetColor(Part, isConvertibleToTerrain, isLockedPartAllowed)
if isConvertibleToTerrain and not isLockedPartAllowed then
return #Part:GetChildren() == 0 and Constants.OUTLINE_COLOR_ALLOW or Constants.OUTLINE_COLOR_WARNING
return if #Part:GetChildren() == 0 then Constants.OUTLINE_COLOR_ALLOW else Constants.OUTLINE_COLOR_WARNING
else
return Constants.OUTLINE_COLOR_ERROR
end
Expand Down Expand Up @@ -71,7 +70,7 @@ local function Outline(props, hooks)
useEventConnection(hooks, PluginMouse.Move, function()
local camera = workspace.CurrentCamera.CFrame
local ray = PluginMouse.UnitRay
local RaycastResults = workspace:Raycast(camera.Position, ray.Direction * 15000, props.raycastParams)
local RaycastResults = workspace:Raycast(camera.Position, ray.Direction * 15000, props.RaycastParams)

if RaycastResults and not RaycastResults.Instance:IsA('Terrain') then
-- Only change the state if the part in the RaycastResults is different from the one in the state.
Expand Down Expand Up @@ -100,7 +99,7 @@ local function Outline(props, hooks)
local outlineClass, outlineProps = CreateOutline(Part, color)

return Roact.createElement(Roact.Portal, {
target = game:GetService('CoreGui')
target = CoreGui
}, {
PTT_Outline = Roact.createElement(outlineClass, outlineProps)
})
Expand Down
8 changes: 6 additions & 2 deletions src/Components/PluginApp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ end
function PluginApp:render()
local state = self.state

return not RunService:IsRunning() and Roact.createElement(StudioWidget, {
if RunService:IsRunning() then
return nil
end

return Roact.createElement(StudioWidget, {
plugin = self.plugin,
Id = 'PartToTerrain',
Title = Localization('Plugin.NameVersion', { Constants.VERSION }),
Expand All @@ -181,7 +185,7 @@ function PluginApp:render()

Outline = state.guiEnabled and Roact.createElement(Outline, {
PluginMouse = self.pluginMouse,
raycastParams = self.raycastParams
RaycastParams = self.raycastParams
})
})
end
Expand Down
4 changes: 2 additions & 2 deletions src/Components/ScrollingFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ local function ScrollingFrame(props, hooks)
end, {})

local isDark = theme.Name == 'Dark'
local BkgColor = isDark and Color3.fromRGB(38, 38, 38) or Color3.fromRGB(245, 245, 245)
local ScrollbarColor = isDark and Color3.fromRGB(85, 85, 85) or Color3.fromRGB(245, 245, 245)
local BkgColor = if isDark then Color3.fromRGB(38, 38, 38) else Color3.fromRGB(245, 245, 245)
local ScrollbarColor = if isDark then Color3.fromRGB(85, 85, 85) else Color3.fromRGB(245, 245, 245)

return Roact.createElement('Frame', {
BackgroundTransparency = 1,
Expand Down
7 changes: 5 additions & 2 deletions src/Components/ToggleButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ local useTheme = require(Plugin.Hooks.useTheme)
local function ToggleButton(props, hooks)
local theme = useTheme(hooks)

local isDark = theme.Name == 'Dark'
local disabledColor = if isDark then Color3.fromRGB(85, 85, 85) else Color3.fromRGB(184, 184, 184)

return Roact.createElement('ImageButton', {
AutoButtonColor = false,
AnchorPoint = props.AnchorPoint,
BackgroundColor3 = props.IsActive and Color3.fromRGB(64, 166, 81) or theme:GetColor(Enum.StudioStyleGuideColor.ScriptWhitespace),
BackgroundColor3 = if props.IsActive then Color3.fromRGB(64, 166, 81) else disabledColor,
Size = UDim2.fromOffset(40, 24),
Position = props.Position,
[Roact.Event.MouseButton1Click] = props.onClick
Expand All @@ -31,7 +34,7 @@ local function ToggleButton(props, hooks)
}),
StateFrame = Roact.createElement('Frame', {
BackgroundColor3 = theme:GetColor(Enum.StudioStyleGuideColor.MainBackground),
Position = UDim2.fromOffset(props.IsActive and 18 or 2, 2),
Position = UDim2.fromOffset(if props.IsActive then 18 else 2, 2),
Size = UDim2.fromOffset(20, 20)
}, {
UICorner = Roact.createElement('UICorner', {
Expand Down
46 changes: 23 additions & 23 deletions src/Util/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ Constants.MATERIAL_GRID_PADDING = UDim2.fromOffset(5, 5)
Constants.MATERIAL_GRID_SIZE = UDim2.fromOffset(50, 50)

Constants.MATERIALS_TABLE = {
{ enum = Enum.Material.Air, img = 'rbxasset://textures/TerrainTools/mtrl_air.png' },
{ enum = Enum.Material.Asphalt, img = 'rbxasset://textures/TerrainTools/mtrl_asphalt.png' },
{ enum = Enum.Material.Basalt, img = 'rbxasset://textures/TerrainTools/mtrl_basalt.png' },
{ enum = Enum.Material.Brick, img = 'rbxasset://textures/TerrainTools/mtrl_brick.png' },
{ enum = Enum.Material.Cobblestone, img = 'rbxasset://textures/TerrainTools/mtrl_cobblestone.png' },
{ enum = Enum.Material.Concrete, img = 'rbxasset://textures/TerrainTools/mtrl_concrete.png' },
{ enum = Enum.Material.CrackedLava, img = 'rbxasset://textures/TerrainTools/mtrl_crackedlava.png' },
{ enum = Enum.Material.Glacier, img = 'rbxasset://textures/TerrainTools/mtrl_glacier.png' },
{ enum = Enum.Material.Grass, img = 'rbxasset://textures/TerrainTools/mtrl_grass.png' },
{ enum = Enum.Material.Ground, img = 'rbxasset://textures/TerrainTools/mtrl_ground.png' },
{ enum = Enum.Material.Ice, img = 'rbxasset://textures/TerrainTools/mtrl_ice.png' },
{ enum = Enum.Material.LeafyGrass, img = 'rbxasset://textures/TerrainTools/mtrl_leafygrass.png' },
{ enum = Enum.Material.Limestone, img = 'rbxasset://textures/TerrainTools/mtrl_limestone.png' },
{ enum = Enum.Material.Mud, img = 'rbxasset://textures/TerrainTools/mtrl_mud.png' },
{ enum = Enum.Material.Pavement, img = 'rbxasset://textures/TerrainTools/mtrl_pavement.png' },
{ enum = Enum.Material.Rock, img = 'rbxasset://textures/TerrainTools/mtrl_rock.png' },
{ enum = Enum.Material.Salt, img = 'rbxasset://textures/TerrainTools/mtrl_salt.png' },
{ enum = Enum.Material.Sand, img = 'rbxasset://textures/TerrainTools/mtrl_sand.png' },
{ enum = Enum.Material.Sandstone, img = 'rbxasset://textures/TerrainTools/mtrl_sandstone.png' },
{ enum = Enum.Material.Slate, img = 'rbxasset://textures/TerrainTools/mtrl_slate.png' },
{ enum = Enum.Material.Snow, img = 'rbxasset://textures/TerrainTools/mtrl_snow.png' },
{ enum = Enum.Material.Water, img = 'rbxasset://textures/TerrainTools/mtrl_water.png' },
{ enum = Enum.Material.WoodPlanks, img = 'rbxasset://textures/TerrainTools/mtrl_woodplanks.png' }
{ enum = Enum.Material.Air, img = 'mtrl_air.png' },
{ enum = Enum.Material.Asphalt, img = '/mtrl_asphalt.png' },
{ enum = Enum.Material.Basalt, img = 'mtrl_basalt.png' },
{ enum = Enum.Material.Brick, img = 'mtrl_brick.png' },
{ enum = Enum.Material.Cobblestone, img = 'mtrl_cobblestone.png' },
{ enum = Enum.Material.Concrete, img = 'mtrl_concrete.png' },
{ enum = Enum.Material.CrackedLava, img = 'mtrl_crackedlava.png' },
{ enum = Enum.Material.Glacier, img = 'mtrl_glacier.png' },
{ enum = Enum.Material.Grass, img = 'mtrl_grass.png' },
{ enum = Enum.Material.Ground, img = 'mtrl_ground.png' },
{ enum = Enum.Material.Ice, img = 'mtrl_ice.png' },
{ enum = Enum.Material.LeafyGrass, img = 'mtrl_leafygrass.png' },
{ enum = Enum.Material.Limestone, img = 'mtrl_limestone.png' },
{ enum = Enum.Material.Mud, img = 'mtrl_mud.png' },
{ enum = Enum.Material.Pavement, img = 'mtrl_pavement.png' },
{ enum = Enum.Material.Rock, img = 'mtrl_rock.png' },
{ enum = Enum.Material.Salt, img = 'mtrl_salt.png' },
{ enum = Enum.Material.Sand, img = 'mtrl_sand.png' },
{ enum = Enum.Material.Sandstone, img = 'mtrl_sandstone.png' },
{ enum = Enum.Material.Slate, img = 'mtrl_slate.png' },
{ enum = Enum.Material.Snow, img = 'mtrl_snow.png' },
{ enum = Enum.Material.Water, img = 'mtrl_water.png' },
{ enum = Enum.Material.WoodPlanks, img = 'mtrl_woodplanks.png' }
}

----------------------------------------
Expand Down
7 changes: 3 additions & 4 deletions src/Util/Localization/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
--!strict
local StudioService = game:GetService('StudioService')

local Table = script.LocalizationTable
local LocaleId = game:GetService('StudioService').StudioLocaleId
local LocaleId = StudioService.StudioLocaleId
local Translator
local FallbackTranslator

Expand All @@ -10,9 +12,6 @@ if LocaleId ~= 'en_US' then
end

local function Localization(id: string, args: {any}?): string
assert(typeof(id) == 'string', 'id must be a string')
assert(args == nil or typeof(args) == 'table', 'args must be a table or nil')

local returnValue
local success = pcall(function()
returnValue = Translator:FormatByKey(id, args)
Expand Down

0 comments on commit 958218e

Please sign in to comment.