# Fighter Factory 3 - Classes and functions

For problems and bug report, go to VirtuallTek Systems web site. For doubts related to M.U.G.E.N., go to a more specialized site like: Elecbyte, Mugen Fighters Guild, among others that you can find using Google.

Classes are implemented using Lua meta-tables. It provides properties (get/set functions that acts as a member variable), enumerations (small and read-only classes to list constant values) and functions.

Classes: To create a class you must use the class constructor. Eg.: classInstance = ClassName(); All classes that doesn't describe the constructor method can't be created by the user.

Properties: accessed using '.'. Eg.: variable = Class.propery; Class.property = variable;

Functions: accessed using ':'. Eg.: variable = Class:function(parameter);

Enumerations: accessed using '.'. Eg.: variable = Class.enumValue1;

Types: Lua is dynamic typed, then the type of vars isn't specified in the code. We will use the notation "{type}" to show the type. All properties are suposed to be read-only, otherwise will be marked as read-write.

# Functions

- rgb(red {integer}, green {integer}, blue {integer}) {integer}
  Returns a packed integer containing a RGB color. 'red', 'green' and 'blue' are values from 0 to 255.
- rgba(red {integer}, green {integer}, blue {integer}, alpha {integer}) {integer}
  Returns a packed integer containing a RGBA color. 'red', 'green', 'blue' and 'alpha' are values from 0 to 255.
- red(color {integer}) {integer}
  Returns the red value of the given integer-packed color.
- green(color {integer}) {integer}
  Returns the green value of the given integer-packed color.
- blue(color {integer}) {integer}
  Returns the blue value of the given integer-packed color.
- alpha(color {integer}) {integer}
  Returns the alpha value of the given integer-packed color.

# Classes

- Point - represents a point (x, y).
- Rect - represents a rectangle.
- BlendTarget - represents a blending target.
- RegExp - regular expression engine.
- TextDocument - used to manipulate text documents.
- SpritePalette - used to manipulate a single sprite palette.
- Sprite - used to manipulate a single sprite.
- Sprites - used to manipulate sprites.
- HitBox - used to manipulate a single hitbox.
- HitBoxes - used to manipulate hit boxes.
- AnimationFrame - used to manipulate a single frame.
- Animation - used to manipulate a single animation.
- Animations - used to manipulate animations.
- Project - used to manipulate a project.

## TextDocument

Enumerations

MoveOperation: {integer}

- NoMove
- Start
- StartOfLine
- StartOfWord
- PreviousLine
- PreviousCharacter
- PreviousWord
- End
- EndOfLine
- EndOfWord
- NextLine
- NextCharacter
- NextWord

MoveMode: {integer}

- MoveAnchor
- KeepAnchor

SelectionType: {integer}

- Document
- LineUnderCursor
- WordUnderCursor

Properties

- atLineStart {boolean}
- atLineEnd {boolean}
- atStart {boolean}
- atEnd {boolean}
- lineNumber {integer}
- columnNumber {integer}
- position {integer}
- selectedText {string}

Functions

- movePosition(op {MoveOperation}, mode {MoveMode}), n {integer})
  Moves the cursor position by n units based on the MoveOperation type. The MoveMode determines if the caret will be moved or keept to create a text selection.
- select(type {SelectionType})
  Creates a text selection based on the SelectionType.
- clearSelection()
  Cancel any text selection.
- removeSelectedText()
  Removes the selected text from the document.
- insertText(text {string})
  Inserts 'text' into the current cursor position. If the cursor has selection, the selected text will be replaced.
- sectionExists(section {string}) {boolean}
  Return if a section (or group) exists in the document.
- findValue(section {string}, param {string}) {string}
  Return the value of a section (or group) parameter. If it doesn't exists, returns an empty string.
- fromFile(fileName {string}, defaultCodec {integer}, asCopy {boolean}) {boolean}
  Load a document from 'fileName'.
- toFile(fileName {string}, saveUnicode {boolean}, asCopy {boolean}) {boolean}
  Saves the document to 'fileName'.

## SpritePalette

Enumerations

ShareMode: {integer}

- Share
- NoShare
- AskToShare

Properties

- index {integer}
- itemGroup {integer} read-write
- itemIndex {integer} read-write
- colorCount {integer} read-write
- colors {array_of_integer}

Functions

- setColors(colors {array_of_integer}, shareMode {ShareMode})
  Sets the colors of the palette.
- fromFile(fileName {string}) {boolean}
  Loads the palette from 'fileName'.
- toFile(fileName {string}) {boolean}
  Saves the palette to 'fileName'.

## Sprite

Enumerations

Flag: {integer}

- DecompressOnLoad

ImagePalette: {integer}

- Default
- Remapped

PaletteMode: {integer}

- Ignore
- OwnPalette
- AdaptImage
- SwapPalette

ShareMode: {integer}

- Share
- NoShare
- AskToShare

Properties

- index {integer}
- itemGroup {integer} read-write
- itemIndex {integer} read-write
- offsetX {integer} read-write
- offsetY {integer} read-write
- palette {SpritePalette} read-write
- imageIsShared {boolean}
- imageProperties {ImageInfo}

Functions

- flag(type {Flag}) {boolean}
  Returns if the specified flag is set.
- setFlag(type {Flag}, set {boolean})
  Sets the state of the specified flag.
- image(palette {ImagePalette}) {Image}
  Returns the sprite's image.
- setImage(image {Image}, shareMode {ShareMode}, reversed {boolean}, paletteMode {PaletteMode}, paletteItem {SubItem})
  Sets the sprite's palette with the given options.

## Sprites

Enumerations

Version: {integer}

- Version_101
- Version_200
- Version_201

Properties

- version {Version} read-write
- currentIndex {integer} read-write
- isModified {boolean}
- count {integer}
- paletteCount {integer}

Functions

- fromFile(fileName {string}, isChar {boolean}, asCopy {boolean}) {boolean}
  Load a .sff file from 'fileName'.
- toFile(fileName {string}, isChar {boolean}, version {Version}, useLZ {boolean}, asCopy {boolean}) {boolean}
  Saves a .sff file to 'fileName'.
- at(index {integer}) {Sprite}
  Returns the sprite at the given index.
- add() {Sprite}
  Adds a new sprite to the end and return the newly created sprite.
- insert(index {integer}) {Sprite}
  Inserts a new sprite to the given index and return the newly created sprite.
- remove(index {integer})
  Removes the sprite of the given index.
- clear()
  Removes all sprites.
- find(start {integer}, group {integer}, index {integer}) {integer}
  Finds the sprite with the given group and index. Returns -1 if not found or the index of the sprite.
- paletteAt(index {integer}) {SpritePalette}
  Returns the SpritePalette at the given index.
- addPalette(palette {array_of_integer}, onlyIfNotExists {boolean}, group {integer}, index {integer}) {SpritePalette}
  Adds a new palette to the end and return the newly created palette.
- insertPalette(pal_index {integer}, palette {array_of_integer}, onlyIfNotExists {boolean}, group {integer}, index {integer}) {SpritePalette}
  Inserts a new Palette to the given index and return the newly created palette.
- removePalette(index {integer})
  Removes the palette at the given index.
- removeDuplicatePalettes()
  Removes all duplicate palettes.
- clearPalettes()
  Removes all palettes.
- clearUnusedPalettes()
  Removes all unused (unreferenced) palettes.
- findPalette(start {integer}, group {integer}, index {integer}) {integer}
  Finds the palette with the given group and index. Returns -1 if not found or the index of the palette.

## HitBox

Properties

- parent {HitBoxes}
- index {integer}
- rect {Rect} read-write

## HitBoxes

Enumerations

Type: {integer}

- Attack
- Collision
- AttackDefault
- CollisionDefault

Properties

- parent {AnimationFrame}
- type {Type}
- count {integer}

Functions

- at(index {integer}) {HitBox}
  Returns the hit box at the given index.
- insert(rect {Rect}) {HitBox}
  Adds a new hit box and returns the newly created one.
- clear()
  Removes all hit boxes.

## AnimationFrame

Enumerations

InterFrame: {integer}

- LoopStart
- InterpolateBlend
- InterpolateOffset
- InterpolateScale
- InterpolateAngle

Flip: {integer}

- Horizontal
- Vertical
- Both

Blend: {integer}

- None
- Addition
- Subtraction

Properties

- parent {Animation}
- index {integer}
- spriteGroup {integer} read-write
- spriteIndex {integer} read-write
- offsetX {integer} read-write
- offsetY {integer} read-write
- time {integer} read-write
- flip {Flip} read-write
- scaleX {float} read-write
- scaleY {float} read-write
- angle {float} read-write
- blend {Blend} read-write
- blendTarget {BlendTarget}

Functions

- setBlend(blend {Blend}, target {BlendTarget})
  Sets the frame's blend mode.
- checkInterFrame(type {InterFrame}) {boolean}
  Returns if the given inter-frame type is set.
- setInterFrame(type {InterFrame}, set {boolean})
  Sets the given inter-frame type to the desired state.
- hitBoxes(type {HitBoxes.Type}) {HitBoxes}
  Returns the hit box list for the given type, if exists.
- insertBox(type {HitBoxes.Type}, rect {Rect}) {HitBox}
  Inserts a new hit box of the given type / rect, and returns the newly created one.

## Animation

Properties

- number {integer} read-write
- name {string} read-write
- frameCount {integer}

Functions

- frameAt(index {integer}) {AnimationFrame}
  Returns the frame at the given index.
- frameAdd() {AnimationFrame}
  Adds a new frame to the end and return the newly created one.
- frameInsert(index {integer}) {AnimationFrame}
  Inserts a new frame to the given index and return the newly created one.

## Animations

Properties

- currentIndex {integer} read-write
- currentFrameIndex {integer} read-write
- isModified {boolean}
- count {integer}

Functions

- fromFile(fileName {string}) {boolean}
  Load a .air file from 'fileName'.
- toFile(fileName {string}) {boolean}
  Saves a .air file to 'fileName'.
- at(index {integer}) {Animation}
  Returns the animation at the given index.
- add() {Animation}
  Adds a new animation to the end and return the newly created one.
- insert(index {integer}) {Animation}
  Inserts a new animation to the given index and return the newly created one.
- remove(index {integer})
  Removes the animation of the given index.
- clear()
  Removes all animations.
- duplicate(index {integer}, newNumber {integer})
  Creates a copy of the animation at the given index using a new number.
- move(source {integer}, destination {integer})
  Moves an animation from source index to the destination index.
- find(start {integer}, text {string}) {integer}
  Finds the animation with the given name or number. Returns -1 if not found or the index of the animation.

## Project

Enumerations

Type: {integer}

- Character
- Stage
- Font
- Storyboard

Properties

- version {Version}
- localCoord {Point}
- type {Type} read-write
- definitions {TextDocument}
- sprites {Sprites}
- animations {Animations}
- commands {TextDocument}
- statesCount {integer}

Functions

- states(index {integer}) {TextDocument}
  Returns the states document at the given index.
- fromFile(fileName {string}, defaultCodec {integer}, backup {boolean}, asCopy {boolean}) {boolean}
  Load a .def file from 'fileName' using the 'defaultCodec' as text encoding, and all other related files defined in it. If true, 'backup' will force the creation of a backup prior to loading any file. 'asCopy' determines if the 'fileName' will be recorded internally.
- toFile(fileName {string}, useUnicode {boolean})
  Saves a .def file to 'fileName' and all other opened project files. If true, 'useUnicode' will force the UTF-8 encoding in all text files to be saved.