-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add RoomTerrain.getRawBuffer() #247
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,12 @@ interface RoomTerrain { | |
* @return number Number of terrain mask like: TERRAIN_MASK_SWAMP | TERRAIN_MASK_WALL | ||
*/ | ||
get(x: number, y: number): 0 | TERRAIN_MASK_WALL | TERRAIN_MASK_SWAMP; | ||
/** | ||
* Get copy of underlying static terrain buffer. | ||
* @param destinationArray (optional) A typed array view in which terrain will be copied to. | ||
* @return Uint8Array Copy of underlying room terrain as a new Uint8Array typed array of size 2500. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although the documentation says that this method may return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, how about adding a jsdoc comment about possible error here
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the in-depth review. I'll update the branch tomorrow and let you know when it's ready for another review. |
||
*/ | ||
getRawBuffer(destinationArray?: Uint8Array): Uint8Array; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type of Btw, it's okay to copy value from uint8array to uint16array. The reverse also works const terrainData = new Uint8Array([1, 2, 3, 4, 5]);
const uint8Receiver = new Uint8Array(5);
uint8Receiver.set(terrainData, 0); // okey
console.log(uint8Receiver); // [1, 2, 3, 4, 5]
const uint16Receiver = new Uint16Array(5);
uint16Receiver.set(terrainData, 0); //okay
console.log(uint16Receiver); // [1, 2, 3, 4, 5]
const normalReceiver = new Array(5);
Uint16Array.prototype.set.call(normalReceiver, terrainData); // error: this is not a typed array. from uintArray16 to uintArray8 const terrainData = new Uint16Array([256,888]);
const uint8Receiver = new Uint8Array(5);
uint8Receiver.set(terrainData, 0); // okey
// (256 & ((1<<8)-1)) is 0, (888 & ((1<<8)-1)) is 120
console.log(uint8Receiver); // [ 0, 120, 0, 0, 0 ]
const uint16Receiver = new Uint16Array(5);
uint16Receiver.set(terrainData, 0); //okay
console.log(uint16Receiver); // [ 256, 888, 0, 0, 0 ] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should define a type alias of the Here are my suggestions for typing this method. getRawBuffer<T extends TypedArray = Uint8Array>(destinationArray?: T): T; or getRawBuffer<T extends TypedArray>(destinationArray: T): T;
getRawBuffer(): Uint8Array; In case there is no built-in union for type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array; |
||
} | ||
|
||
interface RoomTerrainConstructor extends _Constructor<RoomTerrain> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does not need to bump version here