Checkpoint initial implementation
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
# Class ############################################################################################
|
||||
|
||||
class Active:
|
||||
"""
|
||||
The time of day when a creature is normally most active.
|
||||
"""
|
||||
|
||||
def __init__(self, name: str, start:int, end:int):
|
||||
self.name = name
|
||||
self.start = start
|
||||
self.end = end
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Active<{self.name}>{{start:{self.start}, end:{self.end}}}"
|
||||
|
||||
|
||||
# Constants ########################################################################################
|
||||
|
||||
DAY = Active("day", 0, 12000)
|
||||
NIGHT = Active("night", 13000, 23000)
|
||||
SUNRISE = Active("sunrise", 23000, 24000)
|
||||
SUNSET = Active("sunset", 12000, 13000)
|
||||
|
||||
ANY = (SUNRISE, DAY, SUNSET, NIGHT)
|
||||
DIURNAL = (DAY)
|
||||
NOCTURNAL = (NIGHT)
|
||||
CREPUSCULAR = (SUNRISE, SUNSET)
|
||||
@@ -0,0 +1,9 @@
|
||||
from pytest import fixture
|
||||
|
||||
import tungston.core.fauna.active as active
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
@@ -0,0 +1,50 @@
|
||||
# Class ############################################################################################
|
||||
|
||||
class Group:
|
||||
"""
|
||||
How many individuals are commonly present when encountering a creature.
|
||||
"""
|
||||
|
||||
def __init__(self, name, smallest, largest):
|
||||
self.name = name
|
||||
self.smallest = smallest
|
||||
self.largest = largest
|
||||
|
||||
def __eq__(self, other) -> bool:
|
||||
if type(other) != type(self): return False
|
||||
if other.largest != self.largest: return False
|
||||
if other.smallest != self.smallest: return False
|
||||
return True
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash((self.smallest, self.largest))
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return str(self) + f"<{self.smallest} to {self.largest}>"
|
||||
|
||||
|
||||
# Constants ########################################################################################
|
||||
|
||||
SOLO = Group("solo", 1, 1)
|
||||
PAIR = Group("pair", 2, 2)
|
||||
FAMILY = Group("family", 2, 4)
|
||||
TROUP = Group("troup", 3, 6)
|
||||
HERD = Group("herd", 4, 8)
|
||||
|
||||
ALL = [SOLO, PAIR, FAMILY, TROUP, HERD]
|
||||
|
||||
|
||||
# Helper Functions #################################################################################
|
||||
|
||||
def merge(*groups):
|
||||
if not groups: return SOLO
|
||||
|
||||
result = Group(f"", HERD.largest, SOLO.smallest)
|
||||
for group in groups:
|
||||
result.smallest = min(result.smallest, group.smallest)
|
||||
result.largest = max(result.largest, group.largest)
|
||||
|
||||
return result
|
||||
@@ -0,0 +1,17 @@
|
||||
from pytest import fixture
|
||||
|
||||
import tungston.core.fauna.group as group
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="atomicFamily")
|
||||
def createAtomicFamily():
|
||||
yield group.merge(group.PAIR, group.FAMILY)
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_merge(atomicFamily):
|
||||
assert atomicFamily.smallest == 2
|
||||
assert atomicFamily.largest == 4
|
||||
@@ -0,0 +1,27 @@
|
||||
from tungston.core.ecology.biometrait import BiomeTrait
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class Location:
|
||||
"""
|
||||
Where a creature is most likely to be encountered.
|
||||
"""
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Location<{self.name}>"
|
||||
|
||||
|
||||
# Constants ########################################################################################
|
||||
|
||||
OUTSIDE = Location("outside")
|
||||
CAVE = Location("cave")
|
||||
WATER = Location("water")
|
||||
|
||||
ALL = [OUTSIDE, CAVE, WATER]
|
||||
@@ -0,0 +1,36 @@
|
||||
from tungston.core.fauna.active import Active
|
||||
|
||||
import tungston.core.fauna.active as AC
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class Mob:
|
||||
"""
|
||||
A creature which may appear in the game world.
|
||||
"""
|
||||
|
||||
def __init__(self, name:str, gameId:str, active:tuple[Active]=AC.DIURNAL):
|
||||
self.name = name
|
||||
self.gameId = gameId
|
||||
self.active = active
|
||||
|
||||
if not self.active:
|
||||
self.active = AC.DIURNAL
|
||||
|
||||
if isinstance(self.active, Active):
|
||||
self.active = (self.active,)
|
||||
|
||||
def __eq__(self, other) -> bool:
|
||||
if type(self) != type(other): return False
|
||||
if self.gameId != other.gameId: return False
|
||||
return True
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(self.gameId)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.name}<{self.gameId}>{{active:{self.active}}}"
|
||||
@@ -0,0 +1,39 @@
|
||||
from tungston.core.fauna.mob import Mob
|
||||
from pytest import fixture
|
||||
|
||||
import tungston.core.fauna.active as AC
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="squid")
|
||||
def createSquid():
|
||||
yield Mob("squid", "minecraft:squid", AC.ANY)
|
||||
|
||||
@fixture(name="cow")
|
||||
def createCow():
|
||||
yield Mob("cow", "minecraft:cow", AC.DIURNAL)
|
||||
|
||||
@fixture(name="mobMap")
|
||||
def createMobMap(cow, squid):
|
||||
yield {
|
||||
cow: "beef",
|
||||
squid: "calamari"
|
||||
}
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_eq(squid):
|
||||
assert squid == Mob("squid", "minecraft:squid")
|
||||
assert squid != Mob("squid", "animalsplus:squid")
|
||||
|
||||
def test_hash(cow, squid, mobMap):
|
||||
assert mobMap[cow] == "beef"
|
||||
assert mobMap[squid] == "calamari"
|
||||
|
||||
def test_str(squid):
|
||||
assert str(squid) == "squid"
|
||||
|
||||
def test_repr(cow):
|
||||
assert repr(cow) == "cow<minecraft:cow>{active:(Active<day>{start:0, end:12000},)}"
|
||||
@@ -0,0 +1,16 @@
|
||||
from tungston.core.fauna.mob import Mob
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class MobCatalog:
|
||||
|
||||
def __init__(self, mobs):
|
||||
self.mobs = mobs
|
||||
|
||||
def findByName(self, name):
|
||||
for mob in self.mobs:
|
||||
if mob.name == name:
|
||||
return mob
|
||||
|
||||
return None
|
||||
@@ -0,0 +1,15 @@
|
||||
from tungston.core.habitat import Habitat
|
||||
from tungston.core.fauna.mob import Mob
|
||||
from tungston.core.placement import Placement
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class MobPlacement(Placement):
|
||||
"""
|
||||
A description of where a creature should appear in the world.
|
||||
"""
|
||||
|
||||
def __init__(self, mob:Mob, habitats:list[Habitat]=None):
|
||||
super().__init__(habitats)
|
||||
self.mob = mob
|
||||
@@ -0,0 +1,43 @@
|
||||
from pytest import fixture
|
||||
from tungston.core.ecology.biomefilter import BiomeFilter
|
||||
from tungston.core.fauna.mob import Mob
|
||||
from tungston.core.fauna.mobplacement import MobPlacement
|
||||
from tungston.core.habitat import Habitat
|
||||
|
||||
import tungston.core.ecology.flora as F
|
||||
import tungston.core.ecology.heat as E
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="cow")
|
||||
def createCow():
|
||||
yield Mob("cow", "minecraft:cow")
|
||||
|
||||
@fixture(name="fields")
|
||||
def createFieldsHabitat():
|
||||
yield Habitat(biomeFilter=BiomeFilter([F.FIELD, E.TEMPERATE]))
|
||||
|
||||
@fixture(name="placement")
|
||||
def createMobPlacement(cow, fields):
|
||||
yield MobPlacement(cow, fields)
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_cowsInFields(placement):
|
||||
assert str(placement) == (
|
||||
"Placement{" +
|
||||
"habitats: [" +
|
||||
"Habitat{" +
|
||||
"altitude: [anywhere <-64 to 320>], " +
|
||||
"biomeFilter: BiomeFilter([[Flora<field>, Heat<temperate>]], [[]]), " +
|
||||
"seasons: [Season<spring>, Season<summer>, Season<autumn>, Season<winter>], " +
|
||||
"group: solo<1 to 1>, " +
|
||||
"location: Location<outside>, " +
|
||||
"scarcity: Scarcity<sparse>" +
|
||||
"}" +
|
||||
"]" +
|
||||
"}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user