Skip to content

Commit

Permalink
add widget related tools (#1072)
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca authored Nov 7, 2024
1 parent 73b973a commit db00720
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const gameCategory: ToolCategory = {
},
{
label: { en: 'Others', zh: '其他' },
tools: [spx.rand, gop.println]
tools: [spx.rand, gop.println, spx.getWidget]
}
]
}
Expand Down Expand Up @@ -253,6 +253,23 @@ export function getVariableCategory(project: Project): ToolCategory {
})
})

groups.push({
label: { en: 'Widgets', zh: '控件' },
tools: project.stage.widgets.map((widget) => {
const keyword = `"${widget.name}"`
return {
type: ToolType.variable,
target: ToolContext.all,
keyword,
desc: { en: `Widget "${widget.name}"`, zh: `控件 ${widget.name}` },
usage: {
sample: keyword,
insertText: keyword
}
}
})
})

if (project.selectedSprite != null) {
groups.push({
label: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,20 @@ export const exit: Tool = {
}
}

export const getWidget: Tool = {
type: ToolType.function,
callEffect: ToolCallEffect.read,
target: ToolContext.all,
keyword: 'getWidget',
desc: { en: 'Get the widget by given name', zh: '通过指定名称获取控件' },
usage: {
sample: 'getWidget(Monitor, "monitor1")',
insertText: 'getWidget(${1:Monitor}, ${2:name})'
}
}

// TODO: definition for widget methods

function defineConst(name: string, desc: LocaleMessage): Tool {
name = name[0].toUpperCase() + name.slice(1) // it's strange, but required
return {
Expand Down

0 comments on commit db00720

Please sign in to comment.