Convert ui functions to UI class.
This commit is contained in:
parent
fd4f072bde
commit
e97f527937
4 changed files with 109 additions and 106 deletions
|
@ -6,7 +6,7 @@ import { System } from '../models/System'
|
||||||
const EventEmitter = require('events')
|
const EventEmitter = require('events')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
import { globSync } from 'glob'
|
const { globSync } = require('glob')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const lineReader = require('reverse-line-reader')
|
const lineReader = require('reverse-line-reader')
|
||||||
const chokidar = require('chokidar')
|
const chokidar = require('chokidar')
|
||||||
|
@ -57,8 +57,7 @@ export class JournalInterface extends EventEmitter {
|
||||||
const journals = globSync(this.journalPattern)
|
const journals = globSync(this.journalPattern)
|
||||||
|
|
||||||
return maxBy(journals, file => {
|
return maxBy(journals, file => {
|
||||||
const fullPath = path.join(this.journalDir, file)
|
return fs.statSync(file).mtime
|
||||||
return fs.statSync(fullPath).mtime
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +81,7 @@ export class JournalInterface extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (this.location) {
|
if (this.location.name !== 'Unknown') {
|
||||||
log('Attempting to find scanned bodies in current system.')
|
log('Attempting to find scanned bodies in current system.')
|
||||||
this.getScannedBodies()
|
this.getScannedBodies()
|
||||||
}
|
}
|
||||||
|
|
102
src/models/UI.js
Normal file
102
src/models/UI.js
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
export class UI {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- buildRings ---- */
|
||||||
|
|
||||||
|
static buildRings(body) {
|
||||||
|
const rings = $('<span>')
|
||||||
|
const seperator = $('<span>').text(' ) ')
|
||||||
|
rings.appendChild(seperator)
|
||||||
|
|
||||||
|
body.Rings.forEach((ring) => {
|
||||||
|
const ringClass = ring.RingClass.replace('eRingClass_', '')
|
||||||
|
let icon = null
|
||||||
|
|
||||||
|
switch (ringClass) {
|
||||||
|
case 'MetalRich': {
|
||||||
|
icon = 'gold-bars'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'Metalic':
|
||||||
|
case 'Metallic': {
|
||||||
|
icon = 'ingot'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'Icy': {
|
||||||
|
icon = 'snowflake'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'Rocky': {
|
||||||
|
icon = 'asteroid-3'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (icon !== null) {
|
||||||
|
rings.appendChild($('<i>').addClass(`flaticon-${icon}`))
|
||||||
|
rings.appendChild(seperator)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return rings
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------- createBodyRow ---- */
|
||||||
|
|
||||||
|
static createBodyRow(body) {
|
||||||
|
const chartedStyle = body.WasDiscovered && !body.DSSDone ? 'charted' : 'uncharted'
|
||||||
|
const row = $('<div>').addClass('row ms-1 me-1')
|
||||||
|
row.attr('id', body.bodyID)
|
||||||
|
|
||||||
|
// spacer
|
||||||
|
row.appendChild($('<div>').addClass('col-1 system'))
|
||||||
|
|
||||||
|
// name
|
||||||
|
const name = $('<div>').addClass(`col-2 text-left system ${chartedStyle}`)
|
||||||
|
name.appendChild($('<i>')).addClass(`flaticon-${body.nameIcon()}`)
|
||||||
|
name.appendChild($('<span>')).text(body.simpleName())
|
||||||
|
row.appendChild(name)
|
||||||
|
|
||||||
|
// type icon
|
||||||
|
const type = $('<div>').addClass(`col pe-0 me-0 system ${chartedStyle}`)
|
||||||
|
type.appendChild($('<i>').addClass(`flaticon-${body.typeIcon()}`))
|
||||||
|
// rings
|
||||||
|
if (body.Rings !== undefined) {
|
||||||
|
type.appendChild(buildRings(body))
|
||||||
|
}
|
||||||
|
// type
|
||||||
|
const typeName = body.PlanetClass || body.starType || ''
|
||||||
|
type.appendChild($('<span>').text(typeName))
|
||||||
|
row.appendChild(type)
|
||||||
|
|
||||||
|
// distance
|
||||||
|
const distance = $('<div>').addClass(`col-auto ps-2 ms-0 system ${chartedStyle}`)
|
||||||
|
distance.text(body.distance())
|
||||||
|
row.appendChild(distance)
|
||||||
|
|
||||||
|
// info
|
||||||
|
const info = $('<div>').addClass(`col-1 system ${chartedStyle}`)
|
||||||
|
// terraformable
|
||||||
|
const terraform = $('<i>').addClass('flaticon-cooling-tower opacity-0')
|
||||||
|
if (body.isPlanet && body.TerraformState) {
|
||||||
|
terraform.removeClass('opacity-0')
|
||||||
|
}
|
||||||
|
info.appendChild(terraform)
|
||||||
|
// was mapped
|
||||||
|
const mapped = $('<i>').addClass('flaticon-flag-outline-on-a-pole-with-stars-around opacity-0')
|
||||||
|
if (body.isPlanet() && !body.WasMapped) {
|
||||||
|
mapped.removeClass('opacity-0')
|
||||||
|
}
|
||||||
|
info.appendChild(mapped)
|
||||||
|
row.appendChild(info)
|
||||||
|
|
||||||
|
// mapped value
|
||||||
|
const value = $('<div>').addClass(`col-2 text-right system ${chartedStyle}`)
|
||||||
|
row.appendChild(value)
|
||||||
|
|
||||||
|
return row
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,7 @@ import './icons/flaticon.css'
|
||||||
|
|
||||||
const { app } = require('electron')
|
const { app } = require('electron')
|
||||||
import { JournalInterface } from './interfaces/JournalInterface'
|
import { JournalInterface } from './interfaces/JournalInterface'
|
||||||
import { createBodyRow } from './ui'
|
import { UI } from './models/UI'
|
||||||
import { Body } from './models/Body'
|
import { Body } from './models/Body'
|
||||||
|
|
||||||
// Grab app.isPackaged from main process
|
// Grab app.isPackaged from main process
|
||||||
|
@ -71,7 +71,7 @@ journal.once('INIT_COMPLETE', () => {
|
||||||
|
|
||||||
if (journal.location?.bodies?.length > 0) {
|
if (journal.location?.bodies?.length > 0) {
|
||||||
journal.location.bodies.forEach((body) => {
|
journal.location.bodies.forEach((body) => {
|
||||||
const row = createBodyRow(body)
|
const row = UI.createBodyRow(body)
|
||||||
// TODO APPRAISAL DATA
|
// TODO APPRAISAL DATA
|
||||||
$('#lowValueScans').appendChild(row)
|
$('#lowValueScans').appendChild(row)
|
||||||
})
|
})
|
||||||
|
@ -98,13 +98,13 @@ journal.on('BODY_SCANNED', (body, DSS) => {
|
||||||
if (bodyRow.length > 0) { // check just in case body was missed in earlier scans
|
if (bodyRow.length > 0) { // check just in case body was missed in earlier scans
|
||||||
bodyRow.removeClass('highlighted uncharted').addClass('charted')
|
bodyRow.removeClass('highlighted uncharted').addClass('charted')
|
||||||
} else {
|
} else {
|
||||||
const row = createBodyRow(body)
|
const row = UI.createBodyRow(body)
|
||||||
// TODO APPRAISAL DATA
|
// TODO APPRAISAL DATA
|
||||||
$('#lowValueScans').appendChild(row)
|
$('#lowValueScans').appendChild(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // else it's an FSS/auto scan and won't be in the list yet
|
} else { // else it's an FSS/auto scan and won't be in the list yet
|
||||||
const row = createBodyRow(body)
|
const row = UI.createBodyRow(body)
|
||||||
// TODO APPRAISAL DATA
|
// TODO APPRAISAL DATA
|
||||||
$('#lowValueScans').appendChild(row)
|
$('#lowValueScans').appendChild(row)
|
||||||
}
|
}
|
||||||
|
|
98
src/ui.js
98
src/ui.js
|
@ -1,98 +0,0 @@
|
||||||
/* ------------------------------------------------------------------------------ buildRings ---- */
|
|
||||||
|
|
||||||
const buildRings = (body) => {
|
|
||||||
const rings = $('<span>')
|
|
||||||
const seperator = $('<span>').text(' ) ')
|
|
||||||
rings.appendChild(seperator)
|
|
||||||
|
|
||||||
body.Rings.forEach((ring) => {
|
|
||||||
const ringClass = ring.RingClass.replace('eRingClass_', '')
|
|
||||||
let icon = null
|
|
||||||
|
|
||||||
switch (ringClass) {
|
|
||||||
case 'MetalRich': {
|
|
||||||
icon = 'gold-bars'
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'Metalic':
|
|
||||||
case 'Metallic': {
|
|
||||||
icon = 'ingot'
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'Icy': {
|
|
||||||
icon = 'snowflake'
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'Rocky': {
|
|
||||||
icon = 'asteroid-3'
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (icon !== null) {
|
|
||||||
rings.appendChild($('<i>').addClass(`flaticon-${icon}`))
|
|
||||||
rings.appendChild(seperator)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return rings
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- createBodyRow ---- */
|
|
||||||
|
|
||||||
export const createBodyRow = (body) => {
|
|
||||||
const chartedStyle = body.WasDiscovered && !body.DSSDone ? 'charted' : 'uncharted'
|
|
||||||
const row = $('<div>').addClass('row ms-1 me-1')
|
|
||||||
row.attr('id', body.bodyID)
|
|
||||||
|
|
||||||
// spacer
|
|
||||||
row.appendChild($('<div>').addClass('col-1 system'))
|
|
||||||
|
|
||||||
// name
|
|
||||||
const name = $('<div>').addClass(`col-2 text-left system ${chartedStyle}`)
|
|
||||||
name.appendChild($('<i>')).addClass(`flaticon-${body.nameIcon()}`)
|
|
||||||
name.appendChild($('<span>')).text(body.simpleName())
|
|
||||||
row.appendChild(name)
|
|
||||||
|
|
||||||
// type icon
|
|
||||||
const type = $('<div>').addClass(`col pe-0 me-0 system ${chartedStyle}`)
|
|
||||||
type.appendChild($('<i>').addClass(`flaticon-${body.typeIcon()}`))
|
|
||||||
// rings
|
|
||||||
if (body.Rings !== undefined) {
|
|
||||||
type.appendChild(buildRings(body))
|
|
||||||
}
|
|
||||||
// type
|
|
||||||
const typeName = body.PlanetClass || body.starType || ''
|
|
||||||
type.appendChild($('<span>').text(typeName))
|
|
||||||
row.appendChild(type)
|
|
||||||
|
|
||||||
// distance
|
|
||||||
const distance = $('<div>').addClass(`col-auto ps-2 ms-0 system ${chartedStyle}`)
|
|
||||||
distance.text(body.distance())
|
|
||||||
row.appendChild(distance)
|
|
||||||
|
|
||||||
// info
|
|
||||||
const info = $('<div>').addClass(`col-1 system ${chartedStyle}`)
|
|
||||||
// terraformable
|
|
||||||
const terraform = $('<i>').addClass('flaticon-cooling-tower opacity-0')
|
|
||||||
if (body.isPlanet && body.TerraformState) {
|
|
||||||
terraform.removeClass('opacity-0')
|
|
||||||
}
|
|
||||||
info.appendChild(terraform)
|
|
||||||
// was mapped
|
|
||||||
const mapped = $('<i>').addClass('flaticon-flag-outline-on-a-pole-with-stars-around opacity-0')
|
|
||||||
if (body.isPlanet() && !body.WasMapped) {
|
|
||||||
mapped.removeClass('opacity-0')
|
|
||||||
}
|
|
||||||
info.appendChild(mapped)
|
|
||||||
row.appendChild(info)
|
|
||||||
|
|
||||||
// mapped value
|
|
||||||
const value = $('<div>').addClass(`col-2 text-right system ${chartedStyle}`)
|
|
||||||
row.appendChild(value)
|
|
||||||
|
|
||||||
return row
|
|
||||||
}
|
|
Loading…
Reference in a new issue