qudlaty / BloodAndBullets

2 stars 0 forks source link

Refactor map structure #139

Open sEver opened 9 months ago

sEver commented 9 months ago

We've iterated through multiple concepts, noting them down:

Currently we have this

squares: [{
  x:0, y:0, entity: {name: "Octopus", inventory: []}
}]

but we'd much rather have something like this:

map: {
  squares: [{x:0,y:0, type: 4}],
  entities: [{name: "Octopus", x: 1, y:1, inventory: []}]
}

so we can load map and entities separately.

This would be easy in JS:

import { STORAGE_ROOM } from './maps'
import { STORAGE_ROOM_RAT_INFESTATION } from './maps/lists-of-entities'
// ... 

const mission_01 = {
  map: STORAGE_ROOM,
  entities: STORAGE_ROOM_RAT_INFESTATION
  objectives: [SURVIVE, KILL_ALL_UNFRIENDLY_ENTITIES]
}

But to allow easy storage and edits, we'd rather have it in something like this JSON:

{
  mission_name: "Rat Infestation in the Storage Room 2"
  map: 'storage_room',
  entities: 'storage_room_rat_infestation',
  objectives: ['survive', 'kill_all_unfriendly_entities']
}

But then also we'd like to have certain map/entities combinations saved. We named this set a level:

{
  mission_id: 'storage_room_recon' 
  mission_name: "Check the Storage Room",
  level: 'storage_room_rat_infestation'
  objectives: ['survive', 'uncover_entire_map']
}

{
  mission_id: 'storage_room_clearing' 
  mission_name: "Clear out the Storage Room",
  level: 'storage_room_rat_infestation'
  objectives: ['survive', 'kill_all_unfriendly_entities']
}

{
  level_id: 'storage_room_rat_infestation', 
  map: 'storage_room',
  entities: 'storage_room_rat_infestation',
}

So this would require the following types:

type Mission = {
  mission_id: string,
  mission_name: string,
  level: string,
  objectives: string[]
}

type Level = {
  level_id: string,
  level_name: string,
  map: string,
  entities: string,
}

type Map = {
  map_id: string,
  map_name: string,
  squares: SquareJson[]
}

type EntitiesList = {
  entities_list_id: string,
  entities_list_name: string,
  entities: EntityJson[],
}