Inital work on gamesaves/replays

This commit is contained in:
2021-01-15 21:25:55 -06:00
parent f6f2de1433
commit 37bab6ae3d
6 changed files with 80 additions and 16 deletions

50
lib/game_save.rb Normal file
View File

@@ -0,0 +1,50 @@
class IMICRTS
class GameSave
def initialize(mode:, gamesave_file:, map_file: nil, players: nil, gamesave: false, player_id: nil)
@mode = mode
@gamesave_file = File.open(gamesave_file, "#{@mode == :write ? 'w' : 'r'}")
@map_file = map_file
@players = players
@gamesave = gamesave
@player_id = player_id
@version = IMICRTS::VERSION
end
def parse
#
end
def feed_tick(tick_id)
end
def write_header
player_data = @players.map do |player|
{
id: player.id,
name: player.name,
team: player.team,
spawnpoint: player.spawnpoint,
color: player.color&.gl,
bot: player.bot
}
end
s = %{#{@version}
#{@map_file}?#{Digest::SHA256.digest(File.read("#{IMICRTS::GAME_ROOT_PATH}/assets/#{@map_file}"))}
#{@gamesave ? "GAMESAVE?#{@player_id}" : "REPLAY"}
#{JSON.dump(player_data)}}
@gamesave_file.puts(s)
end
def write_order(raw_order)
@gamesave_file.puts(raw_order)
end
def finalize
@gamesave_file&.close
end
end
end