Skip to content
Prev Previous commit
Next Next commit
black -l 80
  • Loading branch information
Dominik Neise committed Jun 26, 2019
commit 06a79581fe7dbd4b33d4e2649597f86991c81d2d
12 changes: 10 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
("index", "sc2reader.tex", u"sc2reader Documentation", u"Graylin Kim", "manual")
(
"index",
"sc2reader.tex",
u"sc2reader Documentation",
u"Graylin Kim",
"manual",
)
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -213,4 +219,6 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [("index", "sc2reader", u"sc2reader Documentation", [u"Graylin Kim"], 1)]
man_pages = [
("index", "sc2reader", u"sc2reader Documentation", [u"Graylin Kim"], 1)
]
15 changes: 11 additions & 4 deletions examples/sc2autosave.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ def reset(args):
def setup(args):
args.team_compare, args.player_compare = create_compare_funcs(args)
args.action = sc2reader.utils.AttributeDict(
type=args.action, run=shutil.copy if args.action == "COPY" else shutil.move
type=args.action,
run=shutil.copy if args.action == "COPY" else shutil.move,
)
if not os.path.exists(args.source):
msg = "Source does not exist: {0}.\n\nScript Aborted."
Expand Down Expand Up @@ -432,13 +433,19 @@ def main():
parser = argparse.ArgumentParser(
description="Automatically copy new replays to directory",
fromfile_prefix_chars="@",
formatter_class=sc2reader.scripts.utils.Formatter.new(max_help_position=35),
formatter_class=sc2reader.scripts.utils.Formatter.new(
max_help_position=35
),
epilog="And that's all folks",
)

required = parser.add_argument_group("Required Arguments")
required.add_argument("source", type=str, help="The source directory to poll")
required.add_argument("dest", type=str, help="The destination directory to copy to")
required.add_argument(
"source", type=str, help="The source directory to poll"
)
required.add_argument(
"dest", type=str, help="The destination directory to copy to"
)

general = parser.add_argument_group("General Options")
general.add_argument(
Expand Down
4 changes: 3 additions & 1 deletion examples/sc2store.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ class Player(Base):

def __init__(self, player, db):
try:
self.person = db.query(Person).filter(Person.name == player.name).one()
self.person = (
db.query(Person).filter(Person.name == player.name).one()
)
except NoResultFound as e:
self.person = Person()
self.person.name = player.name
Expand Down
39 changes: 29 additions & 10 deletions generate_build_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ def generate_build_data(balance_data_path):
command_index = int(command_index_str)

# Pad potential gaps in command indices with empty strings
while len(ability_lookup[ability_name]) <= command_index:
while (
len(ability_lookup[ability_name]) <= command_index
):
ability_lookup[ability_name].append("")

command_name = (
command_id if command_id != "Execute" else ability_name
command_id
if command_id != "Execute"
else ability_name
)
ability_lookup[ability_name][command_index] = command_name
ability_lookup[ability_name][
command_index
] = command_name

unit_id = root.get("id")

Expand Down Expand Up @@ -74,7 +80,9 @@ def generate_build_data(balance_data_path):
command_index = int(command_index_str)

# Pad potential gaps in command indices with empty strings
while len(ability_lookup[build_ability_name]) <= command_index:
while (
len(ability_lookup[build_ability_name]) <= command_index
):
ability_lookup[build_ability_name].append("")

build_command_name = "Build{}".format(built_unit_id)
Expand Down Expand Up @@ -118,7 +126,8 @@ def generate_build_data(balance_data_path):

# Pad potential gaps in command indices with empty strings
while (
len(ability_lookup[train_ability_name]) <= command_index
len(ability_lookup[train_ability_name])
<= command_index
):
ability_lookup[train_ability_name].append("")

Expand All @@ -133,11 +142,14 @@ def generate_build_data(balance_data_path):

# Pad potential gaps in command indices with empty strings
while (
len(ability_lookup[train_ability_name]) <= command_index
len(ability_lookup[train_ability_name])
<= command_index
):
ability_lookup[train_ability_name].append("")

train_command_name = "Train{}".format(trained_unit_name)
train_command_name = "Train{}".format(
trained_unit_name
)
ability_lookup[train_ability_name][
command_index
] = train_command_name
Expand All @@ -160,10 +172,15 @@ def generate_build_data(balance_data_path):
command_index = int(command_index_str)

# Pad potential gaps in command indices with empty strings
while len(ability_lookup[research_ability_name]) <= command_index:
while (
len(ability_lookup[research_ability_name])
<= command_index
):
ability_lookup[research_ability_name].append("")

research_command_name = "Research{}".format(researched_upgrade_id)
research_command_name = "Research{}".format(
researched_upgrade_id
)
ability_lookup[research_ability_name][
command_index
] = research_command_name
Expand All @@ -175,7 +192,9 @@ def generate_build_data(balance_data_path):
sorted(abilities.items(), key=lambda x: int(x[0]))
)

unit_lookup = dict((unit_name, unit_name) for _, unit_name in sorted_units.items())
unit_lookup = dict(
(unit_name, unit_name) for _, unit_name in sorted_units.items()
)

return sorted_units, sorted_abilities, unit_lookup, ability_lookup

Expand Down
4 changes: 3 additions & 1 deletion new_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
print("")

ABIL_LOOKUP = dict()
for entry in pkgutil.get_data("sc2reader.data", "ability_lookup.csv").split("\n"):
for entry in pkgutil.get_data("sc2reader.data", "ability_lookup.csv").split(
"\n"
):
if not entry:
continue
str_id, abilities = entry.split(",", 1)
Expand Down
11 changes: 9 additions & 2 deletions sc2reader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
:copyright: (c) 2011 by Graylin Kim.
:license: MIT, see LICENSE for more details.
"""
from __future__ import absolute_import, print_function, unicode_literals, division
from __future__ import (
absolute_import,
print_function,
unicode_literals,
division,
)

__version__ = "0.8.0"

Expand Down Expand Up @@ -95,7 +100,9 @@ def useDoubleCache(cache_dir, cache_max_size=0, **options):
A limited number of remote resources are cached in memory for faster access times.
All remote resources are saved to the file system for faster access times.
"""
setFactory(factories.DoubleCachedSC2Factory(cache_dir, cache_max_size, **options))
setFactory(
factories.DoubleCachedSC2Factory(cache_dir, cache_max_size, **options)
)


# Allow environment variables to activate caching
Expand Down
35 changes: 30 additions & 5 deletions sc2reader/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals, division
from __future__ import (
absolute_import,
print_function,
unicode_literals,
division,
)

# These are found in Repack-MPQ/fileset.{locale}#Mods#Core.SC2Mod#{locale}.SC2Data/LocalizedData/Editor/EditorCategoryStrings.txt
# EDSTR_CATEGORY_Race
Expand Down Expand Up @@ -46,9 +51,27 @@


GAME_SPEED_FACTOR = {
"WoL": {"Slower": 0.6, "Slow": 0.8, "Normal": 1.0, "Fast": 1.2, "Faster": 1.4},
"HotS": {"Slower": 0.6, "Slow": 0.8, "Normal": 1.0, "Fast": 1.2, "Faster": 1.4},
"LotV": {"Slower": 0.2, "Slow": 0.4, "Normal": 0.6, "Fast": 0.8, "Faster": 1.0},
"WoL": {
"Slower": 0.6,
"Slow": 0.8,
"Normal": 1.0,
"Fast": 1.2,
"Faster": 1.4,
},
"HotS": {
"Slower": 0.6,
"Slow": 0.8,
"Normal": 1.0,
"Fast": 1.2,
"Faster": 1.4,
},
"LotV": {
"Slower": 0.2,
"Slow": 0.4,
"Normal": 0.6,
"Fast": 0.8,
"Faster": 1.0,
},
}

GATEWAY_CODES = {
Expand Down Expand Up @@ -107,7 +130,9 @@
import json
import pkgutil

attributes_json = pkgutil.get_data("sc2reader.data", "attributes.json").decode("utf8")
attributes_json = pkgutil.get_data("sc2reader.data", "attributes.json").decode(
"utf8"
)
attributes_dict = json.loads(attributes_json)
LOBBY_PROPERTIES = dict()
for key, value in attributes_dict.get("attributes", dict()).items():
Expand Down
48 changes: 40 additions & 8 deletions sc2reader/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals, division
from __future__ import (
absolute_import,
print_function,
unicode_literals,
division,
)

import json
import pkgutil
Expand All @@ -18,7 +23,9 @@

ABIL_LOOKUP = dict()
for entry in (
pkgutil.get_data("sc2reader.data", "ability_lookup.csv").decode("utf8").split("\n")
pkgutil.get_data("sc2reader.data", "ability_lookup.csv")
.decode("utf8")
.split("\n")
):
if not entry:
continue
Expand All @@ -27,7 +34,9 @@

UNIT_LOOKUP = dict()
for entry in (
pkgutil.get_data("sc2reader.data", "unit_lookup.csv").decode("utf8").split("\n")
pkgutil.get_data("sc2reader.data", "unit_lookup.csv")
.decode("utf8")
.split("\n")
):
if not entry:
continue
Expand All @@ -37,7 +46,9 @@
unit_data = pkgutil.get_data("sc2reader.data", "unit_info.json").decode("utf8")
unit_lookup = json.loads(unit_data)

command_data = pkgutil.get_data("sc2reader.data", "train_commands.json").decode("utf8")
command_data = pkgutil.get_data("sc2reader.data", "train_commands.json").decode(
"utf8"
)
train_commands = json.loads(command_data)


Expand Down Expand Up @@ -275,7 +286,13 @@ class Ability(object):
""" Represents an in-game ability """

def __init__(
self, id, name=None, title=None, is_build=False, build_time=0, build_unit=None
self,
id,
name=None,
title=None,
is_build=False,
build_time=0,
build_unit=None,
):
#: The internal integer id representing this ability.
self.id = id
Expand Down Expand Up @@ -432,7 +449,9 @@ def load_build(expansion, version):
int_id_base = int(int_id_base, 10) << 5

abils = ABIL_LOOKUP[str_id]
real_abils = [(i, abil) for i, abil in enumerate(abils) if abil.strip() != ""]
real_abils = [
(i, abil) for i, abil in enumerate(abils) if abil.strip() != ""
]

if len(real_abils) == 0:
real_abils = [(0, str_id)]
Expand Down Expand Up @@ -469,7 +488,20 @@ def load_build(expansion, version):

# Load LotV Data
lotv_builds = dict()
for version in ("base", "44401", "47185", "48258", "53644", "54724", "59587", "70154"):
for version in (
"base",
"44401",
"47185",
"48258",
"53644",
"54724",
"59587",
"70154",
):
lotv_builds[version] = load_build("LotV", version)

datapacks = builds = {"WoL": wol_builds, "HotS": hots_builds, "LotV": lotv_builds}
datapacks = builds = {
"WoL": wol_builds,
"HotS": hots_builds,
"LotV": lotv_builds,
}
15 changes: 12 additions & 3 deletions sc2reader/decoders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals, division
from __future__ import (
absolute_import,
print_function,
unicode_literals,
division,
)

from io import BytesIO

Expand Down Expand Up @@ -63,7 +68,9 @@ def __init__(self, contents, endian):
self._unpack_int = struct.Struct(str(self.endian + "I")).unpack
self._unpack_short = struct.Struct(str(self.endian + "H")).unpack
self._unpack_longlong = struct.Struct(str(self.endian + "Q")).unpack
self._unpack_bytes = lambda bytes: bytes if self.endian == ">" else bytes[::-1]
self._unpack_bytes = (
lambda bytes: bytes if self.endian == ">" else bytes[::-1]
)

def done(self):
""" Returns true when all bytes have been decoded """
Expand Down Expand Up @@ -265,7 +272,9 @@ def read_bytes(self, count):
lo_mask, hi_mask = self._bit_masks[self._bit_shift]
for next_byte in struct.unpack(str("B") * count, data):
temp_buffer.write(
struct.pack(str("B"), prev_byte & hi_mask | next_byte & lo_mask)
struct.pack(
str("B"), prev_byte & hi_mask | next_byte & lo_mask
)
)
prev_byte = next_byte

Expand Down
7 changes: 6 additions & 1 deletion sc2reader/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals, division
from __future__ import (
absolute_import,
print_function,
unicode_literals,
division,
)

import sys
from sc2reader.engine.engine import GameEngine
Expand Down
Loading