philihp / weblabora

Ora et Labora boardgame simulation library
http://kennerspiel.com
Apache License 2.0
11 stars 2 forks source link

Buildings d'n'd #93

Open adambadura opened 11 years ago

adambadura commented 11 years ago

To build a building user should be able to drag it from available buildings list and drop it on his board.

Useful features (not necessarily to be implemented in first version) are: (1) Automatic conversions of Grain -> Straw. (2) Being able to drop on non-existing plot/district (in which case proper buy would have to be done). (3) Some means of using prior after the drop (but maybe adding d'n'd of workers in future will solve this). (4) Re-dragging to a different place.

After a valid drop the page will put proper text in the move edit box. The building will lay on drop place but highlighted. Resources used will be highlighted. Then user can commit the move as he would with hand-edited command.

Open issues are: (1) How to cancel such operation. A cancel/clear button (likely placed near the edit box) seems fine. (2) What to do with manual edits of the text in edit box? It would be nice if the board updated properly but what if the text is invalid after the move? How much are we willing to check on client site? (3) How to cope with d'n'd of more than one building.

adambadura commented 11 years ago

In 4a3cce6 I have created a new branch (issue-93) with initial d'n'd code. Just possibility to d'n'd and working only in IE (various browsers drag various elements and JS has to be extended to go to common parent first).

philihp commented 11 years ago

http://jqueryui.com/demos/draggable/ might make things easier, and it's cross-browser.

Also, IE8 isn't currently supported because of the inline SVG, so you needn't worry about it :)

adambadura commented 11 years ago

Interesting, I will have a look at that. Personally I would prefer to stick to HTML5-only features but I already predict some things will ba hard to achive. Thanks for the link.

adambadura commented 11 years ago

My investigations suggest that Safari (at least on Windows) in its current release (5.1.7) doesn't handle native HTML5 drop. You can drag but dropping doesn't work. Others (IE, FF, Chrome and Opera) seam fine for now.

Should I look into different (JavaScript based like the above) solutions or are we sacrificing Safari support?

philihp commented 11 years ago

Can you show me an HTML file that demonstrates it not working on Safari for Windows (but working on others)? I'll check and see if it works on Safari for OSX.

Also, if dragging & dropping turns out to be a pain, pointing and clicking is just as fine with me. It may even work better for our tablet users.

adambadura commented 11 years ago

Sorry for delay but I fall asleep over keyboard last night and decided to check if everything is fine in the morning. The issue-93 branch should contain proper code already. D'n'D works there in all the main browsers buf Safari.

Note also an external example here: http://html5demos.com/drag.

Point'n'click is MUCH worse in my opinion. In implementing. It is not clear for users. There are some special cases. I wouldn't go there. At least not know.

adambadura commented 11 years ago

I just pushed new changes. You can drag'n'drop a building onto playboard. Should look OK. And in addition a move is filled.

Now I will add generation of V commands needed to build.

What then? Maybe we should aim for integrating into running code?

philihp commented 11 years ago

Cool, go ahead and merge it in with Master and I'll take a look.

adambadura commented 11 years ago

I have just updated the branch with code for V(Gn) generation.

The code is still dump thou. It will add V(Gn) for every missing Straw, even if there is not enough Grain in the first place.

Also I removed Peat from building costs. It seems there is no such building that would cost Peat. Why was it there?

I think we should postpone merging until I add a bit more. At least validation of dropped board, terrain type and resources available.

What I don't know how to do now is proper feedback on why drop is not possible.

philihp commented 11 years ago

Also I removed Peat from building costs. It seems there is no such building that would cost Peat. Why was it there?

Good question... I wish I knew what I was thinking too :)

What was the question again on drop being possible?

adambadura commented 11 years ago

Drop (of a building) might not be possible because:

It seems I'm able to check all those conditions without much trouble. But all I can do is to say: no drop possible. And the user will see "no drop" cursor. Nothing more. While it would useful so somehow show to the user why the drop is not possible.

Currently server did that in response to a bad move. This could stay so. If user suspects a bug and wants to build anyway he can very well enter the command manually and execute is as before. And see server's reaction.

But if so then maybe we should also allow drop regardless of those conditions and let the server do the checking. Then again however generating V(Gn) would be wired (what should be generated if there is not enough Grain+Straws for the building?).

HTML 5 specification suggests that there should be rather large control over drag and drop feedback by allowing to specify element (possibly dynamic) to be shown as dragged. But my experiments suggest that this does not work well in cross browser environment. But then again maybe we should do it anyway and when other browsers catch up it will be there already.

adambadura commented 11 years ago

In the mean time I made few commits (already pushed) for this issue. D'n'd validity checking is almost done.

What is still missing is counting available resources and check against dropping a second building.

adambadura commented 11 years ago

In 1487159d1e (on issue-93 branch) I have added drop possibility check for available resources.

What remains to be done: