mirror of
https://github.com/teoxoy/factorio-blueprint-editor.git
synced 2025-03-27 21:39:03 +02:00
Added editor for Train Stop (#232)
* Added editor for Train Stop with inputs for station name and train limit #231 * add history support to train stop editor Co-authored-by: Tad Smith <tad.smith@americo.com> Co-authored-by: teoxoy <28601907+teoxoy@users.noreply.github.com>
This commit is contained in:
parent
8c58aa765c
commit
e1fd94b9ce
61
packages/editor/src/UI/editors/TrainStopEditor.ts
Normal file
61
packages/editor/src/UI/editors/TrainStopEditor.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import { Entity } from '../../core/Entity'
|
||||
import { Checkbox } from '../controls/Checkbox'
|
||||
import { Textbox } from '../controls/Textbox'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
/** Train Stop Editor */
|
||||
export class TrainStopEditor extends Editor {
|
||||
public constructor(entity: Entity) {
|
||||
super(402, 171, entity)
|
||||
|
||||
this.addLabel(140, 46, 'Station Name:')
|
||||
// The length is arbitrary, but the Textbox doesn't work right without it
|
||||
const stationTextBox: Textbox = new Textbox(250, entity.station, 100)
|
||||
stationTextBox.position.set(140, 65)
|
||||
this.addChild(stationTextBox)
|
||||
|
||||
const isLimitDefined: boolean = this.m_Entity.manualTrainsLimit !== undefined
|
||||
const limitCheckBox: Checkbox = new Checkbox(isLimitDefined, 'Enable train limit')
|
||||
limitCheckBox.position.set(140, 97)
|
||||
this.addChild(limitCheckBox)
|
||||
|
||||
const trainsLimitString: string = this.m_Entity.manualTrainsLimit?.toString()
|
||||
const limitTextbox: Textbox = new Textbox(30, trainsLimitString, 3, '0123456789')
|
||||
limitTextbox.position.set(275, 95)
|
||||
this.addChild(limitTextbox)
|
||||
|
||||
stationTextBox.on('changed', () => {
|
||||
this.m_Entity.station = stationTextBox.text
|
||||
})
|
||||
|
||||
limitCheckBox.on('changed', () => {
|
||||
if (limitCheckBox.checked) {
|
||||
this.m_Entity.manualTrainsLimit = 0
|
||||
limitTextbox.text = '0'
|
||||
} else {
|
||||
this.m_Entity.manualTrainsLimit = undefined
|
||||
limitTextbox.text = ''
|
||||
}
|
||||
})
|
||||
|
||||
limitTextbox.on('changed', () => {
|
||||
let limit: number = parseInt(limitTextbox.text)
|
||||
if (isNaN(limit)) {
|
||||
limit = undefined
|
||||
}
|
||||
|
||||
this.m_Entity.manualTrainsLimit = limit
|
||||
limitCheckBox.checked = limit !== undefined && limit >= 0
|
||||
})
|
||||
|
||||
this.onEntityChange('station', () => {
|
||||
stationTextBox.text = this.m_Entity.station
|
||||
})
|
||||
|
||||
this.onEntityChange('manualTrainsLimit', () => {
|
||||
const limit = this.m_Entity.manualTrainsLimit
|
||||
limitTextbox.text = limit === undefined ? '' : `${limit}`
|
||||
limitCheckBox.checked = limit !== undefined && limit >= 0
|
||||
})
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import { MiningEditor } from './MiningEditor'
|
||||
import { SplitterEditor } from './SplitterEditor'
|
||||
import { ChestEditor } from './ChestEditor'
|
||||
import { TempEditor } from './TempEditor'
|
||||
import { TrainStopEditor } from './TrainStopEditor'
|
||||
|
||||
/**
|
||||
* Factory Function for creating Editor based on Entity Number
|
||||
@ -72,6 +73,10 @@ export function createEditor(entity: Entity): Editor {
|
||||
case 'rocket_silo':
|
||||
editor = new TempEditor(entity)
|
||||
break
|
||||
// Train stop
|
||||
case 'train_stop':
|
||||
editor = new TrainStopEditor(entity)
|
||||
break
|
||||
default: {
|
||||
return undefined
|
||||
}
|
||||
|
@ -497,6 +497,34 @@ export class Entity extends EventEmitter {
|
||||
return this.m_rawEntity.color
|
||||
}
|
||||
|
||||
/** Entity Train Stop Station name */
|
||||
public get station(): string {
|
||||
return this.m_rawEntity.station
|
||||
}
|
||||
|
||||
public set station(station: string) {
|
||||
if (this.m_rawEntity.station === station) return
|
||||
|
||||
this.m_BP.history
|
||||
.updateValue(this.m_rawEntity, ['station'], station, 'Change station name')
|
||||
.onDone(() => this.emit('station'))
|
||||
.commit()
|
||||
}
|
||||
|
||||
/** Entity Train Stop Trains Limit */
|
||||
public get manualTrainsLimit(): number | undefined {
|
||||
return this.m_rawEntity.manual_trains_limit
|
||||
}
|
||||
|
||||
public set manualTrainsLimit(limit: number | undefined) {
|
||||
if (this.m_rawEntity.manual_trains_limit === limit) return
|
||||
|
||||
this.m_BP.history
|
||||
.updateValue(this.m_rawEntity, ['manual_trains_limit'], limit, 'Change trains limit')
|
||||
.onDone(() => this.emit('manualTrainsLimit'))
|
||||
.commit()
|
||||
}
|
||||
|
||||
public get operator(): string {
|
||||
if (this.name === 'decider_combinator') {
|
||||
const cb = this.m_rawEntity.control_behavior
|
||||
|
Loading…
x
Reference in New Issue
Block a user