More editor UI improvements

Most of what I got done today was improvements to the different "modes" you can be in while editing shapes - by mode, I simply mean "adding blocks" "deleting blocks" or "setting the center of the shape". Worked on styling li items as buttons, realizing that it is very easy to use too much markup to describe something on the page, and remembering that to write solid javascript, you really need to code as if everything in the world is out to get you.

On that last point, it's always a good practice to code defensively, but I've noticed a greater need for it in javascript, due partially to the nature of the language, partially to differing implementations in different browsers, and partially due to the inconsistency of how different libraries implement their functionality. For instance, I need to pass data about shapes, game rules, and such back and forth between the client and server. I've been using JSON for that, and it works quite well - but the javascript file provided by json.org breaks prototype. The solution to this is to use the newest stable version of prototype, which has JSON support built in. Or you could always roll your own JSON encoder / decoder - it's not really all that complicated.

On the rails side, I've just been using YAML.load, since JSON tends to be valid YAML (god, not to be confused with YAML...), and I was running into some issues with getting rails' json support working correctly.

Another thing that bit me about javascript was NaN being typeof "number". This is documented, and pretty common among languages, and there's a isNaN test, but for some reason, I tend to never expect it. Bah.

No comments:

Post a Comment