<commit_before>import nimx / [ types, context, image, animation, property_visitor, system_logger ]
import nimx / assets / asset_manager

import json, strutils

import rod.rod_types
import rod.node
import rod.ray
import rod.tools.serializer
import rod.component

import rod / utils / [ property_desc, serialization_codegen ]

type Sprite* = ref object of Component
    offset*: Point
    size*: Size
    frameOffsets*: seq[Point]
    images*: seq[Image]
    mCurrentFrame*: int16
    segmentsGeometry: seq[float32] # Used for nine-part images
    when not defined(release):
        resourceUrl: string

Sprite.properties:
    images:
        serializationKey: "fileNames"
        combinedWith: frameOffsets

    segmentsGeometry:
        serializationKey: "segments"

template `currentFrame`*(s: Sprite): int =
    int(s.mCurrentFrame)

template `currentFrame=`*(s: Sprite, v: int) =
    # when not defined(release):
    #     assert(v >= 0, s.resourceUrl & " currentFrame negative")
    s.mCurrentFrame = int16(v)

proc image*(s: Sprite): Image =
    if s.images.len > s.currentFrame:
        result = s.images[s.currentFrame]

proc `image=`*(s: Sprite, i: Image) =
    if s.images.isNil:
        s.images = newSeq[Image](1)
    else:
        s.images.setLen(1)
    s.images[0] = i
    s.currentFrame = 0

proc getOffset*(s: Sprite): Point =
    result = s.offset
    if s.frameOffsets.len > s.currentFrame:
        result += s.frameOffsets[s.currentFrame]
<commit_msg>Added check for negative value (#290)<commit_after>import nimx / [ types, context, image, animation, property_visitor, system_logger ]
import nimx / assets / asset_manager

import json, strutils

import rod.rod_types
import rod.node
import rod.ray
import rod.tools.serializer
import rod.component

import rod / utils / [ property_desc, serialization_codegen ]

type Sprite* = ref object of Component
    offset*: Point
    size*: Size
    frameOffsets*: seq[Point]
    images*: seq[Image]
    mCurrentFrame*: int16
    segmentsGeometry: seq[float32] # Used for nine-part images
    when not defined(release):
        resourceUrl: string

Sprite.properties:
    images:
        serializationKey: "fileNames"
        combinedWith: frameOffsets

    segmentsGeometry:
        serializationKey: "segments"

template `currentFrame`*(s: Sprite): int =
    int(s.mCurrentFrame)

template `currentFrame=`*(s: Sprite, v: int) =
    # when not defined(release):
    #     assert(v >= 0, s.resourceUrl & " currentFrame negative")
    s.mCurrentFrame = int16(v)

proc image*(s: Sprite): Image =
    if s.images.len > s.currentFrame and s.currentFrame >= 0:
        result = s.images[s.currentFrame]

proc `image=`*(s: Sprite, i: Image) =
    if s.images.isNil:
        s.images = newSeq[Image](1)
    else:
        s.images.setLen(1)
    s.images[0] = i
    s.currentFrame = 0

proc getOffset*(s: Sprite): Point =
    result = s.offset
    if s.frameOffsets.len > s.currentFrame and s.currentFrame >= 0:
        result += s.frameOffsets[s.currentFrame]

{'fraction_non_alphanumeric': 0.11262458471760797, 'fraction_numerical': 0.008970099667774087, 'mean_word_length': 3.2769886363636362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4789860', 'n_tokens_mistral': 977, 'n_tokens_neox': 962, 'n_words': 253}