Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Alejandro Martínez Muñoz
/
ProyectoRobotAmbientales
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
de0dd333
authored
Apr 29, 2024
by
Alex
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Agregado lógica de casilla seleccionable
parent
4b786a5e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
16 deletions
src/app/crear-pedido-dialog/crear-pedido-dialog.component.ts
src/app/mapa/mapa.component.ts
src/app/crear-pedido-dialog/crear-pedido-dialog.component.ts
View file @
de0dd333
...
...
@@ -67,11 +67,8 @@ constructor(private pedidoService: ServicioPedidoService) {}
*/
confirmarSeleccion
():
void
{
if
(
this
.
puntoDeRecogida
&&
this
.
puntoDeEntrega
)
{
// Genera un ID único para el pedido, por ejemplo usando la fecha y hora actual.
const
uniqueId
=
Date
.
now
().
toString
();
const
nuevoPedido
:
Pedido
=
{
id
:
uniqueId
,
id
:
''
,
puntoDeRecogida
:
this
.
puntoDeRecogida
,
puntoDeEntrega
:
this
.
puntoDeEntrega
};
...
...
src/app/mapa/mapa.component.ts
View file @
de0dd333
...
...
@@ -20,24 +20,42 @@ export class MapaComponent implements OnInit {
@
Output
()
celdaInvalidaClickeada
=
new
EventEmitter
<
void
>
();
mapMatrix
:
string
[][]
=
[];
mapStr
:
string
=
"0202000105030705000200041109060110031000000200080101100110000106010701"
;
// Cadena de texto que representa las casillas del mapa
celdaInvalida
:
string
[]
=
[
'00'
,
'07'
,
'08'
,
'09'
,
'10'
,
'11'
];
// Listado de bloques no seleccionables
rows
:
number
=
7
;
cols
:
number
=
5
;
SeleccionadoIdRecogida
:
string
|
null
=
null
;
SeleccionadoIdEntrega
:
string
|
null
=
null
;
// Listas de IDs que no constituyen una conexión válida según la dirección
sinConexionIzquierda
:
string
[]
=
[
'02'
,
'05'
,
'06'
,
'10'
,
'00'
];
sinConexionDerecha
:
string
[]
=
[
'02'
,
'03'
,
'04'
,
'08'
,
'00'
];
sinConexionArriba
:
string
[]
=
[
'01'
,
'03'
,
'06'
,
'07'
,
'00'
];
sinConexionAbajo
:
string
[]
=
[
'04'
,
'05'
,
'09'
,
'00'
];
constructor
(
private
MapaService
:
MapaService
)
{
}
/**
* @brief Determina si un bloque es seleccionable.
*
* Evalúa si el ID del bloque dado no está en la lista de bloques no seleccionables.
*
* @param celdaId El ID del bloque a evaluar.
* @return true si el bloque es seleccionable, false de lo contrario.
*/
siCeldaSeleccionable
(
celdaId
:
string
):
boolean
{
return
!
this
.
celdaInvalida
.
includes
(
celdaId
);
/**
* Evalúa si una casilla de calle es válida según su tipo y conexiones adyacentes.
* @param celdaId ID de la casilla (01 para horizontal, 02 para vertical).
* @param row Fila de la casilla en la matriz.
* @param col Columna de la casilla en la matriz.
* @return true si la casilla es válida; false de lo contrario.
*/
esCeldaValida
(
celdaId
:
string
,
row
:
number
,
col
:
number
):
boolean
{
if
(
celdaId
!==
'01'
&&
celdaId
!==
'02'
)
return
false
;
let
conexionesValidas
=
0
;
if
(
celdaId
===
'01'
)
{
if
(
col
>
0
&&
!
this
.
sinConexionIzquierda
.
includes
(
this
.
mapMatrix
[
row
][
col
-
1
]))
conexionesValidas
++
;
if
(
col
<
this
.
cols
-
1
&&
!
this
.
sinConexionDerecha
.
includes
(
this
.
mapMatrix
[
row
][
col
+
1
]))
conexionesValidas
++
;
}
else
if
(
celdaId
===
'02'
)
{
if
(
row
>
0
&&
!
this
.
sinConexionArriba
.
includes
(
this
.
mapMatrix
[
row
-
1
][
col
]))
conexionesValidas
++
;
if
(
row
<
this
.
rows
-
1
&&
!
this
.
sinConexionAbajo
.
includes
(
this
.
mapMatrix
[
row
+
1
][
col
]))
conexionesValidas
++
;
}
return
conexionesValidas
===
1
;
}
/**
...
...
@@ -74,7 +92,7 @@ export class MapaComponent implements OnInit {
* @param col La columna en la matriz del mapa donde está el bloque.
*/
enCeldaClickeada
(
celdaId
:
string
,
row
:
number
,
col
:
number
):
void
{
if
(
this
.
siCeldaSeleccionable
(
celdaId
))
{
if
(
this
.
esCeldaValida
(
celdaId
,
row
,
col
))
{
// Emitir también la fila y la columna
this
.
celdaSeleccionada
.
emit
({
id
:
celdaId
,
row
,
col
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment