1
Fork 0
mirror of https://github.com/Steffo99/lihzahrd.git synced 2024-11-21 23:54:23 +00:00

Use an enum for the difficulty

This commit is contained in:
Steffo 2020-06-04 22:33:49 +02:00
parent 51e8efd8fe
commit ac18c134dd
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
3 changed files with 34 additions and 28 deletions

View file

@ -4,6 +4,7 @@ from .anglerquestfish import AnglerQuestFish
from .backgrounds import Backgrounds from .backgrounds import Backgrounds
from .bossesdefeated import BossesDefeated from .bossesdefeated import BossesDefeated
from .clouds import Clouds from .clouds import Clouds
from .difficulty import Difficulty
from .events import Events from .events import Events
from .fourpartsplit import FourPartSplit from .fourpartsplit import FourPartSplit
from .generatorinfo import GeneratorInfo from .generatorinfo import GeneratorInfo
@ -36,6 +37,7 @@ __all__ = [
"Backgrounds", "Backgrounds",
"BossesDefeated", "BossesDefeated",
"Clouds", "Clouds",
"Difficulty",
"Events", "Events",
"FourPartSplit", "FourPartSplit",
"GeneratorInfo", "GeneratorInfo",
@ -61,5 +63,5 @@ __all__ = [
"Time", "Time",
"TreetopVariants", "TreetopVariants",
"Version", "Version",
"WorldEvilType" "WorldEvilType",
] ]

View file

@ -0,0 +1,11 @@
import enum
class Difficulty(enum.IntEnum):
JOURNEY = 3
CLASSIC = 0
EXPERT = 1
MASTER = 2
def __repr__(self):
return f"{self.__class__.__qualname__}.{self.NAME}"

View file

@ -29,7 +29,7 @@ class World:
id_: int, id_: int,
bounds: Rect, bounds: Rect,
size: Coordinates, size: Coordinates,
game_mode: int, difficulty: Difficulty,
drunk_world: bool, drunk_world: bool,
get_good_world: bool, get_good_world: bool,
created_on, created_on,
@ -107,11 +107,8 @@ class World:
self.size: Coordinates = size self.size: Coordinates = size
"""The world size in tiles.""" """The world size in tiles."""
self.game_mode: int = game_mode self.difficulty: Difficulty = difficulty
"""Which mode the game is in. 0=classic, 1=expert, 2=master, 3=journey""" """The `difficulty <https://terraria.gamepedia.com/Difficulty>`_ the game is in."""
self.is_expert: bool = True if self.game_mode==1 else False
"""If the world is in expert mode or not, no longer stored in worldfile."""
self.drunk_world: bool = drunk_world self.drunk_world: bool = drunk_world
"""Was this world created with the drunk worldgen seed.""" """Was this world created with the drunk worldgen seed."""
@ -319,6 +316,13 @@ class World:
tile = Tile(block=block, wall=wall, liquid=liquid, wiring=wiring) tile = Tile(block=block, wall=wall, liquid=liquid, wiring=wiring)
return [tile] * multiply_by return [tile] * multiply_by
@property
def is_expert(self):
"""If the world is in expert mode or not.
Provided for compatibility purposes."""
return self.difficulty == 1
@classmethod @classmethod
def _create_tilematrix(cls, f, world_size: Coordinates, tileframeimportant: typing.List[bool]): def _create_tilematrix(cls, f, world_size: Coordinates, tileframeimportant: typing.List[bool]):
"""Create a TileMatrix object from a file.""" """Create a TileMatrix object from a file."""
@ -372,7 +376,7 @@ class World:
id_ = f.int4() id_ = f.int4()
bounds = f.rect() bounds = f.rect()
world_size = Coordinates(y=f.int4(), x=f.int4()) world_size = Coordinates(y=f.int4(), x=f.int4())
game_mode = f.int4() difficulty = Difficulty(f.int4())
drunk_world = f.bool() drunk_world = f.bool()
get_good_world = f.bool() get_good_world = f.bool()
created_on = f.datetime() created_on = f.datetime()
@ -849,32 +853,21 @@ class World:
journey_powers = JourneyPowers() journey_powers = JourneyPowers()
power_id = f.int2() power_id = f.int2()
if power_id == 0: if power_id == 0:
freeze_time = f.bool() journey_powers.freeze_time = f.bool()
journey_powers.freeze_time = freeze_time
elif power_id == 5: elif power_id == 5:
god_mode = f.bool() journey_powers.god_mode = f.bool()
journey_powers.god_mode = god_mode
elif power_id == 8: elif power_id == 8:
time_rate = f.single() journey_powers.time_rate = f.single()
journey_powers.time_rate = time_rate
elif power_id == 9: elif power_id == 9:
freeze_rain = f.bool() journey_powers.freeze_rain = f.bool()
journey_powers.freeze_rain = freeze_rain
elif power_id == 10: elif power_id == 10:
freeze_wind = f.bool() journey_powers.freeze_wind = f.bool()
journey_powers.freeze_wind = freeze_wind
elif power_id == 11: elif power_id == 11:
far_placement_range = f.bool() journey_powers.far_placement_range = f.bool()
journey_powers.far_placement_range = far_placement_range
elif power_id == 12: elif power_id == 12:
difficulty = f.single() journey_powers.difficulty = f.single()
journey_powers.difficulty = difficulty
elif power_id == 13: elif power_id == 13:
freeze_biome_spread = f.bool() journey_powers.freeze_biome_spread = f.bool()
journey_powers.freeze_biome_spread = freeze_biome_spread
elif power_id == -1:
spawn_rate: f.single()
journey_powers.spawn_rate = spawn_rate
else: else:
print(f"Unknown id: {power_id}") print(f"Unknown id: {power_id}")
@ -883,7 +876,7 @@ class World:
# Object creation # Object creation
world = cls(version=version, savefile_type=savefile_type, revision=revision, is_favorite=is_favorite, world = cls(version=version, savefile_type=savefile_type, revision=revision, is_favorite=is_favorite,
name=name, generator=generator, uuid_=uuid_, id_=id_, bounds=bounds, size=world_size, name=name, generator=generator, uuid_=uuid_, id_=id_, bounds=bounds, size=world_size,
game_mode=game_mode, drunk_world=drunk_world, get_good_world=get_good_world, difficulty=difficulty, drunk_world=drunk_world, get_good_world=get_good_world,
created_on=created_on, styles=world_styles, backgrounds=backgrounds, created_on=created_on, styles=world_styles, backgrounds=backgrounds,
spawn_point=spawn_point, underground_level=underground_level, cavern_level=cavern_level, spawn_point=spawn_point, underground_level=underground_level, cavern_level=cavern_level,
time=time, events=events, dungeon_point=dungeon_point, world_evil=world_evil, time=time, events=events, dungeon_point=dungeon_point, world_evil=world_evil,