mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-15 15:52:34 +00:00
Added last 2 units, added sidebar actions and build queue components, entities can now have their build actions put on the sidebar
This commit is contained in:
27
lib/components/sidebar_actions.rb
Normal file
27
lib/components/sidebar_actions.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
class IMICRTS
|
||||
class SidebarActions < Component
|
||||
Action = Struct.new(:label, :image, :description, :block)
|
||||
|
||||
attr_reader :actions
|
||||
def initialize(parent:)
|
||||
@parent = parent
|
||||
|
||||
@actions = []
|
||||
end
|
||||
|
||||
def add(action, *args)
|
||||
case action
|
||||
when :add_to_build_queue
|
||||
action = Action.new
|
||||
ent = IMICRTS::Entity.get(args.first)
|
||||
action.label = ent.name.to_s
|
||||
action.description = "Cost: #{ent.cost}\n#{ent.description}"
|
||||
action.block = proc { @parent.component(:build_queue).add(args.first) }
|
||||
|
||||
@actions << action
|
||||
else
|
||||
raise "Unhandled sidebar action: #{action.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user