Elvas Tower: Container management - Elvas Tower

Jump to content

Posting Rules

All new threads will be started by members of the Open Rails team, Staff, and/or Admins. Existing threads started in other forums may get moved here when it makes sense to do so.

Once a thread is started any member may post replies to it.
  • 12 Pages +
  • « First
  • 3
  • 4
  • 5
  • 6
  • 7
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

Container management Rate Topic: -----

#41 User is offline   cjakeman 

  • Vice President
  • PipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 2,869
  • Joined: 03-May 11
  • Gender:Male
  • Location:Peterborough, UK
  • Simulator:Open Rails
  • Country:

Posted 02 May 2022 - 01:03 PM

View PostCsantucci, on 01 May 2022 - 07:08 AM, said:

Chris, I wanted to start with Json, but I've seen that there isn't the possibility to directly read a Vector3 (X, Y, Z), which is instead available for the StfReader, and which is quite useful for this function.
Also an item.AsBoolean(parameter) seems to be missing.
I am a zero in writing/expanding parsers, so I'd need help here if I have to use Json.

Sure. I'll take a look tomorrow and get back to you.

#42 User is offline   gpz 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,772
  • Joined: 27-October 12
  • Gender:Male
  • Location:Budapest
  • Simulator:OpenRails
  • Country:

Posted 03 May 2022 - 05:17 AM

View PostCsantucci, on 01 May 2022 - 07:08 AM, said:

Chris, I wanted to start with Json, but I've seen that there isn't the possibility to directly read a Vector3 (X, Y, Z), which is instead available for the StfReader, and which is quite useful for this function.

See an example here, how a vector3 can be defined in json:
https://github.com/K...TF/Box.gltf#L77
(This is a 3-element array.)

#43 User is offline   Csantucci 

  • Member, Board of Directors
  • Group: Status: Elite Member
  • Posts: 7,014
  • Joined: 31-December 11
  • Gender:Male
  • Country:

Posted 03 May 2022 - 06:07 AM

Thanks Peter,
it's clear how to define it. The problem (only for me) is how to parse it.

#44 User is offline   gpz 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,772
  • Joined: 27-October 12
  • Gender:Male
  • Location:Budapest
  • Simulator:OpenRails
  • Country:

Posted 03 May 2022 - 06:30 AM

The Vector3 struct is defined in the MonoGame package, while the json parser in the NewtonSoft.Json package, so they don't know about each other. Json can be parsed into float[], and that can be written into Vector3, I think.

#45 User is offline   Csantucci 

  • Member, Board of Directors
  • Group: Status: Elite Member
  • Posts: 7,014
  • Joined: 31-December 11
  • Gender:Male
  • Country:

Posted 03 May 2022 - 10:50 PM

Yes, that is a possible, indirect, solution. But in my ignorance I don't know how to read an array using Json parser calls...

#46 User is offline   gpz 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,772
  • Joined: 27-October 12
  • Gender:Male
  • Location:Budapest
  • Simulator:OpenRails
  • Country:

Posted 04 May 2022 - 12:54 AM

You may define the whole json structure as classes, like here:
https://github.com/p....cs#L1599-L1630

Then you can deserialize the string like this:
https://github.com/p...tfShape.cs#L338

It can be done in one pass for the whole complex object.

#47 User is offline   Csantucci 

  • Member, Board of Directors
  • Group: Status: Elite Member
  • Posts: 7,014
  • Joined: 31-December 11
  • Gender:Male
  • Country:

Posted 04 May 2022 - 02:30 AM

Thanks Peter,
I'll study that.

#48 User is offline   cjakeman 

  • Vice President
  • PipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 2,869
  • Joined: 03-May 11
  • Gender:Male
  • Location:Peterborough, UK
  • Simulator:Open Rails
  • Country:

Posted 04 May 2022 - 10:08 AM

Hi Carlo,

View Postcjakeman, on 02 May 2022 - 01:03 PM, said:

Sure. I'll take a look tomorrow and get back to you.

Still working on this.

I'm preparing a PR which extends Source\Orts.Parsers.OR\JsonReader.cs, but I was hoping to provide some parsing for you too.

Here is the test data I am using. Basically contains a list of objects each with Boolean, Vector3, free text, enum text and ints. Hope that will be a good starting point.

Attached Image: 2022-05-04 19_06_59-_C__dev_OR_cjakeman_openrails_Program_a.containers-or - Notepad++.jpg

#49 User is offline   Csantucci 

  • Member, Board of Directors
  • Group: Status: Elite Member
  • Posts: 7,014
  • Joined: 31-December 11
  • Gender:Male
  • Country:

Posted 04 May 2022 - 11:35 PM

Hi Chris and Peter,
in the meantime I could solve my problems. By analogy I could add an AsBoolean and for the vectors I used this simple syntax
		"IntrinsicShapeOffset": [0,1.17,-6.118],

which I was able to parse.

Thank you for your time.

#50 User is offline   cjakeman 

  • Vice President
  • PipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 2,869
  • Joined: 03-May 11
  • Gender:Male
  • Location:Peterborough, UK
  • Simulator:Open Rails
  • Country:

Posted 07 May 2022 - 10:49 AM

View PostCsantucci, on 01 May 2022 - 07:08 AM, said:

Chris, I wanted to start with Json, but I've seen that there isn't the possibility to directly read a Vector3 (X, Y, Z), which is instead available for the StfReader, and which is quite useful for this function.
Also an item.AsBoolean(parameter) seems to be missing.
I am a zero in writing/expanding parsers, so I'd need help here if I have to use Json.

If a JSON file is known to be valid then, using the JSON library, it can be read in a single statement (as it is currently in Updater, ActivityEditor and TrackViewer).

If it might be edited as a text file, then we can use OR's JsonReader class to parse data and report any issues in the log with the appropriate line number.
Aspects to consider include:

  • ensuring required properties are present
  • allowing optional properties to be present or absent
  • ignoring unexpected properties (if desired)

An example which reads valid data and invalid data, including Boolean and a Vector3, is now available at https://github.com/c...-container-file It also shows working with required, optional and unexpected properties.

I know Carlo already has a working solution, but this example shows how OR's JsonReader class is meant be used.


I've now submitted a PR which adds AsBoolean() and AsVector3() to OR's JsonReader class as used in this example. Credit to James for improving my attempt.

  • 12 Pages +
  • « First
  • 3
  • 4
  • 5
  • 6
  • 7
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users