mrbot/bot/settings_controller.iss

111 lines
3.1 KiB
Plaintext

#include "${LavishScript.HomeDirectory}/scripts/mr/common/JsonHelpers.iss"
objectdef SettingsController
{
variable jsonvalue abilityListItems = "[]"
variable jsonvalue currentCastStack = "[]"
variable int currentSelectedAvailableAbilityIndex = -1
variable jsonvalue newCastStackItem = "{}"
method Initialize()
{
LavishScript:RegisterEvent[onNewCastStackItemChanged]
variable jsonvalue jo
jo:ParseFile["${LavishScript.HomeDirectory}/scripts/mr/bot/ability_exports/Ihaihu_shadowknight.json"]
if ${jo.Type.NotEqual["object"]}
{
echo "Error parsing ability list"
return
}
variable jsonvalueref keys
keys:SetReference[jo.Keys]
variable int idx
for (idx:Set[1] ; ${idx} < ${keys.Used} ; idx:Inc)
{
variable string key
key:Set["${keys.Get[${idx}]}"]
variable jsonvalue abilityItem = "{}"
if ${jo.Get["${key}"].Get[1, "spellBookType"]} < 2
{
abilityItem:SetValue[$$>{
"Name": "${key~}"
}<$$]
abilityListItems:Add[${abilityItem}]
}
}
}
method Shutdown()
{
}
method OnClose()
{
}
method SetCurrentAbility(int selectedIndex)
{
currentSelectedAvailableAbilityIndex:Set[${selectedIndex}]
LGUI2.Element[MRSettingsController.events]:FireEventHandler[onNewCastStackItemChanged]
newCastStackItem:SetValue["$$>{
"action": "ability",
"name": "${abilityListItems.Get[${selectedIndex}, "Name"]}"
}<$$"]
}
method OnCastStackAbilityComboChange(string param)
{
echo "param: ${param}"
echo "OnCastStackAbilityComboChange: ${Context.AsJSON~}"
newCastStackItem:Set["${Context.Source.Name.Token[3, "."]}", "${Context.Source.SelectedItem.Data.AsJSON~}"]
echo "${Context.Source.Name.Token[3, "."]} = ${Context.Source.SelectedItem.Data}"
echo "newCastStackItem: ${newCastStackItem.AsJSON[multiline]~}"
}
method SafeSetNewCastStackItemProperty(string propertyName, string value)
{
echo "SafeSetNewCastStackItemProperty: ${propertyName} = ${value}"
if ${value(exists)} && ${value.NotEqual[""]}
{
newCastStackItem:Set["${propertyName}", "${value}"]
}
}
member:string SafeGetNewCastStackItemProperty(string propertyName)
{
if ${newCastStackItem.Has[${propertyName}]}
{
return ${newCastStackItem.Get[${propertyName}]}
}
return ""
}
member GetTargetOptions()
{
variable jsonvalue targetOptions
targetOptions:SetValue[$$>"[
"@Group",
"@Raid",
"@Me",
"@Tank",
"@Healer",
"@DPS"
]"<$$]
; TODO: Add alias options once aliases are supported
return ${targetOptions}
}
method AddAbility()
{
echo "AddAbility: ${newCastStackItem.AsJSON[multiline]~}"
}
}