Skip to content

Latest commit

 

History

History
393 lines (278 loc) · 8.02 KB

File metadata and controls

393 lines (278 loc) · 8.02 KB

lots-o-nekos Documentation

Oneko class

since: 1.0.0

Constructors

Oneko objects are constructed using this syntax:

new Oneko(options: OnekoOptions);

Properties

allowedIdleAnimations: OnekoIdleAnimation[]

since: 3.0.0

A list of animations that the Oneko can use when idle.

Default value:

[
  "scratchSelf",
  "scratchWallE",
  "scratchWallN",
  "scratchWallS",
  "scratchWallW",
  "sleeping"
]

allowedTargetDistance: number

since: 3.0.0

The maximum distance, in pixels, that the Oneko is allowed to be from the target point before it becomes idle.

Default value: 48

element: HTMLDivElement | null

since: 1.0.0

An HTMLDivElement used to represent the Oneko in the document.

Default value: HTMLDivElement

frameCount: number

since: 1.0.0

How long the Oneko has been alive for. Measured by how many times the Oneko's element has been updated.

Default value: 0

idleAnimation: OnekoIdleAnimation

since: 1.0.0

The idle animation that's currently playing. null means the regular idle animation of being played.

Default value: null

idleAnimationFrame: number

since: 1.0.0

The current frame of the playing idle animation.

Default value: 0

idleTime: number

since: 1.0.0

How long the Oneko has been idle for. Measured by how many times the Oneko's element has been updated.

Default value: 0

lastFrameTimestamp: number

readonly since: 2.3.0

The timestamp of the last time the Oneko's element was updated.

loopAnimating: boolean

since: 2.2.0

Controls if onAnimationFrame() loops called after each completion of itself.

Default value: true

maxAlertDuration: number

since: 3.0.0

The maximum number of frames the Oneko will spend in the alert state before moving towards the target point.

Default value: 7

scratchDuration: number

since: 3.0.0

The number of frames the Oneko will spend in any scratching animation before the idle animation is reset.

Default value: 9

size: number

since: 3.0.0

How big the Oneko is, in pixels.

Default value: 32

skipAlertAnimation: boolean

since: 2.2.0

Controls if the alert animation is skipped before running begins.

Default value: false

sleepDuration: number

since: 3.0.0

The number of frames the Oneko will spend in the main sleep animation before the idle animation is reset.

Default value: 192

source: string

since: 1.0.0

The path to an image file used to represent the Oneko, as a string.

Default value: "https://raw.githubusercontent.com/raynecloudy/oneko_db/refs/heads/master/default.png"

speed: number

since: 1.0.0

How far the Oneko runs per update, in pixels.

Default value: 10

spriteSets

since: 1.0.0

A keyed list of arrays of points ([number, number]), defined as animations.

Default value:

{
  idle: [[-3, -3]],
  alert: [[-7, -3]],
  scratchSelf: [
    [-5, 0],
    [-6, 0],
    [-7, 0],
  ],
  scratchWallN: [
    [0, 0],
    [0, -1],
  ],
  scratchWallS: [
    [-7, -1],
    [-6, -2],
  ],
  scratchWallE: [
    [-2, -2],
    [-2, -3],
  ],
  scratchWallW: [
    [-4, 0],
    [-4, -1],
  ],
  tired: [[-3, -2]],
  sleeping: [
    [-2, 0],
    [-2, -1],
  ],
  N: [
    [-1, -2],
    [-1, -3],
  ],
  NE: [
    [0, -2],
    [0, -3],
  ],
  E: [
    [-3, 0],
    [-3, -1],
  ],
  SE: [
    [-5, -1],
    [-5, -2],
  ],
  S: [
    [-6, -3],
    [-7, -2],
  ],
  SW: [
    [-5, -3],
    [-6, -1],
  ],
  W: [
    [-4, -2],
    [-4, -3],
  ],
  NW: [
    [-1, 0],
    [-1, -1],
  ],
}

targetX: number

since: 1.0.0

The X position the Oneko is running towards, in pixels.

Default value: 16

targetY: number

since: 1.0.0

The Y position the Oneko is running towards, in pixels.

Default value: 16

updateSpeed: number

since: 1.0.0

How fast the Oneko updates its animations, in milliseconds.

Default value: 100

x: number

since: 1.0.0

The Oneko's element's position on the X axis, in pixels.

Default value: 16

y: number

since: 1.0.0

The Oneko's element's position on the Y axis, in pixels.

Default value: 16

yawnDuration: number

since: 3.0.0

The number of frames the Oneko will spend in the tired state before entering the main sleep animation.

Default value: 8

Methods

canInitialize(): Oneko

static since: 3.0.0

Returns true if an Oneko can be initialized under current conditions. An example in which this would return false is if the prefers-reduced-motion media query is set to reduce.

draw(): Oneko

since: 2.3.0

Updates the Oneko element's position and image. Fires the draw event after completion.

force(): Oneko

since: 3.0.0 throws Error if Oneko cannot be initialized.

Forces an initialized Oneko object.

frame(): Oneko

since: 2.3.0

Controls all animation logic.

idle(): Oneko

since: 2.3.0

Controls idle animation logic (scratching, sleeping, etc.)

isInitialized(): boolean

since: 3.0.0

Only true if the Oneko has been properly initialized. For example, if the prefers-reduced-motion media query is set to reduce, the Oneko will not initialize.

moveTo(x: number, y: number): Oneko

since: 2.3.0

Sets the Oneko's target coordinates and element position.

onAnimationFrame(timestamp: number): Oneko

since: 2.3.0

Runs every frame. Enables Oneko animations. timestamp is the duration since the last update.

resetIdleAnimation(): Oneko

since: 2.3.0

Resets the idle animation.

createDatabaseSourceURL(sourceName: OnekoDatabaseSource): string

static since: 3.0.0

Constructs a complete URL path to a file of a given name on the online source database.

setPosition(x: number, y: number): Oneko

since: 2.3.0

Sets the coordinates for the Oneko element to be positioned at.

setSourceDB(sourceName: OnekoDatabaseSource): Oneko

since: 2.1.0

Sets the source image of the Oneko element to a URL accessing the source database of Oneko PNGs (https://github.com/raynecloudy/oneko_db/).

setSprite(name: string, frame: number): Oneko

since: 2.3.0

Sets the sprite image to a given frame of a given animation.

setTarget(x: number, y: number): Oneko

since: 1.0.0

Set the coordinates for the Oneko to run to. x and y are pixel values.

Events

draw

since: 1.1.0

Fires when the draw method is finished.

startRunning

since: 2.0.0

Fires when the target coordinate becomes outside range, after alert animation plays.

stopRunning

since: 2.0.0

Fires when target coordinate becomes inside range.

OnekoDatabaseSource type

private since: 2.3.0

Used as Oneko.prototype.setSourceDB's sourceName argument's type.

type OnekoDatabaseSource = "ace" | "black" | "bunny" | "calico" | "default" | "eevee" | "esmeralda" | "fox" | "ghost" | "gray" | "jess" | "kina" | "lucy" | "maia" | "maria" | "mike" | "silver" | "silversky" | "snuupy" | "spirit" | "tora" | "valentine";

OnekoIdleAnimation type

private since 2.3.0

Used as Oneko.prototype.idleAnimation's type.

type OnekoIdleAnimation = "sleeping" | "scratchSelf" | "scratchWallW" | "scratchWallN" | "scratchWallE" | "scratchWallS";

OnekoOptions type

private since: 2.3.0

Used as the Oneko class constructor's options argument's type.

type OnekoOptions = {
  allowedIdleAnimations?: OnekoIdleAnimation[],
  allowedTargetDistance?: number,
  element?: HTMLDivElement | null,
  frameCount?: number,
  idleAnimation?: OnekoIdleAnimation,
  idleAnimationFrame?: number,
  idleTime?: number,
  loopAnimating?: boolean,
  size?: number,
  skipAlertAnimation?: boolean,
  skipElementInit?: boolean, // Determines if the Oneko's element has automatic styling applied to it.
  source?: number,
  speed?: number,
  targetX?: number,
  targetY?: number,
  updateSpeed?: number,
  x?: number,
  y?: number,
};

OnekoSpriteSetOptions type

private since: 2.4.0

Used as Oneko.prototype.setSprite's setName argument's type.

type OnekoSpriteSetOptions = keyof typeof Oneko.prototype.spriteSets;