Skip to content

Commit

Permalink
fix: adjust gen room_inputs to match new style
Browse files Browse the repository at this point in the history
Uglier but more flexible - could get into some nice constructors if a
code api for this is useful.
  • Loading branch information
russmatney committed Apr 3, 2024
1 parent 273e3ab commit c01379b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
21 changes: 12 additions & 9 deletions src/dino/modes/vania/RoomInputs.gd
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ static func merge_many(inputs):
return inputs.reduce(func(a, b): return a.merge(b))

static func apply_constraints(conses, def: VaniaRoomDef):
def.constraints = conses

var existing_shape = def.local_cells

if conses is RoomInputs:
def.constraints = [conses]

conses.update_def(def)
if existing_shape != null and not existing_shape.is_empty():
# maintain current local_cells
Expand All @@ -148,6 +148,7 @@ static func apply_constraints(conses, def: VaniaRoomDef):
Log.warn("Unhandled constraint collection passed to apply_constraints, aborting", conses)
return

def.constraints = conses
var ri = conses.map(func(cons):
# map constants to dicts with default opts
if cons is String:
Expand Down Expand Up @@ -308,13 +309,15 @@ static func has_entity(ent, opts={}):
var inp = RoomInputs.new({entities=U.repeat(ent, opts.get("count", 1))})
return inp

static func has_boss(_opts={}):
return RoomInputs.new({
entities=[
["Monstroar"],
["Beefstronaut"],
].pick_random(),
})
static func has_boss(opts={}):
if opts.get("count", 1):
return RoomInputs.new({
entities=[["Monstroar"], ["Beefstronaut"]].pick_random(),
})
else:
return RoomInputs.new({
entities=["Monstroar", "Beefstronaut"],
})

## encounters ######################################################33

Expand Down
5 changes: 2 additions & 3 deletions src/dino/modes/vania/VaniaEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,14 @@ func update_edit_constraints():

var items = []
items.append_array(current_room_def.constraints.map(func(cons):
return {label="Remove '%s'" % cons, on_select=func(): current_room_def.constraints.erase(cons)}))
return {label="Remove '%s'" % Log.to_printable([cons]), on_select=func(): current_room_def.constraints.erase(cons)}))
items.append_array(RoomInputs.all_constraints.map(func(cons):
return {label="Add '%s'" % cons, on_select=func(): current_room_def.constraints.append(cons)}))
return {label="Add '%s'" % Log.to_printable([cons]), on_select=func(): current_room_def.constraints.append(cons)}))

var popup = edit_constraints_menu_button.get_popup()
U.setup_popup_items(popup, items, func(item):
item.on_select.call()

# TODO when changing room shape, this updates local_cells, but not map_cells
current_room_def.reapply_constraints()

game.generator.build_and_prep_scene(current_room_def)
Expand Down
38 changes: 15 additions & 23 deletions src/dino/modes/vania/VaniaRoomDef.gd
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func get_neighbor_room_paths() -> Array[String]:
## constraints #####################################################3

func reapply_constraints():
# TODO prevent changing room shape via this func
RoomInputs.apply_constraints(constraints, self)

## static #####################################################3
Expand All @@ -183,18 +182,14 @@ static func generate_defs(opts={}):
RoomInputs.IN_SPACESHIP,
RoomInputs.IN_SMALL_ROOM,
], [
RoomInputs.HAS_LEAF,
RoomInputs.HAS_LEAF,
{RoomInputs.HAS_LEAF: {count=2}},
RoomInputs.IN_GRASSY_CAVE,
RoomInputs.IN_WIDE_ROOM,
], [
RoomInputs.HAS_TARGET,
RoomInputs.HAS_TARGET,
RoomInputs.IN_VOLCANO,
], [
RoomInputs.HAS_ENEMY,
RoomInputs.HAS_ENEMY,
RoomInputs.HAS_ENEMY,
], {
RoomInputs.HAS_TARGET: {count=3},
RoomInputs.IN_VOLCANO: {}
}, [
{RoomInputs.HAS_ENEMY: {count=3}},
RoomInputs.IN_LARGE_ROOM,
], [
RoomInputs.HAS_TARGET,
Expand All @@ -206,19 +201,16 @@ static func generate_defs(opts={}):
RoomInputs.IN_SPACESHIP,
],
RoomInputs.random_room(),
[
RoomInputs.HAS_ENEMY,
], [
{
RoomInputs.HAS_ENEMY: {count=3},
}, [
RoomInputs.IS_COOKING_ROOM,
], [
RoomInputs.HAS_TARGET,
RoomInputs.HAS_TARGET,
RoomInputs.HAS_ENEMY,
RoomInputs.HAS_ENEMY,
RoomInputs.IN_LARGE_ROOM,
], [
RoomInputs.HAS_BOSS,
RoomInputs.HAS_BOSS,
], {
RoomInputs.HAS_TARGET: {count=5},
RoomInputs.HAS_ENEMY: {count=2},
RoomInputs.IN_LARGE_ROOM: {},
}, [
{RoomInputs.HAS_BOSS: {count=2}},
RoomInputs.IN_LARGE_ROOM,
RoomInputs.IN_SPACESHIP,
]
Expand Down

0 comments on commit c01379b

Please sign in to comment.