Update eventSyncRequest() docs, and x,y params -> tile units#4814
Update eventSyncRequest() docs, and x,y params -> tile units#4814aubergineagain wants to merge 3 commits intoWarzone2100:masterfrom
eventSyncRequest() docs, and x,y params -> tile units#4814Conversation
The docs for `eventSyncRequest()` did not specify the first parameter (`fromPlayerId`), or the units used for `x,y` params, and incorrectly stated that the object params were `id` when they are actual game objects (or `null` if not defined). Additionally, the `x,y` params were not being converted back to tile units before being passed to the JS API. I've checked every mod and script I can find and haven't found a single place where anyone was using this event, most likely because the original docs were super-confusing. Fixes Warzone2100#4738 , Warzone2100#4737
// Convert x,y from world coordinates to tile coordinates
int tile_x = map_coord(x);
int tile_y = map_coord(y);
...
instance->handle_eventSyncRequest(from, req_id, tile_x, tile_y, psObj, psObj2);I like the documentation changes but I don't understand why this breaking change is being made? It seems completely unnecessary and will break all existing implementations of |
|
I first learnt about the issues with the
That post also references an issue with similar report: #3193 (now added to Fixes list in OP of this PR) As far as I can tell, only wanjia has ever done anything with
Maybe we should add a new, optional, string parameter so it's much easier to just send a string in a single packet? For example: const str = JSON.stringify(someObj);
syncRequest(x, y, null, null, str);
//...
function eventSyncRequest(from, x, y, o1, o2, str)
{
const text = JSON.parse(str);
} |
|
I couldn't find if wanjia had a github acct so posted in linked forum posts asking for feedback on breaking change to the x/y params. |
The `syncRequest` / `eventSyncRequest` is exclusive to JS API, so removed the useless conversion to world units and subsequent conversion back to tile units. Entire process is now in tile units. Also, as maps are limited to 256x256 tiles, changed `int32` to `uint8` to reduce packet size.
Make sure `x,y` fit in `uint8_t` before sending the request.
|
@aco4 Are you using syncRequest in similar way to wanjia1's mods (encoding abstract data in to the integer params)? If so, would it be better to add a new function/event pair: |
|
@aubergineagain I am indeed. Yes, syncString() is a great idea. About "fixing" eventSyncRequest() — I really don't see any problem with its current form. The documentation was wrong, but once that is updated, the event will work without issue. Why change the API for something so trivial? |
|
Added PR for As for fixing |
The docs for
eventSyncRequest()did not specify the first parameter (fromPlayerId), or the units used forx,yparams, and incorrectly stated that the object params wereidwhen they are actual game objects (ornullif not defined).Additionally, the
x,yparams were not being converted back to tile units before being passed to the JS API.I've checked every mod and script I can find and haven't found a single place where anyone was using this event, most likely because the original docs were super-confusing.
Fixes #4738
Fixes #4737
Fixes #3193