k4kfh / ZephyrCab

Drive a model train with prototypical controls, realistic behavior, and simulated physics; uses JMRI's WebSockets interface for layout connection
http://k4kfh.github.io/ZephyrCab
GNU Affero General Public License v3.0
10 stars 4 forks source link

Rewrite UI.js #17

Closed k4kfh closed 7 years ago

k4kfh commented 7 years ago

UI.js is in need of a major overhaul. I'm making this issue to keep track of my own efforts to fix it.

ToDo:

k4kfh commented 7 years ago

I really need to upgrade MaterializeCSS to a later version, but I'll have to use SASS and recompile it, so that'll have to wait a little bit.

k4kfh commented 7 years ago

I've decided to rewrite this in the master branch for simplicity's sake.

k4kfh commented 7 years ago

Note: Need to decide if we're going to keep the locomotive name plate in the cab view. If so, we need to build a replacement for ui.cab.locoName.update(), if not we need to go through and remove all those calls.

k4kfh commented 7 years ago

Also need to figure out what ui.layout.power.status.update() did, and if it needs to be replaced.

k4kfh commented 7 years ago

ui.layout.power.status.update() has been removed/replaced. It wasn't really a complex function anyway.

Also I have successfully (I think) replaced ui.cab.currentLoco and friends. So that's good.

k4kfh commented 7 years ago

I just fixed the headlight switch to work, and added a "not implemented yet" message to the sand switch.

k4kfh commented 7 years ago

In order to effectively rewrite ui.js, it looks like I'll probably have to rewrite sim.js too. Currently there are some very non-asynchronous architectural quirks in sim.js. For example, engine start is handled by a very clunky if statement in sim.js that checks the state of a button. This should be consolidated to a button click event that sets a single boolean variable. This isn't an isolated thing either, there's several dumb architectural/design mistakes I've made in this, and leaving them as is will just mean I have to do another ui.js overhaul in 2 months, since the two files integrate so closely.

k4kfh commented 7 years ago

I've began rewriting sim.js and ui.js together, but I kept the old version of sim.js for reference in scripts/sim-old.js.

The one clunky part of the rewrite is the engine start/stop switch; it works, and it's very asynchronous, but it could use a little improvement. The UI switch code actually does a lot of work; it checks the fuel and everything before actually calling the DCC decoder's engine start method. The code in sim.js (inside the if statement that runs when a locomotive runs out of fuel) also has the ability to call the DCC decoder method to shut off the engine. It works, but it's rather hard to read, and I'm thinking of commenting out all the executable fuel code anyway since most people don't care a lot about that right now.

k4kfh commented 7 years ago

With the last few commits, the new version of ui.js has proven solid. It's basically finished, so I am closing this issue.