Skip to content

Commit

Permalink
Implement lastColumnKeyUsesIndices
Browse files Browse the repository at this point in the history
  • Loading branch information
hoontee committed Aug 21, 2024
1 parent fd104da commit 0e0732d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 46 deletions.
Binary file modified Lync/Plugin.rbxm
Binary file not shown.
Binary file modified Lync/RobloxPluginSource/Model.rbxm
Binary file not shown.
28 changes: 14 additions & 14 deletions Lync/RobloxPluginSource/Plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ mainWidget.ZIndexBehavior = Enum.ZIndexBehavior.Sibling

local widgetFrame = script.WidgetGui.Frame
widgetFrame.Parent = mainWidget
widgetFrame.Title.Version.Text = VERSION:lower()
widgetFrame.TopBar.Title.Version.Text = VERSION:lower()

local connect = widgetFrame.Actions.Connect
local portTextBox = widgetFrame.Actions.Port
local connect = widgetFrame.TopBar.Actions.Connect
local portTextBox = widgetFrame.TopBar.Actions.Port
portTextBox.Text = plugin:GetSetting("Lync_Port") or ""

local unsavedFilesFrame = widgetFrame.UnsavedFiles
Expand Down Expand Up @@ -442,17 +442,17 @@ end
function setTheme()
-- Main Widget
do
widgetFrame.Actions.BackgroundColor3 = theme:GetColor(Enum.StudioStyleGuideColor.InputFieldBackground)
widgetFrame.Actions.UIStroke.Color = theme:GetColor(Enum.StudioStyleGuideColor.InputFieldBorder)
widgetFrame.TopBar.Actions.BackgroundColor3 = theme:GetColor(Enum.StudioStyleGuideColor.InputFieldBackground)
widgetFrame.TopBar.Actions.UIStroke.Color = theme:GetColor(Enum.StudioStyleGuideColor.InputFieldBorder)
connect.UIStroke.Color = theme:GetColor(Enum.StudioStyleGuideColor.DialogButtonBorder)
portTextBox.PlaceholderColor3 = theme:GetColor(Enum.StudioStyleGuideColor.MainText, Enum.StudioStyleGuideModifier.Disabled)
portTextBox.TextColor3 = theme:GetColor(Enum.StudioStyleGuideColor.MainText)
widgetFrame.Title.Version.TextColor3 = theme:GetColor(Enum.StudioStyleGuideColor.MainText, Enum.StudioStyleGuideModifier.Disabled)
widgetFrame.TopBar.Title.Version.TextColor3 = theme:GetColor(Enum.StudioStyleGuideColor.MainText, Enum.StudioStyleGuideModifier.Disabled)
local portBorderColor = Enum.StudioStyleGuideColor.InputFieldBorder
widgetFrame.Actions:SetAttribute("Border", theme:GetColor(portBorderColor))
widgetFrame.Actions:SetAttribute("BorderHover", theme:GetColor(portBorderColor, Enum.StudioStyleGuideModifier.Hover))
widgetFrame.Actions:SetAttribute("BorderSelected", theme:GetColor(portBorderColor, Enum.StudioStyleGuideModifier.Selected))
widgetFrame.Actions.UIStroke.Color = widgetFrame.Actions:GetAttribute("Border")
widgetFrame.TopBar.Actions:SetAttribute("Border", theme:GetColor(portBorderColor))
widgetFrame.TopBar.Actions:SetAttribute("BorderHover", theme:GetColor(portBorderColor, Enum.StudioStyleGuideModifier.Hover))
widgetFrame.TopBar.Actions:SetAttribute("BorderSelected", theme:GetColor(portBorderColor, Enum.StudioStyleGuideModifier.Selected))
widgetFrame.TopBar.Actions.UIStroke.Color = widgetFrame.TopBar.Actions:GetAttribute("Border")
setConnectTheme()
end

Expand Down Expand Up @@ -1113,23 +1113,23 @@ if not IS_PLAYTEST_SERVER then
do
portTextBox.MouseEnter:Connect(function()
if not portTextBox.Active or portTextBox:IsFocused() then return end
widgetFrame.Actions.UIStroke.Color = widgetFrame.Actions:GetAttribute("BorderHover")
widgetFrame.TopBar.Actions.UIStroke.Color = widgetFrame.TopBar.Actions:GetAttribute("BorderHover")
end)

portTextBox.MouseLeave:Connect(function()
if portTextBox:IsFocused() then return end
widgetFrame.Actions.UIStroke.Color = widgetFrame.Actions:GetAttribute("Border")
widgetFrame.TopBar.Actions.UIStroke.Color = widgetFrame.TopBar.Actions:GetAttribute("Border")
end)

portTextBox.Focused:Connect(function()
if not portTextBox.Active then return end
widgetFrame.Actions.UIStroke.Color = widgetFrame.Actions:GetAttribute("BorderSelected")
widgetFrame.TopBar.Actions.UIStroke.Color = widgetFrame.TopBar.Actions:GetAttribute("BorderSelected")
end)

portTextBox.FocusLost:Connect(function(_enterPressed)
local entry = math.clamp(tonumber(portTextBox.Text) or 0, 0, 65535)
portTextBox.Text = entry > 0 and entry or ""
widgetFrame.Actions.UIStroke.Color = widgetFrame.Actions:GetAttribute("Border")
widgetFrame.TopBar.Actions.UIStroke.Color = widgetFrame.TopBar.Actions:GetAttribute("Border")
plugin:SetSetting("Lync_Port", entry > 0 and entry or nil)
end)
end
Expand Down
79 changes: 51 additions & 28 deletions Lync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,30 @@ function runJobs(event, localPath) {
}
}

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Automated Download Functions
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

async function fetchSources() {
if (!('sources' in projectJson) || projectJson.length == 0) console.log('Nothing to download')
for (const index in projectJson.sources) {
const source = projectJson.sources[index]
console.log('Fetching source', green(source.name), '. . .')
try {
let contents;
if (source.type == 'GET') {
contents = await getAsync(source.url, source.headers)
} else if (source.type == 'POST') {
contents = await postAsync(source.url, source.headers, source.postData)
}
fs.writeFileSync(source.path, contents)
console.log(green(source.name), 'saved to', cyan(source.path))
} catch (err) {
console.error(red('Fetch error:'), yellow(err))
}
}
}

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Main
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -936,23 +960,7 @@ function runJobs(event, localPath) {

// Download sources
if (MODE == 'fetch') {
if (!('sources' in projectJson) || projectJson.length == 0) console.log('Nothing to download')
for (const index in projectJson.sources) {
const source = projectJson.sources[index]
console.log('Fetching source', green(source.name), '. . .')
try {
let contents;
if (source.type == 'GET') {
contents = await getAsync(source.url, source.headers)
} else if (source.type == 'POST') {
contents = await postAsync(source.url, source.headers, source.postData)
}
fs.writeFileSync(source.path, contents)
console.log(green(source.name), 'saved to', cyan(source.path))
} catch (err) {
console.error(red('Fetch error:'), yellow(err))
}
}
fetchSources()
process.exit()
}

Expand Down Expand Up @@ -1398,37 +1406,46 @@ function runJobs(event, localPath) {
defval: null
})
const entries = tableDefinitions.numColumnKeys > 0 && {} || []
const startRow = tableDefinitions.hasHeader && 1 || 0
const hasHeader = tableDefinitions.hasHeader
const startRow = hasHeader && 1 || 0
const startColumn = tableDefinitions.numColumnKeys
const lastColumnKeyUsesIndices = tableDefinitions.lastColumnKeyUsesIndices
const header = sheetJson[0]
for (let row = startRow; row < sheetJson.length; row++) {
for (let column = startColumn; column < header.length; column++) {
const key = tableDefinitions.hasHeader && header[column] || (column - startColumn)
const key = hasHeader && header[column] || (column - startColumn)
let target = entries
if (tableDefinitions.numColumnKeys > 0) {
for (let columnKeyIndex = 0; columnKeyIndex < tableDefinitions.numColumnKeys; columnKeyIndex++) {
if (startColumn > 0) {
for (let columnKeyIndex = 0; columnKeyIndex < startColumn; columnKeyIndex++) {
const columnKey = sheetJson[row][columnKeyIndex]
if (!columnKey) {
target = null
break
}
if (!(columnKey in target)) {
target[columnKey] = tableDefinitions.hasHeader && {} || []
if (lastColumnKeyUsesIndices && columnKeyIndex == startColumn - 1) {
if (!(columnKey in target))
target[columnKey] = []
target = target[columnKey]
if (!(target[row]))
target[row] = {}
target = target[row]
} else {
if (!(columnKey in target))
target[columnKey] = hasHeader && {} || []
target = target[columnKey]
}
target = target[columnKey]
}
} else {
const indexKey = row - startRow
if (!target[indexKey]) {
target[indexKey] = tableDefinitions.hasHeader && {} || []
}
if (!target[indexKey])
target[indexKey] = hasHeader && {} || []
target = target[indexKey]
}
if (target)
target[key] = sheetJson[row][column]
}
}
read = LUA.format(entries, { singleQuote: false, spaces: '\t' })
read = LUA.format(entries, { singleQuote: false, spaces: '\t' }).replaceAll(/^\n/gm, '') // Regex removes blank newlines
}
}

Expand Down Expand Up @@ -1500,6 +1517,12 @@ function runJobs(event, localPath) {
res.end()
break

case 'FetchSources':
res.writeHead(200)
res.end()
fetchSources()
break

default:
res.writeHead(400)
res.end('Missing / invalid type header')
Expand Down
8 changes: 8 additions & 0 deletions Lync/validator/excel.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ module.exports.validate = function(json, localPath) {
failed = true
}

if (!('lastColumnKeyUsesIndices' in json)) {
console.error(fileError(localPath), yellow('Missing key'), green('lastColumnKeyUsesIndices'))
failed = true
} else if (typeof json.lastColumnKeyUsesIndices != 'boolean') {
console.error(fileError(localPath), green('lastColumnKeyUsesIndices'), yellow('must be a boolean'))
failed = true
}

if (failed) return
return json
}
9 changes: 5 additions & 4 deletions Sample Project/Assets/Workspace/Test_excel.excel.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"spreadsheet": "Test_excel.xlsx",
"ref": "Sheet1!C4:F7",
"hasHeader": true,
"numColumnKeys": 1
"spreadsheet": "Test_excel.xlsx",
"ref": "Sheet1!C4:F7",
"hasHeader": true,
"numColumnKeys": 1,
"lastColumnKeyUsesIndices": false
}
Binary file modified Sample Project/Assets/Workspace/Test_excel.xlsx
Binary file not shown.

0 comments on commit 0e0732d

Please sign in to comment.