Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
geraintwhite committed Feb 4, 2021
1 parent fbe23b5 commit 79c8a2d
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 31 deletions.
2 changes: 1 addition & 1 deletion data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from colours import *
from colours import DARK, BOLD, DARK_GRAY, YELLOW, RED, WHITE
from console import supported_chars


Expand Down
2 changes: 1 addition & 1 deletion events.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def boom(server, x, y):

server.splash_damage(x, y, radius*2, blast_strength/3)

return new_blocks
return new_blocks
2 changes: 1 addition & 1 deletion items.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def items_to_render_objects(items, x, offset):

objects.append(object_)

return objects
return objects
5 changes: 2 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def setdown():

def game(server, settings, benchmarks):
dt = 0 # Tick
df = 0 # Frame
dc = 0 # Cursor
ds = 0 # Selector
dpos = False
Expand Down Expand Up @@ -286,14 +285,14 @@ def game(server, settings, benchmarks):
events += new_events

new_blocks = {}
for i in range(int(dt)):
for _ in range(int(dt)):
new_blocks.update(process_events(events, server))
if new_blocks:
server.set_blocks(new_blocks)

# If no block below, kill player
try:
block = server.map_[x][y+1]
_ = server.map_[x][y+1]
except IndexError:
alive = False

Expand Down
4 changes: 2 additions & 2 deletions mobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def update(mobs, players, map_, last_tick):
new_items = {}

for mob_id, mob in mobs.items():
mx, my, x_vel = mob['x'], mob['y'], mob['x_vel']
mx, my = mob['x'], mob['y']

if mob['health'] <= 0:
removed_mobs.append(mob_id)
Expand Down Expand Up @@ -64,7 +64,7 @@ def update(mobs, players, map_, last_tick):


def spawn(mobs, players, map_, x_start_range, y_start_range, x_end_range, y_end_range):
log("spawning", x_start_range, x_end_range, m='mobs');
log('spawning', x_start_range, x_end_range, m='mobs')

n_mobs_to_spawn = random.randint(0, 5) if random.random() < mob_rate else 0
new_mobs = {}
Expand Down
4 changes: 2 additions & 2 deletions network.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def receive(sock):
d = bytes()

try:
for i in range(length // bufsize):
for _ in range(length // bufsize):
d += sock.recv(bufsize)
time.sleep(0.001)
d += sock.recv(length % bufsize)
Expand Down Expand Up @@ -107,7 +107,7 @@ def start(data_handler, port):
HOST, PORT = '0.0.0.0', int(port)

server = ThreadedTCPServer((HOST, PORT), requestHandlerFactory(data_handler))
ip, port = server.server_address
_, port = server.server_address

# Start a thread with the server -- that thread will then start one
# more thread for each request
Expand Down
2 changes: 1 addition & 1 deletion pathfinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def pathfind_towards_delta(entity, delta, map_):

updated = True

return updated, kill_entity
return updated, kill_entity
2 changes: 1 addition & 1 deletion player.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_pos_delta_on_input(inp, map_, x, y, jump, flight):
return dx, dy, jump


def get_pos_delta(dx, x, y, map_, flight):
def get_pos_delta(dx, x, y, map_, flight=False):

player_slice = map_[x]

Expand Down
7 changes: 3 additions & 4 deletions render.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from math import pi, cos, sin, sqrt, modf, radians

from colours import *
from console import *
from colours import colour_str, uncolour_str, rgb, round_to_palette, lightness, bold, RED, CYAN, BLUE
from console import supported_chars, DEBUG, POS_STR, CLS_END_LN
from data import lighting, world_gen, blocks, timings
from terrain import is_solid

Expand Down Expand Up @@ -104,7 +104,6 @@ def obj_pixel(x, y, objects):

if object_:
model = object_['model']
width = len(model)
height = len(model[0])

dx = x - object_['x']
Expand Down Expand Up @@ -240,7 +239,7 @@ def get_light_colour(x, y, world_x, map_, slice_heights, lights, colour_behind,

else:

light = CYAN if any(map(lambda l: lit(world_x, x, y, l) < 1, lights)) else hsv_to_rgb(colour_behind)
light = CYAN if any(map(lambda l: lit(world_x + x, y, l) < 1, lights)) else hsv_to_rgb(colour_behind)

return light

Expand Down
2 changes: 1 addition & 1 deletion render_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def get_light_level(*args):
log('Not implemented: Python get_light_level function', m='warning')

log('{}'.format(result), m='lighting')
return result
return result
2 changes: 1 addition & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def spawn_mobs(self, n_mob_spawn_cycles, bk_objects, sky_colour, day, lights):

render_interface.create_lighting_buffer(width, height, x_start, y_start, self._map, self._slice_heights, bk_objects, sky_colour, day, lights)

for i in range(n_mob_spawn_cycles):
for _ in range(n_mob_spawn_cycles):
mobs.spawn(self._meta['mobs'], self._meta['players'], self._map, x_start, y_start, x_end, y_end)

def update_items(self):
Expand Down
4 changes: 1 addition & 3 deletions server_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,13 @@ def _event_logout(self, error=None):
self.game = False

def _event_error(self, error):
self.error = 'Error from server: ' + error['event'] + ': ' + event['message']
self.error = 'Error from server: ' + error['event'] + ': ' + error['message']
log(self.error)
self.game = False

# Main loop methods:

def get_chunks(self, chunk_list):
slices_its_loading = ((chunk_num + chunk * chunk_size) for chunk in chunk_list for chunk_num in range(chunk_size))

self.handle(self._send('get_chunks', [chunk_list]))
self.view_change = True

Expand Down
11 changes: 4 additions & 7 deletions terrain_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TerrainCache(OrderedDict):
Beyond which it replaces the oldest item. """

def __init__(self, *args, **kwds):
self._limit = kwds.pop("limit", None)
self._limit = kwds.pop('limit', None)
OrderedDict.__init__(self, *args, **kwds)
self._check_limit()

Expand Down Expand Up @@ -81,7 +81,7 @@ def gen_hill_chunk_features(chunk_pos, chunk_features_in_range, seed):
def gen_biome_slice_features(x, chunk_features_in_range, slice_features, seed):

slice_biome = ('normal', None)
slice_biome_distance_to_centre = float("inf")
slice_biome_distance_to_centre = float('inf')

if chunk_features_in_range.get('biomes') is not None:
for biome in chunk_features_in_range.get('biomes'):
Expand Down Expand Up @@ -248,7 +248,7 @@ def gen_cave_features(features, chunk_pos, meta):

if features[chunk_pos].get('cave') is None:
# Perform cellular automata
for i in range(ca_iterations):
for _ in range(ca_iterations):
new_air_points = set()

for x in range(air_points_x_min, air_points_x_max):
Expand All @@ -274,7 +274,6 @@ def generate_slice_features(features, chunk_pos, meta, feature_generator, featur
log("generate_slice_features range", chunk_pos - feature_buffer[0], chunk_pos + world_gen['chunk_size'] + feature_buffer[1], m=1)

# Generate dictionary of chunk-features (features on chunk positions) within the feature_buffer range.
chunk_n = ceil(chunk_pos / world_gen['chunk_size'])
feature_buffer_chunk = (ceil(feature_buffer[0] / world_gen['chunk_size']) * world_gen['chunk_size'],
ceil(feature_buffer[1] / world_gen['chunk_size']) * world_gen['chunk_size'])
feature_buffer_range = range(chunk_pos - feature_buffer_chunk[0],
Expand All @@ -283,8 +282,6 @@ def generate_slice_features(features, chunk_pos, meta, feature_generator, featur

for x in range(chunk_pos - feature_buffer[0], chunk_pos + world_gen['chunk_size'] + feature_buffer[1]):

slice_chunk_pos = (x // world_gen['chunk_size']) * world_gen['chunk_size']

if features.get(x) is None:
# Init to empty, so 'no features' is cached.
features[x] = {}
Expand Down Expand Up @@ -339,4 +336,4 @@ def gen_chunk_features(chunk_n, meta):
generate_slice_features(FEATURES, chunk_pos, meta, gen_grass_features, 'grass', (0, 0))
generate_slice_features(FEATURES, chunk_pos, meta, gen_ore_features, 'ores', MAX_ORE_RANGE)

return FEATURES
return FEATURES
2 changes: 1 addition & 1 deletion translate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ def main():


if __name__ == '__main__':
main()
main()
3 changes: 1 addition & 2 deletions ui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from nbinput import BlockingInput, UP, DOWN, RIGHT, LEFT
from console import CLS, REDRAW, WIDTH, HEIGHT, SHOW_CUR, HIDE_CUR
from colours import *
from console import *
from colours import colour_str, TERM_YELLOW, TERM_RED, BOLD
from data import help_data

import saves
Expand Down

0 comments on commit 79c8a2d

Please sign in to comment.