Skip to content

Commit

Permalink
Fix action_usable and support spell ids, names, exact match (#9)
Browse files Browse the repository at this point in the history
* let's just pass kwargs into the trigger directly, so we can use id, name and exact

* while we're here, let's fix these titles
  • Loading branch information
fx authored Jun 20, 2024
1 parent 8b7504d commit f28364c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions public/weak_aura/triggers/action_usable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module Trigger
class ActionUsable < Base # rubocop:disable Style/Documentation
def initialize(**_options)
super
@options = {
exact: false
}.merge(@options)
@options[:spell_name] = @options[:spell] if @options[:spell_name].nil?
end

Expand All @@ -13,6 +16,7 @@ def as_json # rubocop:disable Metrics/MethodLength
type: 'spell',
subeventSuffix: '_CAST_START',
spellName: options[:spell],
use_exact_spellName: !!options[:exact],
use_genericShowOn: true,
event: 'Action Usable',
names: [],
Expand Down
31 changes: 21 additions & 10 deletions public/whack_aura.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,40 @@ def debuff_missing(*args, **kwargs, &block)
auras(*args, **kwargs, &block)
end

# rubocop:disable Metrics/MethodLength
# rubocop:disable all
def action_usable(
names, requires: {
spells, requires: {
target_debuffs_missing: [],
auras: [],
events: []
},
if_missing: [],
if_stacks: {},
on_show: {},
title: nil,
&block
)
names = [names] unless names.is_a?(Array)
spells = [spells] unless spells.is_a?(Array)
if title.nil?
title = spells.map do |spell|
if spell.is_a?(String)
spell
else
spell[:spell_name] || spell[:spell]
end
end.join(' + ')
end
triggers = spells.to_a.map do |kwargs|
kwargs = { spell: kwargs } if kwargs.is_a?(String)
Trigger::ActionUsable.new(**kwargs)
end

triggers = make_triggers(
requires,
if_missing: if_missing,
if_stacks: if_stacks,
triggers: names.map do |name|
Trigger::ActionUsable.new(spell: name)
end
).merge({ disjunctive: names.size > 1 ? 'any' : 'all', activeTriggerMode: -10 })
triggers: triggers
).merge({ disjunctive: spells.size > 1 ? 'any' : 'all', activeTriggerMode: -10 })

if on_show[:event]
actions =
Expand All @@ -73,9 +85,8 @@ def action_usable(

end

node = WeakAura::Icon.new(id: name, parent: self, triggers: triggers, actions: actions, &block)
# block.call(triggers, node) if block_given?
node = WeakAura::Icon.new(id: title, parent: self, triggers: triggers, actions: actions, &block)
add_node(node)
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable
end

0 comments on commit f28364c

Please sign in to comment.