game: add: class: point and segment, add: type docstring
This commit is contained in:
33
frontend/static/js/api/game/Segment.js
Normal file
33
frontend/static/js/api/game/Segment.js
Normal file
@ -0,0 +1,33 @@
|
||||
import { Point } from "./Point.js"
|
||||
|
||||
class Segment
|
||||
{
|
||||
/**
|
||||
* @param {Point} start
|
||||
* @param {Point} stop
|
||||
*/
|
||||
constructor(start, stop)
|
||||
{
|
||||
this.start = start === undefined ? new Point() : start;
|
||||
this.stop = stop === undefined ? new Point() : stop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
*/
|
||||
draw(ctx)
|
||||
{
|
||||
ctx.moveTo(this.start.x, this.start.y);
|
||||
ctx.lineTo(this.stop.x, this.stop.y);
|
||||
}
|
||||
|
||||
from_json(data)
|
||||
{
|
||||
this.start = this.start.from_json(data.start);
|
||||
this.stop = this.stop.from_json(data.stop);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export { Segment }
|
Reference in New Issue
Block a user