Skip to content

Commit

Permalink
Adding admin pages, various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rwampler committed Jan 8, 2024
1 parent 9504d9c commit df513ae
Show file tree
Hide file tree
Showing 30 changed files with 1,366 additions and 95 deletions.
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

## v0.3.14 - in progress - updated 2023-12-30
## v0.3.14 - in progress - updated 2024-01-07
### platform
* [done] improve API integration with galaxies [v0.3.1]
* [done] document multiverse API integration [starpeace-server-multiverse-api]
Expand Down Expand Up @@ -34,7 +34,7 @@
* [done] fixed galaxy and research menu bugs [v0.3.13]
* [done] building inspect API [v0.3.13]
* [done] player and building event handling [v0.3.13]
* [in progress] admin API [v0.3.14]
* [done] admin API [v0.3.14]

### assets
* [done] finish initial language translation for assets [v0.3.1]
Expand Down
64 changes: 63 additions & 1 deletion assets/stylesheets/starpeace-bulma.sass
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ html
background: linear-gradient(to bottom, $sp-primary-bg, #000)
color: $sp-primary

&.sp-dark-background
background: $sp-dark-bg

&.sp-menu-background
//background: linear-gradient(to bottom, darken($sp-primary-bg, 2.5%), darken($sp-primary-bg, 25%)) !important
background: darken($sp-dark-bg, 12.5%)

a
Expand Down Expand Up @@ -221,3 +223,63 @@ html
&:active,
&.is-active
background-color: lighten($sp-dark-bg, 15%)

.menu
&.is-starpeace
p
color: $sp-light

&:not(:first-child)
margin-top: 1.5rem

a
&.is-active
background-color: $sp-light-bg

&:hover
background-color: $sp-light-bg
color: #fff !important


.tag
&.is-starpeace
&.is-primary
background-color: $sp-primary

.table
&.is-starpeace
background-color: transparent
border-color: $sp-dark-bg

tr
&:not(:last-child)
th,
td
border-bottom: 1px solid $sp-dark-bg

tr
&.nowrap
th
white-space: nowrap

th,
td
border-color: $sp-dark-bg
color: $sp-primary
vertical-align: middle

&.sp-striped
tr:nth-child(even)
td
background-color: darken($sp-dark-bg, 10%)

&.sp-solid-header
th
background-color: $sp-dark-bg
color: $sp-light
z-index: 500

&.sp-sticky-header
th
position: sticky
top: 0
4 changes: 4 additions & 0 deletions assets/stylesheets/starpeace-inspect.sass
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
th
background-color: $sp-dark-bg
color: $sp-light
z-index: 500

&.sp-sticky-header
th
Expand All @@ -72,6 +73,9 @@
position: relative
overflow: hidden

.loading-container
grid-row: start-tabs / end-details

.inspect-tabs
grid-column: 1 / 2
grid-row: start-tabs / end-tabs
Expand Down
197 changes: 197 additions & 0 deletions components/admin/buildings/buildings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<template lang='pug'>
.card.is-starpeace
.card-header
.card-header-title Town Buildings
.card-content.sp-menu-background.columns.is-marginless.is-paddingless
.column.is-paddingless
.columns.columns.is-marginless.is-paddingless
.column.is-narrow
aside.menu.is-starpeace.planet-selection
ul.menu-list
li(v-for='planet in planets')
a(:class="{'is-active': planetId == planet.id}" @click.stop.prevent='togglePlanet(planet.id)')
span {{ planet.name }}

aside.menu.is-starpeace.town-selection.mt-6
ul.menu-list
li(v-for='town in towns')
a(:class="{'is-active': townId == town.id}" @click.stop.prevent='toggleTown(town.id)')
span {{ town.name }}

.column
table.table.is-fullwidth.is-starpeace
thead
tr.nowrap
th ID
th Name
th Definition ID
th Tycoon ID
th Corporation ID
th Company ID
th.has-text-right X
th.has-text-right Y
th.has-text-right Level
th Upgrading
th.has-text-right Started At
th.has-text-right Finished At
th.has-text-right Condemned At
th.has-text-centered
tbody
template(v-if='!buildings.length')
tr
td.has-text-centered(colspan=4) None
template(v-else)
tr(v-for='building in buildings')
td {{ building.id }}
td {{ building.name }}
td {{ building.definitionId }}
td {{ building.tycoonId }}
td {{ building.corporationId }}
td {{ building.companyId }}
td.has-text-right {{ building.mapX }}
td.has-text-right {{ building.mapY }}
td.has-text-right {{ building.level }}
td {{ building.upgrading }}
td.has-text-right {{ building.constructionStartedAt?.toFormat('yyyy-MM-dd HH:mm') }}
td.has-text-right {{ building.constructionFinishedAt?.toFormat('yyyy-MM-dd HH:mm') }}
td.has-text-right {{ building.condemnedAt?.toFormat('yyyy-MM-dd HH:mm') }}
td.has-text-centered
button.button.is-starpeace(:disabled="building.corporationId == 'IFEL'" @click.stop.prevent='demolishBuilding(building.id)') Demolish

</template>

<script lang='ts'>
import _ from 'lodash';
import Building from '~/plugins/starpeace-client/building/building';
import Galaxy from '~/plugins/starpeace-client/galaxy/galaxy';
import Planet from '~/plugins/starpeace-client/planet/planet';
import Town from '~/plugins/starpeace-client/planet/town';
declare interface AdminBuildingsData {
planetId: string | undefined;
townId: string | undefined;
townById: Record<string, Town>;
buildingById: Record<string, Building>;
}
export default {
props: {
tycoonById: { type: Object, require: false },
galaxyMetadata: { type: Galaxy, require: false }
},
data (): AdminBuildingsData {
return {
planetId: undefined,
townId: undefined,
townById: {},
buildingById: {}
};
},
computed: {
planets (): Array<Planet> {
return _.orderBy(this.galaxyMetadata?.planets ?? [], ['name'], ['asc']);
},
towns (): Array<Town> {
return _.orderBy(Object.values(this.townById), ['name'], ['asc']);
},
buildings (): Array<Building> {
return _.orderBy(Object.values(this.buildingById), ['name', 'definitionId'], ['asc']);
}
},
watch: {
planets: {
immediate: true,
handler () {
this.planetId = this.planets.length > 0 ? this.planets[0].id : undefined;
this.townId = undefined;
}
},
planetId: {
immediate: true,
handler () {
this.refreshTowns();
}
},
townId: {
immediate: true,
handler () {
this.refreshBuildings();
}
}
},
methods: {
togglePlanet (planetId: string): void {
this.planetId = planetId;
},
toggleTown (townId: string): void {
this.townId = townId;
},
async refreshTowns (): Promise<void> {
try {
this.townById = {};
if (this.planetId) {
this.$starpeaceClient.client_state.player.planet_id = this.planetId;
this.townById = Object.fromEntries((await this.$starpeaceClient.api.towns_for_planet()).map(t => [t.id, t]));
if (this.towns.length > 0) {
this.townId = this.towns[0].id;
}
}
}
catch (err) {
console.error(err);
}
},
async refreshBuildings (): Promise<void> {
try {
this.buildingById = {};
if (this.townId) {
this.$starpeaceClient.client_state.player.planet_id = this.planetId;
this.buildingById = Object.fromEntries((await this.$starpeaceClient.api.buildings_for_town(this.townId)).map(b => [b.id, b]));
}
}
catch (err) {
console.error(err);
}
},
async demolishBuilding (buildingId: string): Promise<void> {
try {
if (!!buildingId && !!this.buildingById[buildingId] && this.buildingById[buildingId].corporationId !== 'IFEL') {
this.$starpeaceClient.client_state.player.planet_id = this.planetId;
await this.$starpeaceClient.api.demolish_building(buildingId);
delete this.buildingById[buildingId];
}
}
catch (err) {
console.error(err);
}
}
}
}
</script>

<style lang='sass' scoped>
@import '~/assets/stylesheets/starpeace'
@import '~/assets/stylesheets/starpeace-variables'
.button
letter-spacing: 0.1rem
text-transform: uppercase
.planet-selection
border: 1px solid $sp-light-bg
min-width: 10rem
</style>
Loading

0 comments on commit df513ae

Please sign in to comment.