Completed ability to choose a node as player.
This commit is contained in:
parent
35a65cfa1f
commit
30188a1a76
@ -38,15 +38,46 @@ export default class SelectTeamUI extends AbstractTopBarInterface {
|
|||||||
const teamDiv = this.getNodeFromTemplateId('conquer-team-to-select-template')
|
const teamDiv = this.getNodeFromTemplateId('conquer-team-to-select-template')
|
||||||
const nameParagraph = teamDiv.querySelector('p.conquer-name');
|
const nameParagraph = teamDiv.querySelector('p.conquer-name');
|
||||||
const descriptionParagraph = teamDiv.querySelector('p.conquer-description');
|
const descriptionParagraph = teamDiv.querySelector('p.conquer-description');
|
||||||
if (!(nameParagraph instanceof HTMLParagraphElement) || !(descriptionParagraph instanceof HTMLParagraphElement)) {
|
const submit = teamDiv.querySelector('button.conquer-submit');
|
||||||
|
if (!(nameParagraph instanceof HTMLParagraphElement)
|
||||||
|
|| !(descriptionParagraph instanceof HTMLParagraphElement)
|
||||||
|
|| !(submit instanceof HTMLButtonElement)) {
|
||||||
Conquer.fail('Select team name inclusive or description container are not correctly defined in template.');
|
Conquer.fail('Select team name inclusive or description container are not correctly defined in template.');
|
||||||
}
|
}
|
||||||
nameParagraph.innerText = team.getName();
|
nameParagraph.innerText = team.getName();
|
||||||
descriptionParagraph.innerText = team.getDescription();
|
descriptionParagraph.innerText = team.getDescription();
|
||||||
nameParagraph.style.color = team.getColor();
|
nameParagraph.style.color = team.getColor();
|
||||||
|
submit.addEventListener('click', async () => {
|
||||||
|
this.onSelectTeam(team);
|
||||||
|
});
|
||||||
this.getForm().append(teamDiv);
|
this.getForm().append(teamDiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async onSelectTeam(team: ConquerTeam) {
|
||||||
|
const urlTeam = new URL('/conquer/user/team',
|
||||||
|
window.location.protocol + '//'
|
||||||
|
+ window.location.hostname + ':'
|
||||||
|
+ window.location.port);
|
||||||
|
const response = await fetch(urlTeam, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
team: team.getUUID(),
|
||||||
|
node: this.node.getUUID(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
let responseBody;
|
||||||
|
try {
|
||||||
|
responseBody = await response.json();
|
||||||
|
if (response.status !== 200) {
|
||||||
|
console.error(responseBody.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.runCallbacks('close')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error parsing json', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private getForm(): HTMLElement {
|
private getForm(): HTMLElement {
|
||||||
if (this.form === null) {
|
if (this.form === null) {
|
||||||
const form = this.getNodeFromTemplateId('conquer-select-team-list-template')
|
const form = this.getNodeFromTemplateId('conquer-select-team-list-template')
|
||||||
|
@ -104,17 +104,16 @@ export default class SelfPlayerUI extends AbstractTopBarInterface {
|
|||||||
+ ' ve al nodo más cercano para unirte a un equipo.';
|
+ ' ve al nodo más cercano para unirte a un equipo.';
|
||||||
return this.userTeamData;
|
return this.userTeamData;
|
||||||
}
|
}
|
||||||
|
const spanText = document.createElement('span');
|
||||||
|
spanText.innerText = 'Equipo: ';
|
||||||
|
element.append(spanText);
|
||||||
const spanCircle = document.createElement('span');
|
const spanCircle = document.createElement('span');
|
||||||
spanCircle.classList.add('conquer-team-circle');
|
spanCircle.classList.add('conquer-team-circle');
|
||||||
spanCircle.style.backgroundColor = team.getColor();
|
spanCircle.style.backgroundColor = team.getColor();
|
||||||
element.append(spanCircle);
|
element.append(spanCircle);
|
||||||
const spanText = document.createElement('span');
|
|
||||||
spanText.innerText = 'Perteneces al equipo: ';
|
|
||||||
element.append(spanText);
|
|
||||||
const spanTeamName = document.createElement('span');
|
const spanTeamName = document.createElement('span');
|
||||||
spanTeamName.style.color = team.getColor();
|
spanTeamName.style.color = team.getColor();
|
||||||
spanTeamName.style.backgroundColor = 'white';
|
spanTeamName.innerText = ' ' + team.getName();
|
||||||
spanTeamName.innerText = team.getName();
|
|
||||||
element.append(spanTeamName);
|
element.append(spanTeamName);
|
||||||
return this.userTeamData;
|
return this.userTeamData;
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,10 @@ export default class MapNode {
|
|||||||
return 'node-' + this.uuid;
|
return 'node-' + this.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getUUID(): string {
|
||||||
|
return this.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public getFeature(): Feature {
|
public getFeature(): Feature {
|
||||||
if (this.feature === null) {
|
if (this.feature === null) {
|
||||||
this.feature = new Feature({
|
this.feature = new Feature({
|
||||||
|
@ -17,6 +17,10 @@ export default class ConquerTeam {
|
|||||||
@JsonProperty()
|
@JsonProperty()
|
||||||
private color: string;
|
private color: string;
|
||||||
|
|
||||||
|
public getUUID(): string {
|
||||||
|
return this.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public getName(): string {
|
public getName(): string {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,7 @@ sub startup ($self) {
|
|||||||
$r->get('/conquer')->to('Conquer#index');
|
$r->get('/conquer')->to('Conquer#index');
|
||||||
$r->put('/conquer/user')->to('UserConquer#create');
|
$r->put('/conquer/user')->to('UserConquer#create');
|
||||||
$r->get('/conquer/user/team')->to('UserConquer#getSelfTeam');
|
$r->get('/conquer/user/team')->to('UserConquer#getSelfTeam');
|
||||||
|
$r->post('/conquer/user/team')->to('UserConquer#setTeamForUser');
|
||||||
$r->post('/conquer/user/coordinates')->to('UserConquer#setCoordinates');
|
$r->post('/conquer/user/coordinates')->to('UserConquer#setCoordinates');
|
||||||
$r->get('/conquer/team/<uuid>')->to('ConquerTeam#get');
|
$r->get('/conquer/team/<uuid>')->to('ConquerTeam#get');
|
||||||
$r->put('/conquer/team')->to('ConquerTeam#put');
|
$r->put('/conquer/team')->to('ConquerTeam#put');
|
||||||
|
@ -21,6 +21,46 @@ my $username_maximum_chars = 15;
|
|||||||
my $password_minimum_chars = 8;
|
my $password_minimum_chars = 8;
|
||||||
my $password_maximum_chars = 4096;
|
my $password_maximum_chars = 4096;
|
||||||
|
|
||||||
|
sub setTeamForUser($self) {
|
||||||
|
my $user = $self->current_user;
|
||||||
|
if (!defined $user) {
|
||||||
|
return $self->_renderError(401, 'No estás loggeado.');
|
||||||
|
}
|
||||||
|
my $input = $self->_expectJson;
|
||||||
|
if (!defined $input) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
my $node_uuid = $input->{node};
|
||||||
|
my $team_uuid = $input->{team};
|
||||||
|
my $resultset_team = BurguillosInfo::Schema->Schema->resultset('ConquerTeam');
|
||||||
|
my $resultset_node = BurguillosInfo::Schema->Schema->resultset('ConquerNode');
|
||||||
|
my @teams = $resultset_team->search({uuid => $team_uuid});
|
||||||
|
my @nodes = $resultset_node->search({uuid => $node_uuid});
|
||||||
|
if (scalar @teams < 1) {
|
||||||
|
return $self->render(status => 404, json => {
|
||||||
|
error => 'No se encontró ese equipo.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (scalar @nodes < 1) {
|
||||||
|
return $self->render(status => 404, json => {
|
||||||
|
error => 'No se encontró este nodo.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
my $team = $teams[0];
|
||||||
|
my $node = $nodes[0];
|
||||||
|
if (!$node->is_near($user)) {
|
||||||
|
return $self->render(status => 400, json => {
|
||||||
|
error => 'Estás demasiado lejos del nodo.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$user = $user->get_from_storage;
|
||||||
|
$user->team_object($team);
|
||||||
|
$user->update;
|
||||||
|
return $self->render(json => {
|
||||||
|
ok => $JSON::true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
sub get_self ($self) {
|
sub get_self ($self) {
|
||||||
my $user = $self->current_user;
|
my $user = $self->current_user;
|
||||||
if ( !defined $user ) {
|
if ( !defined $user ) {
|
||||||
|
@ -83,6 +83,7 @@ sub serialize_to_owner ($self) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
__PACKAGE__->set_primary_key('uuid');
|
__PACKAGE__->set_primary_key('uuid');
|
||||||
|
__PACKAGE__->belongs_to('team_object', 'BurguillosInfo::Schema::Result::ConquerTeam', 'team');
|
||||||
__PACKAGE__->add_unique_constraint( "unique_constraint_username",
|
__PACKAGE__->add_unique_constraint( "unique_constraint_username",
|
||||||
['username'] );
|
['username'] );
|
||||||
1;
|
1;
|
||||||
|
@ -9,6 +9,11 @@ body {
|
|||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%; }
|
height: 100%; }
|
||||||
|
body span.conquer-team-circle {
|
||||||
|
display: inline-block;
|
||||||
|
aspect-ratio: 1 / 1;
|
||||||
|
height: 1rem;
|
||||||
|
border-radius: 50%; }
|
||||||
body div.conquer-team-to-select {
|
body div.conquer-team-to-select {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
@ -17,6 +17,12 @@ html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
span.conquer-team-circle {
|
||||||
|
display: inline-block;
|
||||||
|
aspect-ratio: 1 / 1;
|
||||||
|
height: 1rem;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
div.conquer-team-to-select {
|
div.conquer-team-to-select {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user