mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-13 06:52:33 +00:00
now save player name from SoloLobby, made Director know able game so that construction workers can set active tool for Game (todo: implement tools :D), drafted 'structure' document
This commit is contained in:
@@ -9,19 +9,31 @@ class IMICRTS
|
|||||||
@actions = []
|
@actions = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(action, *args)
|
def add(type, *args)
|
||||||
case action
|
action = Action.new
|
||||||
|
|
||||||
|
case type
|
||||||
when :add_to_build_queue
|
when :add_to_build_queue
|
||||||
action = Action.new
|
|
||||||
ent = IMICRTS::Entity.get(args.first)
|
ent = IMICRTS::Entity.get(args.first)
|
||||||
|
raise "Failed to find entity: #{args.first.inspect}" unless ent
|
||||||
|
|
||||||
action.label = ent.name.to_s.split("_").map{ |s| s.capitalize }.join(" ")
|
action.label = ent.name.to_s.split("_").map{ |s| s.capitalize }.join(" ")
|
||||||
action.description = "Cost: #{ent.cost}\n#{ent.description}"
|
action.description = "Cost: #{ent.cost}\n#{ent.description}"
|
||||||
action.block = proc { @parent.component(:build_queue).add(args.first) }
|
action.block = proc { @parent.component(:build_queue).add(args.first) }
|
||||||
|
|
||||||
@actions << action
|
when :set_build_tool
|
||||||
|
ent = IMICRTS::Entity.get(args[1])
|
||||||
|
raise "Failed to find entity: #{args[1].inspect}" unless ent
|
||||||
|
|
||||||
|
action.label = ent.name.to_s.split("_").map { |s| s.capitalize }.join(" ")
|
||||||
|
action.description = "Cost: #{ent.cost}\n#{ent.description}"
|
||||||
|
action.block = proc { @parent.director.game.set_tool(:building, ent) }
|
||||||
|
|
||||||
else
|
else
|
||||||
raise "Unhandled sidebar action: #{action.inspect}"
|
raise "Unhandled sidebar action: #{action.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@actions << action
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class IMICRTS
|
class IMICRTS
|
||||||
class Director
|
class Director
|
||||||
attr_reader :current_tick, :map
|
attr_reader :current_tick, :map, :game
|
||||||
def initialize(map:, players:, networking_mode:, tick_rate: 10)
|
def initialize(game:, map:, players:, networking_mode:, tick_rate: 10)
|
||||||
|
@game = game
|
||||||
@map = map
|
@map = map
|
||||||
@players = players
|
@players = players
|
||||||
@connection = IMICRTS::Connection.new(director: self, mode: networking_mode)
|
@connection = IMICRTS::Connection.new(director: self, mode: networking_mode)
|
||||||
@@ -121,4 +122,4 @@ class IMICRTS
|
|||||||
@connection.finalize
|
@connection.finalize
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ IMICRTS::Entity.define_entity(:construction_worker, :unit, 1000, "Constructs bui
|
|||||||
entity.has(:build_queue)
|
entity.has(:build_queue)
|
||||||
entity.has(:sidebar_actions)
|
entity.has(:sidebar_actions)
|
||||||
[:power_plant, :refinery, :barracks, :war_factory, :helipad, :construction_yard].each do |ent|
|
[:power_plant, :refinery, :barracks, :war_factory, :helipad, :construction_yard].each do |ent|
|
||||||
entity.component(:sidebar_actions).add(:add_to_build_queue, ent)
|
entity.component(:sidebar_actions).add(:set_build_tool, :place_building, ent)
|
||||||
end
|
end
|
||||||
|
|
||||||
entity.radius = 14
|
entity.radius = 14
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class IMICRTS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :player, :id, :name, :type, :speed
|
attr_reader :director, :player, :id, :name, :type, :speed
|
||||||
attr_accessor :position, :angle, :radius, :target, :state,
|
attr_accessor :position, :angle, :radius, :target, :state,
|
||||||
:movement, :health, :max_health,
|
:movement, :health, :max_health,
|
||||||
:turret, :center, :particle_emitters
|
:turret, :center, :particle_emitters
|
||||||
@@ -188,4 +188,4 @@ end
|
|||||||
|
|
||||||
Dir.glob("#{IMICRTS::GAME_ROOT_PATH}/lib/entities/**/*.rb").each do |entity|
|
Dir.glob("#{IMICRTS::GAME_ROOT_PATH}/lib/entities/**/*.rb").each do |entity|
|
||||||
require_relative entity
|
require_relative entity
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class IMICRTS
|
|||||||
@options[:networking_mode] ||= :host
|
@options[:networking_mode] ||= :host
|
||||||
|
|
||||||
@player = Player.new(id: 0)
|
@player = Player.new(id: 0)
|
||||||
@director = Director.new(map: Map.new(map_file: "maps/test_map.tmx"), networking_mode: @options[:networking_mode], players: [@player])
|
@director = Director.new(game: self, map: Map.new(map_file: "maps/test_map.tmx"), networking_mode: @options[:networking_mode], players: [@player])
|
||||||
@entity_controller = EntityController.new(game: self, director: @director, player: @player)
|
@entity_controller = EntityController.new(game: self, director: @director, player: @player)
|
||||||
|
|
||||||
@overlays = []
|
@overlays = []
|
||||||
@@ -172,8 +172,12 @@ class IMICRTS
|
|||||||
@player.camera.button_up(id)
|
@player.camera.button_up(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_tool(tool, *args)
|
||||||
|
pp tool, args
|
||||||
|
end
|
||||||
|
|
||||||
def finalize
|
def finalize
|
||||||
@director.finalize
|
@director.finalize
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class IMICRTS
|
|||||||
end
|
end
|
||||||
flow do
|
flow do
|
||||||
button("Refresh") do
|
button("Refresh") do
|
||||||
# refresh_games
|
refresh_games
|
||||||
end
|
end
|
||||||
button("Host Game")
|
button("Host Game")
|
||||||
button("Join Game")
|
button("Join Game")
|
||||||
@@ -25,9 +25,9 @@ class IMICRTS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def refresh_games
|
def refresh_games
|
||||||
@games_list.clear do
|
@games_list.clear do |stack|
|
||||||
label "No games found..."
|
stack.label "No games found..."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,15 +35,22 @@ class IMICRTS
|
|||||||
|
|
||||||
flow(width: 1.0) do
|
flow(width: 1.0) do
|
||||||
button("Accept", width: 0.5) do
|
button("Accept", width: 0.5) do
|
||||||
Setting.set(:player_name, @player_name.value)
|
save_playerdata
|
||||||
push_state(Game, networking_mode: :virtual)
|
push_state(Game, networking_mode: :virtual)
|
||||||
end
|
end
|
||||||
|
|
||||||
button("Back", align: :right) do
|
button("Back", align: :right) do
|
||||||
|
save_playerdata
|
||||||
push_state(MainMenu)
|
push_state(MainMenu)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def save_playerdata
|
||||||
|
Setting.set(:player_name, @player_name.value)
|
||||||
|
|
||||||
|
Setting.save!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
13
structure.md
Normal file
13
structure.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# I-MIC RTS - Structure
|
||||||
|
* Dependancy Trees
|
||||||
|
* Entity
|
||||||
|
* Director
|
||||||
|
* Player
|
||||||
|
* Networking
|
||||||
|
|
||||||
|
## Dependancy Trees
|
||||||
|
### Entity
|
||||||
|
An entity requires access to Director
|
||||||
|
|
||||||
|
### Director
|
||||||
|
The Director requires access to most everything as its purpose is to: sync commands to and from other players (local and remote), to execute said commands on the correct tick, and to be the primary for entities to gain access to required features and functions outside of the Director.
|
||||||
Reference in New Issue
Block a user