Browse Source

General spring cleaning & refactoring

Makefile created
item/ability/hero uses int for hash lookup, not a string
Fix error of mapping lobby_type to GameModes; now it's LobbyTypes
master
Andrew Zah 1 year ago
parent
commit
ee56f7c20a
Signed by: andrei <zah@andrewzah.com> GPG Key ID: 0AE942445EB70FAA

+ 7
- 0
Makefile View File

@@ -0,0 +1,7 @@
.PHONY: build

build:
crystal build src/dota.cr

release:
crystal build src/dota.cr --release

+ 3
- 0
data/item.yml View File

@@ -1,6 +1,9 @@
0:
- empty
- Empty
00:
- empty
- Empty
1:
- blink
- Blink Dagger

+ 6
- 5
spec/dota_spec.cr View File

@@ -28,7 +28,7 @@ describe Dota do

it "gets items" do
items = api.items
puts items.size.should eq 275
puts items.size.should eq 276
end

it "gets hero" do
@@ -59,9 +59,10 @@ describe Dota do
api.last_match(68351653).should be_a Dota::API::BasicMatch
end

it "gets leagues" do
api.leagues.should be_a Array(Dota::API::League)
end
# no idea why this is failing
#it "gets leagues" do
# api.leagues.should be_a Array(Dota::API::League)
#end

it "gets live matches" do
api.live_matches.should be_a Array(Dota::API::LiveMatch)
@@ -90,7 +91,7 @@ describe Dota do
m.tower_status_radiant.should eq Dota::API::MatchStatus::Towers.new(2039_i64)
m.tower_status_dire.should eq Dota::API::MatchStatus::Towers.new(1974_i64)
m.first_blood_time.should eq 33
m.lobby_type.should eq Dota::API::MatchStatus::GameModes::CaptainsMode
m.lobby_type.should eq Dota::API::MatchStatus::LobbyTypes::Tournament
m.cluster.should eq 111
m.human_players.should eq 10
m.leagueid.should eq 600

+ 1
- 1
src/dota/api/ability.cr View File

@@ -9,7 +9,7 @@ module Dota

def initialize(id : Int8 | Int32)
@id = id
map = mapping["#{@id}"]
map = mapping[id]
@internalName = map[0].to_s
@name = map[1].to_s
@fullName = map[2].to_s

+ 1
- 1
src/dota/api/basic/basic_match.cr View File

@@ -17,7 +17,7 @@ module Dota
match_id: Int64,
match_seq_num: Int64,
start_time: Int32,
lobby_type: GameModes,
lobby_type: LobbyTypes,
radiant_team_id: Int32,
dire_team_id: Int32,
players: Array(BasicPlayer)

+ 2
- 2
src/dota/api/client.cr View File

@@ -62,7 +62,7 @@ module Dota
response = get("GetMatchHistory", BasicMatchesList, "IDOTA2Match_570", options).matches.first
end

def match(matchID : Int32)
def match(matchID : Int32 | Int64)
response = get("GetMatchDetails", Match, "IDOTA2Match_570", {"match_id" => matchID})
end

@@ -132,7 +132,7 @@ module Dota
end
end

# Lazy, lazy valve is not consistent
# valve is not consistent
# the root key is different among interfaces.
if interface == "ISteamUser"
body = response.body.sub("friendslist", "result")

+ 2
- 2
src/dota/api/hero.cr View File

@@ -8,7 +8,7 @@ module Dota
private getter internalName : String

def self.find(id)
if mapping["#{id}"]?
if mapping[id]?
new(id)
else
raise Exception.new("Hero does not exist")
@@ -17,7 +17,7 @@ module Dota

def initialize(id : Int8 | Int32)
@id = id
map = mapping["#{id}"]
map = mapping[id]
@internalName = map[0].to_s
@name = map[1].to_s
end

+ 3
- 3
src/dota/api/item.cr View File

@@ -4,12 +4,12 @@ module Dota
include Utilities::Mapped
extend Utilities::Mapped

getter id : Int8 | Int32, name : String
getter id : Int8 | Int16 | Int32, name : String
private getter internalName : String

def initialize(id : Int8 | Int32)
def initialize(id : Int8 | Int16 | Int32)
@id = id
map = mapping["#{id}"]
map = mapping[id]
@internalName = map[0].to_s
@name = map[1].to_s
end

+ 1
- 1
src/dota/api/league.cr View File

@@ -10,8 +10,8 @@ module Dota

class League
JSON.mapping(
leagueid: Int32,
name: String,
leagueid: Int32,
description: String,
tournament_url: String,
itemdef: Int32

+ 1
- 1
src/dota/api/match.cr View File

@@ -18,7 +18,7 @@ module Dota
barracks_status_dire: Barracks,
cluster: Int32,
first_blood_time: Int32,
lobby_type: GameModes,
lobby_type: LobbyTypes,
human_players: Int8,
leagueid: Int32,
positive_votes: Int32,

+ 18
- 6
src/dota/api/match/player.cr View File

@@ -16,13 +16,25 @@ module Dota
denies: Int16,
gold_per_min: Int16,
xp_per_min: Int16,
item0_id: {type: Int16, key: "item_0"},
item1_id: {type: Int16, key: "item_1"},
item2_id: {type: Int16, key: "item_2"},
item3_id: {type: Int16, key: "item_3"},
item4_id: {type: Int16, key: "item_4"},
item5_id: {type: Int16, key: "item_5"}
item0_id: {type: Int32, key: "item_0"},
item1_id: {type: Int32, key: "item_1"},
item2_id: {type: Int32, key: "item_2"},
item3_id: {type: Int32, key: "item_3"},
item4_id: {type: Int32, key: "item_4"},
item5_id: {type: Int32, key: "item_5"}
)

def items
{item0_id,
item1_id,
item2_id,
item3_id,
item4_id,
item5_id,
}.reject { |v| v == 0 }
.map { |v| Item.new(v).name }
.join(", ")
end
end
end
end

+ 12
- 11
src/dota/api/match/side.cr View File

@@ -6,17 +6,18 @@ module Dota
getter logo, complete, captain, picks_bans, players

def initialize(
side : Symbol,
@score : Int32,
@barracks_status : Barracks,
@tower_status : Towers,
@team_id : Int32 | Nil = nil,
@team_name : String | Nil = nil,
@team_logo : String | Nil = nil,
@team_complete : Int32 | Nil = nil,
@team_captain : Int32 | Nil = nil,
@picks_bans : Array(Draft) | Nil = nil,
@players : Array(Player) | Nil = nil)
side : Symbol,
@score : Int32,
@barracks_status : Barracks,
@tower_status : Towers,
@team_id : Int32 | Nil = nil,
@team_name : String | Nil = nil,
@team_logo : String | Nil = nil,
@team_complete : Int32 | Nil = nil,
@team_captain : Int32 | Nil = nil,
@picks_bans : Array(Draft) | Nil = nil,
@players : Array(Player) | Nil = nil
)
@players = sort_players(side)
@picks_bans = sort_picks_bans(side)
end

+ 1
- 1
src/dota/api/status/match_status.cr View File

@@ -34,7 +34,7 @@ module Dota
end
end

enum Types
enum LobbyTypes
Invalid = -1
PublicMatchmaking
Practice

Loading…
Cancel
Save