an idea about layer safety
James Paige <Bob <at> HamsterRepublic.com>
2009-08-04 19:04:27 GMT
I have an idea I want to throw out for the other developers to comment
on. I don't tknow if this is a good idea or not, but I am thinking out
out here...
Eventually, various standard gui elements will be drawn using slices. I
already have a partial implementation of drawing text boxes using
slices.
I have two somewhat conflicting goals in doing this.
1) I want to make it easier for us as developers to maintain and extend
the interface
2) I want to make it possible for game authors to tweak the interface
with their scripts.
The reason I think these two goals could be at odds, is because once
game authors start writing scripts that make assumptions about the
tree-layout of the interface, those tree-layouts can't be changed
without a risk of breaking games.
For example, suppose I implement:
get text box portrait slice
which returns a handle to the portrait of the currently displaying text
box.
An enterprising scripter might discover that they can get the text box
container by doing
parent slice(parent slice(get text box portrait slice))
Then they might discover that they can get a handle to the text of the
text box by doing
first child(first child(parent slice(parent slice(get text box
portrait slice))))
Now obviously that is messy code, but it would work. And maybe I
haven't gotten around to implementing "get text box text slice" yet
(yeah, the namespace for these command iss a whole different discussion)
so since it works, somebody does it, but down the line, maybe I change
the order in which the slices are constructed, or add an aditional
container slice around the portrait to handle variable padding, or who
knows what? Breakage!
One option is to grin and bear it. We already have a situation like this
with some of our other commands (the one for manipulating enemy data
comes to mind)
But what if we add a feature to the slices that allows us to mark
certain slices as "protected"?
A protected slice could still be asked for specifically, maybe by
commands like:
get text box portrait slice
or better yet:
slice by name(string)
but if you tried to get a protected slice using "parent slice" it would
fail
and if you tried to get a protected slice with "first child" or "next
sibling" it would be skipped.
That way it would not be possible to traverse protected slices in a
dangerous way, but you could still get handles to them and you could
still give them new children.
Alternately, maybe we could protect slices but just write a debug
warning any time someone tries to traverse to one of them... that would
alow people to write bad dangerous slice code, but it would at least
give them a heads-up first.
Another alternative would be to make protected slices, but to add
commands like "unsafe parent slice" "first unsafe child" "next unsafe
sibling" to allow scripters to traverse protected slices if they REALLY
want to, but making our documentation job easy, since there would then
only be a couple places that we would have to write "use this at your
own risk!!!" (instead of having to write it in the docs for almost every
command :P)
---
James