Page 1 of 1

[SOLVED] Precisions about Zone

Posted: 18 July 2016, 17:26
by Woodruff
Hello everybody :)

I am trying to customize a pile of cards using Zone component, but the documentation about it is rather sparse: http://en.doc.boardgamearena.com/Zone
I have three questions:

1) Is it mandatory to declare the zone inside the constructor?

Code: Select all

this.myZone = new ebg.zone();
I currently declare it in the setup because in the constructor I can't have access to the player list, and I need several zones for each player. Moreover, the stock component is declarable in the setup as the doc for it reads: http://en.doc.boardgamearena.com/Stock, what would it be different for zone?

2) I am using setPattern('custom') but I got an error message reading "unknown pattern: 'custom'" so I can't specify my item coordinates. This problem could be linked with number 1), since I declare the zone inside the setup and not the constructor...

3) How does the weight works for sorting items ? When I have already x cards in my zone, what value for weight should I use for:
  • Put a new card on top, that is on x+1 position;
  • Put a new card on bottom, that is in position 1 and other cards increase their position by one.
For the moment I use weight = x when I want to put the card at position x but it does not seem to work that way... In top of that, it seems that this weight is not saved with the tag in HTML so I surmise it has only a meaning when a card is added/deleted.

Do you have any experience with that? That would help me a lot ;)

Thanks

Tchebychev

Re: Precisions about Zone

Posted: 19 July 2016, 00:13
by Victoria_La
1) Is it mandatory to declare the zone inside the constructor?
I don't see why it would be. Its a regular java script object you can declare/create it anywhere you want.
2) I am using setPattern('custom') but I got an error message reading "unknown pattern: 'custom'" so I can't specify my item coordinates. This problem could be linked with number 1), since I declare the zone inside the setup and not the constructor...
I don't know where wiki gets this but looking at the source code there is no 'custom' mode, modes are
"grid", "diagonal", "verticalfit", "horizontalfit"
3) How does the weight works for sorting items ?
Weight is used by sorting function only when adding item. Items remain sorted after. It works as normal sorting operator a.weight <=> b.weight.
You can increase weight of all the cards BEFORE adding a new item, that should sort them properly. Or perhaps just go in negative numbers to add to the bottom?

Re: Precisions about Zone

Posted: 19 July 2016, 09:48
by Woodruff
Thanks Victoria_La.

1) OK, that seems to be consistent.

2) With 'verticalfit' and 'horizontalfit', is it possible to make the cards cover each other with at a given percentage?

3)
You can increase weight of all the cards BEFORE adding a new item
So I understand that this weight is stored somewhere for each item. Could you indicate me the method(s) to access and update it individually?

[SOLVED] Precisions about Zone

Posted: 19 July 2016, 11:19
by Woodruff
OK, with some investigations I think I can now answer my own questions. Please correct me if I'm wrong.

I explored the stock object using Firebug and here's what I found:
  • zone.item_margin enables to set the margin between cards. But it seems this margin cannot be negative so I can't use that.
  • zone.item_pattern stores the pattern. Since there is no 'custom' mode anymore, 4 functions zone.itemToCoordsX can be found:
    • zone.itemToCoordsGrid to be used with 'grid' pattern;
    • zone.itemIdToCoordsHorizontalFit to be used with 'horizontalfit' pattern;
    • zone.itemIdToCoordsVerticalFit to be used with 'verticalfit' pattern;
    • zone.itemIdToCoordsDiagonal to be used with 'diagonal' pattern.
    There is a 5th function called simply itemToCoord which is a legacy from 'custom' mode but I thinks its deprecated, I didn't found any way to apply it.
    Since I want to create card piles with cards covering each other in one direction (left, right or up), I went for the most generic solution. I stick to the 'grid' pattern and:
    • I update the width and the height of the zone dynamically when adding a card to avoid autofit which would screw up the shape of my pile;
    • I provide a function to zone.itemToCoordsGrid which depends of the direction of coverage.
  • zone.items is the array of the items currently inside the zone. Each item has two properties:
    • item.id which is its HTML id;
    • item.weight.
    So it's possible to update the weight of any item using something like zone.items.weight = <new weight>.