RoomSaver ja no reventa els yamals
This commit is contained in:
@@ -1,568 +1,58 @@
|
|||||||
enemies:
|
# VOID MAIN
|
||||||
-
|
|
||||||
animation: code.yaml
|
|
||||||
boundaries:
|
|
||||||
position1:
|
|
||||||
x: 3
|
|
||||||
y: 2
|
|
||||||
position2:
|
|
||||||
x: 20
|
|
||||||
y: 2
|
|
||||||
color: yellow
|
|
||||||
position:
|
|
||||||
x: 8
|
|
||||||
y: 2
|
|
||||||
velocity:
|
|
||||||
x: 24.0
|
|
||||||
y: 0
|
|
||||||
items:
|
|
||||||
-
|
|
||||||
counter: 1
|
|
||||||
position:
|
|
||||||
x: 21
|
|
||||||
y: 13
|
|
||||||
tile: 42
|
|
||||||
tileSetFile: items.gif
|
|
||||||
room:
|
room:
|
||||||
|
name_en: "VOID MAIN"
|
||||||
|
name_ca: "VOID MAIN"
|
||||||
bgColor: black
|
bgColor: black
|
||||||
border: magenta
|
border: magenta
|
||||||
|
tileSetFile: standard.gif
|
||||||
|
|
||||||
|
# Conexiones de la habitación (null = sin conexión)
|
||||||
connections:
|
connections:
|
||||||
|
up: null
|
||||||
down: null
|
down: null
|
||||||
left: 02.yaml
|
left: 02.yaml
|
||||||
right: null
|
right: null
|
||||||
up: null
|
|
||||||
conveyorBelt: left
|
# Colores de los objetos
|
||||||
itemColor1: bright_cyan
|
itemColor1: bright_cyan
|
||||||
itemColor2: yellow
|
itemColor2: yellow
|
||||||
name_ca: VOID MAIN
|
|
||||||
name_en: VOID MAIN
|
# Dirección de la cinta transportadora: left, none, right
|
||||||
tileSetFile: standard.gif
|
conveyorBelt: left
|
||||||
|
|
||||||
|
# Tilemap: 16 filas × 32 columnas (256×192 píxeles @ 8px/tile)
|
||||||
|
# Índices de tiles (-1 = vacío)
|
||||||
tilemap:
|
tilemap:
|
||||||
-
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- 24
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- 24
|
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [24, 24, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, -1, -1, 504, 24, 24, 24, 24, 24, 24, 24, 24]
|
||||||
- -1
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, 24, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, 24, 24, 24, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [24, 24, -1, -1, -1, -1, -1, -1, -1, 252, 252, 252, 252, 252, 252, 252, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24]
|
||||||
- -1
|
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 134, 24]
|
||||||
- -1
|
- [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 440, 440, 440, 440, -1, -1, -1, -1, -1, -1, -1, -1, 134, 24]
|
||||||
- -1
|
- [24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24]
|
||||||
- -1
|
|
||||||
- -1
|
# Enemigos en esta habitación
|
||||||
- -1
|
enemies:
|
||||||
- -1
|
- animation: code.yaml
|
||||||
- -1
|
position: {x: 3, y: 2}
|
||||||
- -1
|
velocity: {x: 24.0, y: 0}
|
||||||
- -1
|
boundaries:
|
||||||
- -1
|
position1: {x: 3, y: 2}
|
||||||
- -1
|
position2: {x: 27, y: 2}
|
||||||
- -1
|
color: yellow
|
||||||
- -1
|
|
||||||
- -1
|
# Objetos en esta habitación
|
||||||
- -1
|
items:
|
||||||
- -1
|
- tileSetFile: items.gif
|
||||||
- -1
|
tile: 42
|
||||||
- 24
|
position: {x: 21, y: 13}
|
||||||
- 24
|
counter: 1
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 504
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 504
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 504
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 504
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 504
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 504
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 504
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 504
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- 252
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 134
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 440
|
|
||||||
- 440
|
|
||||||
- 440
|
|
||||||
- 440
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- -1
|
|
||||||
- 134
|
|
||||||
- 24
|
|
||||||
-
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
- 24
|
|
||||||
|
|||||||
@@ -109,15 +109,13 @@ auto MapEditor::revert() -> std::string {
|
|||||||
if (!active_) { return "Editor not active"; }
|
if (!active_) { return "Editor not active"; }
|
||||||
if (file_path_.empty()) { return "Error: No file path"; }
|
if (file_path_.empty()) { return "Error: No file path"; }
|
||||||
|
|
||||||
// Restaurar el YAML al backup original
|
// Restaurar el YAML original y reescribir el fichero
|
||||||
yaml_ = yaml_backup_;
|
yaml_ = yaml_backup_;
|
||||||
RoomSaver::saveYAML(file_path_, yaml_);
|
|
||||||
|
|
||||||
// Recargar room_data_ desde el backup
|
|
||||||
auto room_data_ptr = Resource::Cache::get()->getRoom(room_path_);
|
auto room_data_ptr = Resource::Cache::get()->getRoom(room_path_);
|
||||||
if (room_data_ptr) {
|
if (room_data_ptr) {
|
||||||
room_data_ = *room_data_ptr;
|
room_data_ = *room_data_ptr;
|
||||||
}
|
}
|
||||||
|
RoomSaver::saveYAML(file_path_, yaml_, room_data_);
|
||||||
|
|
||||||
// Resetear los sprites vivos a las posiciones originales
|
// Resetear los sprites vivos a las posiciones originales
|
||||||
room_->resetEnemyPositions(room_data_.enemies);
|
room_->resetEnemyPositions(room_data_.enemies);
|
||||||
@@ -131,10 +129,19 @@ auto MapEditor::revert() -> std::string {
|
|||||||
return "Reverted to original";
|
return "Reverted to original";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-guarda los cambios puntuales al YAML tras soltar una entidad
|
// Auto-guarda al YAML tras soltar una entidad
|
||||||
void MapEditor::autosave() {
|
void MapEditor::autosave() {
|
||||||
if (file_path_.empty()) { return; }
|
if (file_path_.empty()) { return; }
|
||||||
RoomSaver::saveYAML(file_path_, yaml_);
|
|
||||||
|
// Sincronizar posiciones de items desde los sprites vivos a room_data_
|
||||||
|
auto* item_mgr = room_->getItemManager();
|
||||||
|
for (int i = 0; i < item_mgr->getCount() && i < static_cast<int>(room_data_.items.size()); ++i) {
|
||||||
|
SDL_FPoint pos = item_mgr->getItem(i)->getPos();
|
||||||
|
room_data_.items[i].x = pos.x;
|
||||||
|
room_data_.items[i].y = pos.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomSaver::saveYAML(file_path_, yaml_, room_data_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el editor
|
// Actualiza el editor
|
||||||
@@ -298,7 +305,6 @@ void MapEditor::handleMouseUp() {
|
|||||||
room_data_.enemies[IDX].x = drag_.snap_x;
|
room_data_.enemies[IDX].x = drag_.snap_x;
|
||||||
room_data_.enemies[IDX].y = drag_.snap_y;
|
room_data_.enemies[IDX].y = drag_.snap_y;
|
||||||
room_->getEnemyManager()->getEnemy(IDX)->resetToInitialPosition(room_data_.enemies[IDX]);
|
room_->getEnemyManager()->getEnemy(IDX)->resetToInitialPosition(room_data_.enemies[IDX]);
|
||||||
RoomSaver::updateEnemyPosition(yaml_, IDX, drag_.snap_x, drag_.snap_y);
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -307,7 +313,6 @@ void MapEditor::handleMouseUp() {
|
|||||||
if (IDX >= 0 && IDX < static_cast<int>(room_data_.enemies.size())) {
|
if (IDX >= 0 && IDX < static_cast<int>(room_data_.enemies.size())) {
|
||||||
room_data_.enemies[IDX].x1 = SNAP_X;
|
room_data_.enemies[IDX].x1 = SNAP_X;
|
||||||
room_data_.enemies[IDX].y1 = SNAP_Y;
|
room_data_.enemies[IDX].y1 = SNAP_Y;
|
||||||
RoomSaver::updateEnemyBound1(yaml_, IDX, SNAP_X, SNAP_Y);
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -316,7 +321,6 @@ void MapEditor::handleMouseUp() {
|
|||||||
if (IDX >= 0 && IDX < static_cast<int>(room_data_.enemies.size())) {
|
if (IDX >= 0 && IDX < static_cast<int>(room_data_.enemies.size())) {
|
||||||
room_data_.enemies[IDX].x2 = SNAP_X;
|
room_data_.enemies[IDX].x2 = SNAP_X;
|
||||||
room_data_.enemies[IDX].y2 = SNAP_Y;
|
room_data_.enemies[IDX].y2 = SNAP_Y;
|
||||||
RoomSaver::updateEnemyBound2(yaml_, IDX, SNAP_X, SNAP_Y);
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -324,7 +328,6 @@ void MapEditor::handleMouseUp() {
|
|||||||
case DragTarget::ITEM:
|
case DragTarget::ITEM:
|
||||||
if (IDX >= 0 && IDX < room_->getItemManager()->getCount()) {
|
if (IDX >= 0 && IDX < room_->getItemManager()->getCount()) {
|
||||||
room_->getItemManager()->getItem(IDX)->setPosition(drag_.snap_x, drag_.snap_y);
|
room_->getItemManager()->getItem(IDX)->setPosition(drag_.snap_x, drag_.snap_y);
|
||||||
RoomSaver::updateItemPosition(yaml_, IDX, drag_.snap_x, drag_.snap_y);
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <cmath> // Para std::round
|
#include <cmath> // Para std::round
|
||||||
#include <fstream> // Para ifstream, ofstream, istreambuf_iterator
|
#include <fstream> // Para ifstream, ofstream, istreambuf_iterator
|
||||||
#include <iostream> // Para cout, cerr
|
#include <iostream> // Para cout, cerr
|
||||||
|
#include <sstream> // Para ostringstream
|
||||||
|
|
||||||
#include "utils/defines.hpp" // Para Tile::SIZE
|
#include "utils/defines.hpp" // Para Tile::SIZE
|
||||||
|
|
||||||
@@ -21,9 +22,144 @@ auto RoomSaver::loadYAML(const std::string& file_path) -> fkyaml::node {
|
|||||||
return fkyaml::node::deserialize(content);
|
return fkyaml::node::deserialize(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guarda el nodo YAML completo a disco
|
// Convierte una room connection al formato YAML
|
||||||
auto RoomSaver::saveYAML(const std::string& file_path, const fkyaml::node& yaml) -> std::string {
|
auto RoomSaver::roomConnectionToYAML(const std::string& connection) -> std::string {
|
||||||
std::string content = fkyaml::node::serialize(yaml);
|
if (connection == "0" || connection.empty()) { return "null"; }
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convierte la dirección del conveyor belt a string
|
||||||
|
auto RoomSaver::conveyorBeltToString(int direction) -> std::string {
|
||||||
|
if (direction < 0) { return "left"; }
|
||||||
|
if (direction > 0) { return "right"; }
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Genera el YAML completo como texto con formato compacto
|
||||||
|
auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string {
|
||||||
|
std::ostringstream out;
|
||||||
|
|
||||||
|
// --- Cabecera: nombre como comentario ---
|
||||||
|
out << "# " << room_data.name << "\n";
|
||||||
|
|
||||||
|
// --- Sección room ---
|
||||||
|
out << "room:\n";
|
||||||
|
|
||||||
|
// Escribir todos los campos name_* del YAML original (preserva name_ca, name_en, etc.)
|
||||||
|
if (original_yaml.contains("room")) {
|
||||||
|
const auto& room_node = original_yaml["room"];
|
||||||
|
for (auto it = room_node.begin(); it != room_node.end(); ++it) {
|
||||||
|
const std::string key = it.key().get_value<std::string>();
|
||||||
|
if (key.substr(0, 5) == "name_") {
|
||||||
|
out << " " << key << ": \"" << it.value().get_value<std::string>() << "\"\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out << " bgColor: " << room_data.bg_color << "\n";
|
||||||
|
out << " border: " << room_data.border_color << "\n";
|
||||||
|
out << " tileSetFile: " << room_data.tile_set_file << "\n";
|
||||||
|
|
||||||
|
// Conexiones
|
||||||
|
out << "\n";
|
||||||
|
out << " # Conexiones de la habitación (null = sin conexión)\n";
|
||||||
|
out << " connections:\n";
|
||||||
|
out << " up: " << roomConnectionToYAML(room_data.upper_room) << "\n";
|
||||||
|
out << " down: " << roomConnectionToYAML(room_data.lower_room) << "\n";
|
||||||
|
out << " left: " << roomConnectionToYAML(room_data.left_room) << "\n";
|
||||||
|
out << " right: " << roomConnectionToYAML(room_data.right_room) << "\n";
|
||||||
|
|
||||||
|
// Colores de items
|
||||||
|
out << "\n";
|
||||||
|
out << " # Colores de los objetos\n";
|
||||||
|
out << " itemColor1: " << (room_data.item_color1.empty() ? "yellow" : room_data.item_color1) << "\n";
|
||||||
|
out << " itemColor2: " << (room_data.item_color2.empty() ? "magenta" : room_data.item_color2) << "\n";
|
||||||
|
|
||||||
|
// Conveyor belt
|
||||||
|
out << "\n";
|
||||||
|
out << " # Dirección de la cinta transportadora: left, none, right\n";
|
||||||
|
out << " conveyorBelt: " << conveyorBeltToString(room_data.conveyor_belt_direction) << "\n";
|
||||||
|
|
||||||
|
// --- Tilemap (16 filas × 32 columnas, formato flow) ---
|
||||||
|
out << "\n";
|
||||||
|
out << "# Tilemap: 16 filas × 32 columnas (256×192 píxeles @ 8px/tile)\n";
|
||||||
|
out << "# Índices de tiles (-1 = vacío)\n";
|
||||||
|
out << "tilemap:\n";
|
||||||
|
constexpr int MAP_WIDTH = 32;
|
||||||
|
constexpr int MAP_HEIGHT = 16;
|
||||||
|
for (int row = 0; row < MAP_HEIGHT; ++row) {
|
||||||
|
out << " - [";
|
||||||
|
for (int col = 0; col < MAP_WIDTH; ++col) {
|
||||||
|
int index = row * MAP_WIDTH + col;
|
||||||
|
if (index < static_cast<int>(room_data.tile_map.size())) {
|
||||||
|
out << room_data.tile_map[index];
|
||||||
|
} else {
|
||||||
|
out << -1;
|
||||||
|
}
|
||||||
|
if (col < MAP_WIDTH - 1) { out << ", "; }
|
||||||
|
}
|
||||||
|
out << "]\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Enemigos ---
|
||||||
|
if (!room_data.enemies.empty()) {
|
||||||
|
out << "\n";
|
||||||
|
out << "# Enemigos en esta habitación\n";
|
||||||
|
out << "enemies:\n";
|
||||||
|
for (const auto& enemy : room_data.enemies) {
|
||||||
|
out << " - animation: " << enemy.animation_path << "\n";
|
||||||
|
|
||||||
|
int pos_x = static_cast<int>(std::round(enemy.x / Tile::SIZE));
|
||||||
|
int pos_y = static_cast<int>(std::round(enemy.y / Tile::SIZE));
|
||||||
|
out << " position: {x: " << pos_x << ", y: " << pos_y << "}\n";
|
||||||
|
|
||||||
|
out << " velocity: {x: " << enemy.vx << ", y: " << enemy.vy << "}\n";
|
||||||
|
|
||||||
|
int b1_x = enemy.x1 / Tile::SIZE;
|
||||||
|
int b1_y = enemy.y1 / Tile::SIZE;
|
||||||
|
int b2_x = enemy.x2 / Tile::SIZE;
|
||||||
|
int b2_y = enemy.y2 / Tile::SIZE;
|
||||||
|
out << " boundaries:\n";
|
||||||
|
out << " position1: {x: " << b1_x << ", y: " << b1_y << "}\n";
|
||||||
|
out << " position2: {x: " << b2_x << ", y: " << b2_y << "}\n";
|
||||||
|
|
||||||
|
if (!enemy.color.empty() && enemy.color != "white") {
|
||||||
|
out << " color: " << enemy.color << "\n";
|
||||||
|
}
|
||||||
|
if (enemy.flip) { out << " flip: true\n"; }
|
||||||
|
if (enemy.mirror) { out << " mirror: true\n"; }
|
||||||
|
if (enemy.frame != -1) { out << " frame: " << enemy.frame << "\n"; }
|
||||||
|
|
||||||
|
out << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Items ---
|
||||||
|
if (!room_data.items.empty()) {
|
||||||
|
out << "# Objetos en esta habitación\n";
|
||||||
|
out << "items:\n";
|
||||||
|
for (const auto& item : room_data.items) {
|
||||||
|
out << " - tileSetFile: " << item.tile_set_file << "\n";
|
||||||
|
out << " tile: " << item.tile << "\n";
|
||||||
|
|
||||||
|
int item_x = static_cast<int>(std::round(item.x / Tile::SIZE));
|
||||||
|
int item_y = static_cast<int>(std::round(item.y / Tile::SIZE));
|
||||||
|
out << " position: {x: " << item_x << ", y: " << item_y << "}\n";
|
||||||
|
|
||||||
|
if (item.counter != 0) {
|
||||||
|
out << " counter: " << item.counter << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
out << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guarda el YAML a disco
|
||||||
|
auto RoomSaver::saveYAML(const std::string& file_path, const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string {
|
||||||
|
std::string content = buildYAML(original_yaml, room_data);
|
||||||
|
|
||||||
std::ofstream file(file_path);
|
std::ofstream file(file_path);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
@@ -39,80 +175,4 @@ auto RoomSaver::saveYAML(const std::string& file_path, const fkyaml::node& yaml)
|
|||||||
return "Saved " + FILE_NAME;
|
return "Saved " + FILE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición inicial de un enemigo (pixels → tiles)
|
|
||||||
void RoomSaver::updateEnemyPosition(fkyaml::node& yaml, int index, float x, float y) {
|
|
||||||
if (!yaml.contains("enemies")) { return; }
|
|
||||||
auto& enemies = yaml["enemies"];
|
|
||||||
if (index < 0 || index >= static_cast<int>(enemies.size())) { return; }
|
|
||||||
|
|
||||||
auto& enemy = enemies[index];
|
|
||||||
int tile_x = static_cast<int>(std::round(x / Tile::SIZE));
|
|
||||||
int tile_y = static_cast<int>(std::round(y / Tile::SIZE));
|
|
||||||
|
|
||||||
if (!enemy.contains("position")) {
|
|
||||||
enemy["position"] = fkyaml::node::mapping();
|
|
||||||
}
|
|
||||||
enemy["position"]["x"] = tile_x;
|
|
||||||
enemy["position"]["y"] = tile_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza boundary1 de un enemigo (pixels → tiles)
|
|
||||||
void RoomSaver::updateEnemyBound1(fkyaml::node& yaml, int index, int x, int y) {
|
|
||||||
if (!yaml.contains("enemies")) { return; }
|
|
||||||
auto& enemies = yaml["enemies"];
|
|
||||||
if (index < 0 || index >= static_cast<int>(enemies.size())) { return; }
|
|
||||||
|
|
||||||
auto& enemy = enemies[index];
|
|
||||||
int tile_x = x / Tile::SIZE;
|
|
||||||
int tile_y = y / Tile::SIZE;
|
|
||||||
|
|
||||||
if (!enemy.contains("boundaries")) {
|
|
||||||
enemy["boundaries"] = fkyaml::node::mapping();
|
|
||||||
}
|
|
||||||
auto& bounds = enemy["boundaries"];
|
|
||||||
if (!bounds.contains("position1")) {
|
|
||||||
bounds["position1"] = fkyaml::node::mapping();
|
|
||||||
}
|
|
||||||
bounds["position1"]["x"] = tile_x;
|
|
||||||
bounds["position1"]["y"] = tile_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza boundary2 de un enemigo (pixels → tiles)
|
|
||||||
void RoomSaver::updateEnemyBound2(fkyaml::node& yaml, int index, int x, int y) {
|
|
||||||
if (!yaml.contains("enemies")) { return; }
|
|
||||||
auto& enemies = yaml["enemies"];
|
|
||||||
if (index < 0 || index >= static_cast<int>(enemies.size())) { return; }
|
|
||||||
|
|
||||||
auto& enemy = enemies[index];
|
|
||||||
int tile_x = x / Tile::SIZE;
|
|
||||||
int tile_y = y / Tile::SIZE;
|
|
||||||
|
|
||||||
if (!enemy.contains("boundaries")) {
|
|
||||||
enemy["boundaries"] = fkyaml::node::mapping();
|
|
||||||
}
|
|
||||||
auto& bounds = enemy["boundaries"];
|
|
||||||
if (!bounds.contains("position2")) {
|
|
||||||
bounds["position2"] = fkyaml::node::mapping();
|
|
||||||
}
|
|
||||||
bounds["position2"]["x"] = tile_x;
|
|
||||||
bounds["position2"]["y"] = tile_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la posición de un item (pixels → tiles)
|
|
||||||
void RoomSaver::updateItemPosition(fkyaml::node& yaml, int index, float x, float y) {
|
|
||||||
if (!yaml.contains("items")) { return; }
|
|
||||||
auto& items = yaml["items"];
|
|
||||||
if (index < 0 || index >= static_cast<int>(items.size())) { return; }
|
|
||||||
|
|
||||||
auto& item = items[index];
|
|
||||||
int tile_x = static_cast<int>(std::round(x / Tile::SIZE));
|
|
||||||
int tile_y = static_cast<int>(std::round(y / Tile::SIZE));
|
|
||||||
|
|
||||||
if (!item.contains("position")) {
|
|
||||||
item["position"] = fkyaml::node::mapping();
|
|
||||||
}
|
|
||||||
item["position"]["x"] = tile_x;
|
|
||||||
item["position"]["y"] = tile_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // _DEBUG
|
#endif // _DEBUG
|
||||||
|
|||||||
@@ -5,32 +5,31 @@
|
|||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
|
|
||||||
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
||||||
#include "game/entities/enemy.hpp" // Para Enemy::Data
|
#include "game/gameplay/room.hpp" // Para Room::Data
|
||||||
#include "game/entities/item.hpp" // Para Item::Data
|
|
||||||
#include "game/entities/player.hpp" // Para Player::SpawnData
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Edición parcial de archivos YAML de habitaciones
|
* @brief Guardado de archivos YAML de habitaciones para el editor de mapas
|
||||||
*
|
*
|
||||||
* Lee el YAML original, modifica solo los campos editados y serializa.
|
* Lee el YAML original con fkyaml (para acceder a todos los campos: name_ca, name_en, etc.)
|
||||||
* Preserva todos los campos que no se editan (name_ca, comentarios del formato, etc.)
|
* Genera el YAML como texto formateado compacto (idéntico al formato original de los ficheros).
|
||||||
* Solo se usa en builds de debug (editor de mapas).
|
* Solo se usa en builds de debug.
|
||||||
*/
|
*/
|
||||||
class RoomSaver {
|
class RoomSaver {
|
||||||
public:
|
public:
|
||||||
RoomSaver() = delete;
|
RoomSaver() = delete;
|
||||||
|
|
||||||
// Carga el YAML original desde disco (llamar al entrar al editor)
|
// Carga el YAML original desde disco como nodo fkyaml (lee del filesystem, no del pack)
|
||||||
static auto loadYAML(const std::string& file_path) -> fkyaml::node;
|
static auto loadYAML(const std::string& file_path) -> fkyaml::node;
|
||||||
|
|
||||||
// Guarda el nodo YAML completo a disco
|
// Genera y guarda el YAML completo a disco
|
||||||
static auto saveYAML(const std::string& file_path, const fkyaml::node& yaml) -> std::string;
|
// original_yaml: nodo fkyaml con los datos originales (para campos que no se editan: name_ca, etc.)
|
||||||
|
// room_data: datos editados (posiciones de enemigos, items, etc.)
|
||||||
|
static auto saveYAML(const std::string& file_path, const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string;
|
||||||
|
|
||||||
// Modificaciones puntuales sobre el nodo YAML (posiciones en pixels, se convierten a tiles)
|
private:
|
||||||
static void updateEnemyPosition(fkyaml::node& yaml, int index, float x, float y);
|
static auto buildYAML(const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string;
|
||||||
static void updateEnemyBound1(fkyaml::node& yaml, int index, int x, int y);
|
static auto roomConnectionToYAML(const std::string& connection) -> std::string;
|
||||||
static void updateEnemyBound2(fkyaml::node& yaml, int index, int x, int y);
|
static auto conveyorBeltToString(int direction) -> std::string;
|
||||||
static void updateItemPosition(fkyaml::node& yaml, int index, float x, float y);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _DEBUG
|
#endif // _DEBUG
|
||||||
|
|||||||
Reference in New Issue
Block a user