Commit b2c13161 authored by noasakurajin's avatar noasakurajin
Browse files

using libtrainsim go library

parent 426749be
module train-creator
go 1.16
require git.thm.de/bahn-simulator/libtrainsim-go v0.0.0-20210606125647-5db49d872a16
......@@ -3,11 +3,12 @@ package main
import (
"encoding/json"
"fmt"
"git.thm.de/bahn-simulator/libtrainsim-go"
"io/ioutil"
"log"
)
var supportedVersions = [...]versionStruct { {0,4,0} }
var supportedVersions = [...]libtrainsim.VersionStruct { {Major:0, Minor:4, Patch:0} }
func main(){
......@@ -21,19 +22,24 @@ func main(){
create(selectedVersion)
}
func create(version versionStruct){
var trainConfig trainProperties
func create(version libtrainsim.VersionStruct){
var trainConfig libtrainsim.TrainProperties
switch version {
case versionStruct{0,4,0}:
case libtrainsim.VersionStruct{Major:0, Minor:4, Patch:0}:
tmp := createTrainProperties040()
trainConfig = tmp.cast()
trainConfig = tmp.Cast()
default:
trainConfig = createTrainProperties()
}
if !trainConfig.IsValid(){
fmt.Println("The train configuration is not valid. Restart the program and try again!")
return
}
filename := trainConfig.Name + ".json"
jOutput, err := json.MarshalIndent(trainConfig, "", "")
jOutput, err := json.MarshalIndent(trainConfig, "", " ")
if err != nil {
log.Fatalln(err.Error())
return
......
package main
type versionStruct struct {
Major int64
Minor int64
Patch int64
}
type trainProperties struct{
trainProperties040
}
type trainProperties040 struct {
Name string `json:"name"`
Mass float64 `json:"mass"`
MaxVelocity float64 `json:"maxVelocity"`
MaxAcceleration float64 `json:"maxAcceleration"`
FormatVersion string `json:"formatVersion"`
TrackDrag float64 `json:"trackDrag"`
AirDrag float64 `json:"airDrag"`
VelocityUnit string `json:"velocityUnit"`
}
func (b *trainProperties040) cast() trainProperties{
var retVal trainProperties
retVal.Name = b.Name
retVal.Mass = b.Mass
retVal.MaxVelocity = b.MaxVelocity
retVal.MaxAcceleration = b.MaxAcceleration
retVal.FormatVersion = b.FormatVersion
retVal.TrackDrag = b.TrackDrag
retVal.AirDrag = b.AirDrag
retVal.VelocityUnit = b.VelocityUnit
return retVal
}
import (
"git.thm.de/bahn-simulator/libtrainsim-go"
)
func createTrainProperties() trainProperties{
func createTrainProperties() libtrainsim.TrainProperties{
tmp := createTrainProperties040()
return tmp.cast()
return tmp.Cast()
}
func createTrainProperties040() trainProperties040{
var retVal trainProperties040
func createTrainProperties040() libtrainsim.TrainProperties040{
var retVal libtrainsim.TrainProperties040
retVal.FormatVersion = "0.4.0"
retVal.Name = readTrainName()
retVal.Mass = readPositiveFloat("Please enter the mass of the train:")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment