DinnerBuffet / TTSCarcassonne

Script and data for the Tabletop Simulator mod
MIT License
45 stars 23 forks source link

Farms on tile fbe423 #12

Open mmann78 opened 2 years ago

mmann78 commented 2 years ago

I found a bug on tile fbe423 (part of the princess and the dragon expansion) where I can't place a meeple on one of the farming sides of the tile. I thought this would be a straightforward enough bug to fix, but I'm having some issues and I'm hoping to be pointed in the correct direction. I've worked much more with the "scripting" code that I can easily upload changes to and see them applied. Actual objects (like tiles) have been much more of struggle. In this case, I went to directly modifying the saved JSON file (of my test setup with the tile) in hopes of understanding the "properties" of the tile. Strictly as a test, I modified the "properties" (script) of tile fbe423 to match exactly the "properties" of tile 10551f (in abbey and mayor expansion). The "castle shapes" on 10551f were similar enough that I expected to see a change in behavior of tile fbe423 when placed. This presumes that the Card.fbe423.ttslua is the only place this information is stored (I have not found anything to contradict that) and that the tile itself is just a graphic. When I did that, I didn't get any change in behavior, and the "markers" for the tile didn't change (and I triple checked with the scripting dialog within TTS that my new scripting code had been applied to the fbe423 tile). One thing I'm looking for is the code that determines "markers". And there seem to be 2 types of markers and I've only found code for the "hint markers" (which I could easily change to intentionally have them never appear). In this case the "hint markers" are correct and think I should be able to place a meeple in the desired farm side, but the "other" markers (that I don't have a name for), still don't make a "shadow" of a meeple on the desired farm location and trying to place a meeple in the farm area, it will just snap to center (inside the castle) when I try to drop the meeple. One thought I had was to somehow combine the two so if "hint markers" are enabled (because that is a preference that someone could turn off), that the meeple should be able to cycle through different hint markers (with mouse movement) instead of the "other" markers. But I would settle for just having the "other" markers recognize the validity of the farm.

Any advice would be appreciated.

DinnerBuffet commented 2 years ago

Not 100% sure I follow what the issue is. It sounds like the issue is that the meeple is not "snapping" to the correct place on the tile. Is that right? The snap points are not programmatically controlled and are added to the tiles by hand*. You'll need to add a snap point to the tile at the point where you want your meeple to snap to. Note that a snap point isn't required to place it there. You can still pick up the meeple with left-click, hold right-click, then release left-click to bypass the snap points and place it where you wish. If I'm misinterpreting the issue please let me know.

*Side-note: I believe TTS eventually added the ability to add snap points in code, but only after I had already manually added all of the snap points to all of the tiles. If you had to do it over again, I suggest adding the snap points via code. I had long wanted to generate all of the tiles via code instead of pulling them from bags, but never got around to it.

mmann78 commented 2 years ago

Not 100% sure I follow what the issue is. It sounds like the issue is that the meeple is not "snapping" to the correct place on the tile. Is that right? The snap points are not programmatically controlled and are added to the tiles by hand*. You'll need to add a snap point to the tile at the point where you want your meeple to snap to. Note that a snap point isn't required to place it there. You can still pick up the meeple with left-click, hold right-click, then release left-click to bypass the snap points and place it where you wish. If I'm misinterpreting the issue please let me know.

I believe you are correct and the "other markers" I was referring to are snap points, I just didn't realize that was the name. I was also able to do the "mouse click dance" you mentioned and was able to put the meeple where desired, however I still think I want to adjust the tile (and a few others I've come across) for the additional snap point(s).

*Side-note: I believe TTS eventually added the ability to add snap points in code, but only after I had already manually added all of the snap points to all of the tiles. If you had to do it over again, I suggest adding the snap points via code. I had long wanted to generate all of the tiles via code instead of pulling them from bags, but never got around to it.

This may spill into a different GitHub issue, but this sounds like a great idea (that I would gladly take on). How would you recommend generating all tiles from code? (This is where my understanding of the TTS architecture is lacking) I thought the bags at the "start" of the game helped with creating and persisting the TTS objects (tiles and game pieces). I guess minimally the snap points would be added to each tile script, i.e Card.fbe423.ttslua, and then those properties could be applied? I presume I should be writing this type of code in Lua, but since the "save file format" is just JSON, it seems potentially better to just use a JSON parser to inject the necessary code.

DinnerBuffet commented 2 years ago

Not 100% sure I follow what the issue is. It sounds like the issue is that the meeple is not "snapping" to the correct place on the tile. Is that right? The snap points are not programmatically controlled and are added to the tiles by hand*. You'll need to add a snap point to the tile at the point where you want your meeple to snap to. Note that a snap point isn't required to place it there. You can still pick up the meeple with left-click, hold right-click, then release left-click to bypass the snap points and place it where you wish. If I'm misinterpreting the issue please let me know.

I believe you are correct and the "other markers" I was referring to are snap points, I just didn't realize that was the name. I was also able to do the "mouse click dance" you mentioned and was able to put the meeple where desired, however I still think I want to adjust the tile (and a few others I've come across) for the additional snap point(s).

Yup it should be trivial to adjust them. Just note that the snap point system can go wonky from time to time. You'll likely not run into any issues if you're just editing a few, though.

*Side-note: I believe TTS eventually added the ability to add snap points in code, but only after I had already manually added all of the snap points to all of the tiles. If you had to do it over again, I suggest adding the snap points via code. I had long wanted to generate all of the tiles via code instead of pulling them from bags, but never got around to it.

This may spill into a different GitHub issue, but this sounds like a great idea (that I would gladly take on). How would you recommend generating all tiles from code? (This is where my understanding of the TTS architecture is lacking) I thought the bags at the "start" of the game helped with creating and persisting the TTS objects (tiles and game pieces). I guess minimally the snap points would be added to each tile script, i.e Card.fbe423.ttslua, and then those properties could be applied? I presume I should be writing this type of code in Lua, but since the "save file format" is just JSON, it seems potentially better to just use a JSON parser to inject the necessary code.

Sorry it's been a long time since I looked at the TTS API. I had forgotten that you can't create a deck from code. spawnObject only allows you to create a "custom object"(not primitives game objects like dice, cards, etc). I knew there was something else stopping me! Though I've never tried spawnObjectJSON(), I would guess it only works for "custom objects" as well.

nullstalgia commented 2 years ago

Sorry to boop a stale issue, but I wanted to correct something @DinnerBuffet said.

You actually can make decks from code. There's a great library called Decker that lets you take an image URL and make decks and cards from it.

I've been working on adding many decks to a Cards Against Humanity table I've been working on, and I needed a better way to spawn the decks.

Here's some snippets from a tool I made that takes PNGs, the card #, and spawns decks as needed: image

local cardAsset = Decker.Asset(url, cardBack)

Decker.Card(cardAsset, 1, 1):spawn({position = {self.getPosition().x+2.5, 3, self.getPosition().z-3}})
local cardAsset = Decker.Asset(url, cardBack, {width = 10, height = 7})
Decker.AssetDeck(cardAsset, cardCount):spawn({position = {self.getPosition().x+2.5, 3, self.getPosition().z-3}})

The Decker documentation does not show using AssetDecks, unfortunately. I wish it did, as when I tried to make a deck by making many card objects and putting it into an array, it gave me WEIRD bugs.

So make sure to use AssetDeck if you just want to spawn a whole deck at once

I also had to rename my Decker file to Decker.ttslua in the path to get the require("Decker") to work not Decker.Decker