Skip to content

Commit

Permalink
Flake fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielBingham committed Jan 12, 2024
1 parent 10a0024 commit e205d9e
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 105 deletions.
3 changes: 0 additions & 3 deletions game/account_menu/creation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from game.interpreters.state.state import State

from game.account_menu.password import GetNewAccountPassword


class CreateNewAccount(State):
"Create a new account for `player`."

Expand Down
2 changes: 0 additions & 2 deletions game/account_menu/password.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from game.interpreters.state.state import State

import game.account_menu.menu


class GetNewAccountPassword(State):
"Get a new password for an account."
Expand Down
4 changes: 0 additions & 4 deletions game/account_menu/welcome.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from game.interpreters.state.state import State

from game.account_menu.creation import CreateNewAccount
from game.account_menu.menu import AccountMenu


class WelcomeScreen(State):
"""
Introduce the game to the new player and start them on the account flow.
Expand Down
3 changes: 0 additions & 3 deletions game/commands/system.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from game.interpreters.command.command import Command
from game.interpreters.state.interpreter import StateInterpreter
from game.account_menu.menu import AccountMenu


class Quit(Command):
'Leave the game.'
Expand Down
2 changes: 1 addition & 1 deletion game/library/movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def move(self, direction, player, arguments):
def moveInDirection(self, player, direction):
room = player.character.room
if direction in room.exits:
if room.exits[direction].is_door and room.exits[direction].is_open == False:
if room.exits[direction].is_door and room.exits[direction].is_open is False:
player.write("The way " + room.exits[direction] + " is closed.")
return False

Expand Down
4 changes: 2 additions & 2 deletions game/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def setAccountState(self, state_string):
The name of the state we want to set for the character.
"""

if self.status != self.STATUS_ACCOUNT and state_string != None:
if self.status != self.STATUS_ACCOUNT and state_string is not None:
raise ValueError("Can't set player account state when the player is in the game.")
elif state_string != None:
elif state_string is not None:
self.last_account_state = self.current_account_state
self.current_account_state = state_string
if self.last_account_state != self.current_account_state:
Expand Down
2 changes: 1 addition & 1 deletion game/sockets/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import socket, telnetlib
import telnetlib

###
# ClientSocket
Expand Down
4 changes: 2 additions & 2 deletions game/sockets/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def handleWriteSet(self):
def handleErrorSet(self):
while self.erroring:
client = self.erroring.pop()
client.handleError();
client.handleError()

def hasNewConnection(self):
return self.newConnections

def accept(self):
try:
client = ClientSocket(self.server.accept(), self)
except socket.error as error:
except socket.error:
return None

self.clients.append(client)
Expand Down
15 changes: 7 additions & 8 deletions game/store/models/account.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json, os, bcrypt
import bcrypt

from game.store.models.base import NamedModel
from game.store.models.character import Character


class Account(NamedModel):
Expand All @@ -28,16 +27,16 @@ def isPassword(self, password):
return bcrypt.checkpw(password.encode('utf-8'), self.password_hash)

def toJson(self):
json = {}
json['name'] = self.name
data = {}
data['name'] = self.name

json['password_hash'] = self.password_hash.decode('utf-8', 'strict')
data['password_hash'] = self.password_hash.decode('utf-8', 'strict')

json['characters'] = []
data['characters'] = []
for name in self.characters:
json['characters'].append(name)
data['characters'].append(name)

return json
return data

def fromJson(self, data):
self.setId(data['name'])
Expand Down
92 changes: 44 additions & 48 deletions game/store/models/character.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import json

from game.store.models.base import NamedModel
from game.store.models.base import JsonSerializable

from game.account_menu.menu import AccountMenu


class Attributes(JsonSerializable):

Expand All @@ -26,18 +22,18 @@ def __init__(self):
self.max_constitution = 10

def toJson(self):
json = {}
data = {}

json['strength'] = self.strength
json['maxStrength'] = self.max_strength
data['strength'] = self.strength
data['maxStrength'] = self.max_strength

json['stamina'] = self.stamina
json['maxStamina'] = self.max_stamina
data['stamina'] = self.stamina
data['maxStamina'] = self.max_stamina

json['constitution'] = self.constitution
json['maxConstitution'] = self.max_constitution
data['constitution'] = self.constitution
data['maxConstitution'] = self.max_constitution

return json
return data

def fromJson(self, data):
self.strength = data['strength']
Expand Down Expand Up @@ -194,22 +190,22 @@ def energyString(self, prompt=False):

def toString(self):
reservesString = ("You are %s, %s, and %s.\nYou are %s and %s." %
(self.hungerString(), self.thirstString(), self.sleepString(), self.windString(), self.energyString()))
(self.hungerString(), self.thirstString(), self.sleepString(), self.windString(), self.energyString()))
return reservesString

def toJson(self):
json = {}
data = {}

json["calories"] = self.calories
json["maxCalories"] = self.max_calories
data["calories"] = self.calories
data["maxCalories"] = self.max_calories

json["thirst"] = self.thirst
json["maxThirst"] = self.max_thirst
data["thirst"] = self.thirst
data["maxThirst"] = self.max_thirst

json["sleep"] = self.sleep
json["maxSleep"] = self.max_sleep
data["sleep"] = self.sleep
data["maxSleep"] = self.max_sleep

return json
return data

def fromJson(self, data):

Expand Down Expand Up @@ -251,12 +247,12 @@ def __init__(self):
self.pain = 0

def toJson(self):
json = {}
json['type'] = self.wound
json['bleed'] = self.bleed
json['infected'] = self.infected
json['pain'] = self.pain
return json
data = {}
data['type'] = self.wound
data['bleed'] = self.bleed
data['infected'] = self.infected
data['pain'] = self.pain
return data

def fromJson(self, data):
self.type = data['type']
Expand Down Expand Up @@ -289,16 +285,16 @@ def wound(self, body_part, wound):
return False

def toJson(self):
json = {}
json['wounds'] = {}
data = {}
data['wounds'] = {}
for body_part in self.wounds:
json['wounds'][body_part] = self.wounds[body_part]
data['wounds'][body_part] = self.wounds[body_part]

json['worn'] = {}
data['worn'] = {}
for body_part in self.worn:
json['worn'][body_part] = self.worn[body_part].getId()
data['worn'][body_part] = self.worn[body_part].getId()

return json
return data

def fromJson(self, data):
if 'wounds' in data:
Expand Down Expand Up @@ -455,29 +451,29 @@ def __init__(self):
self.room = None

def toJson(self):
json = {}
data = {}

json['name'] = self.name
json['description'] = self.description
json['details'] = self.details
json['sex'] = self.sex
json['position'] = self.position
json['speed'] = self.speed
data['name'] = self.name
data['description'] = self.description
data['details'] = self.details
data['sex'] = self.sex
data['position'] = self.position
data['speed'] = self.speed

json['attributes'] = self.attributes.toJson()
json['reserves'] = self.reserves.toJson()
data['attributes'] = self.attributes.toJson()
data['reserves'] = self.reserves.toJson()

json['bodyType'] = self.body_type
json['body'] = self.body.toJson()
data['bodyType'] = self.body_type
data['body'] = self.body.toJson()

json['inventory'] = []
data['inventory'] = []
for item in self.inventory:
json['inventory'].append(item.getId())
data['inventory'].append(item.getId())

if self.room:
json['room'] = self.room.getId()
data['room'] = self.room.getId()

return json
return data

def fromJson(self, data):
self.setId(data['name'])
Expand Down
2 changes: 1 addition & 1 deletion game/store/models/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def describe(self, player):
output += "---\n"
output += "Exits: "
for direction in Room.DIRECTIONS:
if not direction in self.exits:
if direction not in self.exits:
continue

output += self.exits[direction].room_to.getColorString()
Expand Down
2 changes: 1 addition & 1 deletion game/store/store.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json, glob, copy, os
import glob, copy, os

from game.store.models.world import World
from game.store.models.account import Account
Expand Down
4 changes: 2 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# Generates a world of the given size.
###############################################################################
import sys, argparse, random, glob, math
import sys, argparse, random, glob

import generator.utils.snapshot as snapshot

Expand Down Expand Up @@ -35,7 +35,7 @@ def loadBiomes():
if not biome.load(file_path):
print("Error! Failed to load %s..." % file_path)
else:
if not biome.name in biomes:
if biome.name not in biomes:
biomes[biome.name] = biome
else:
print("Error! Duplicate Biome(%s)" % biome.name)
Expand Down
2 changes: 1 addition & 1 deletion generator/biome.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def load(self, path):
file = open(path, 'r')
try:
self.fromJson(json.load(file))
except:
except Exception:
return False
finally:
file.close()
Expand Down
5 changes: 1 addition & 4 deletions generator/generators/biomes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import sys, glob, random

from generator.biome import Biome
import random

initial_biomes_by_height = [
{'height': 2000, 'biome': 'pioneer-meadow'}
]


def getInitialBiomeFromHeight(height):
for item in initial_biomes_by_height:
if height <= item['height']:
Expand Down
6 changes: 3 additions & 3 deletions generator/generators/erosion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# https://hal.inria.fr/inria-00402079/document

import numpy as np
import scipy as sp

import generator.utils.util as util

Expand All @@ -16,7 +15,7 @@
def apply_slippage(terrain, repose_slope, cell_width):
delta = util.simple_gradient(terrain) / cell_width
smoothed = util.gaussian_blur(terrain, sigma=1.5)
should_smooth = np.abs(delta) > repose_slope
# should_smooth = np.abs(delta) > repose_slope
result = np.select([np.abs(delta) > repose_slope], [smoothed], terrain)
return result

Expand Down Expand Up @@ -44,7 +43,8 @@ def erode(world):
min_height_delta = 0.05
repose_slope = 0.03
gravity = 30.0
gradient_sigma = 0.5
# Unused?
# gradient_sigma = 0.5

# Sediment constants
sediment_capacity_constant = 50.0
Expand Down
3 changes: 0 additions & 3 deletions generator/generators/heights.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import math
import numpy as np

from generator.generators.erosion import erode
import generator.utils.util as util

Expand Down
Loading

0 comments on commit e205d9e

Please sign in to comment.