fText plugin
Options
All
  • Public
  • Public/Protected
  • All
Menu

Superpowers fText asset plugin

This plugin brings a generic text asset of type fText to Superpowers, the extensible HTML5 2D+3D game engine.

Go back to the repository on Github.

Creating a new asset

When creating a new asset in Superpowers' client, select the fText type.

Editor features and settings

You can configure the editor through the Settings tool :

Setting Action / Effect
Theme Define the editor's looks.
See below for using a custom theme.
Tab Size This define the width (in spaces equivalent) of a tab.
Updating the value will update all existing tab characters (and not tabs that use spaces) in you text assets.
Indent with tabs Tell whether pressing the Tab key should insert an actual tab character or regular spaces.
Key map Define the basic set of keyboard shortcuts and commands.
Auto close brackets Automatically add the closing character when writing the following characters { ( [ " '
Highlight - active line: Makes the current line stand out.
- trailing spaces: in red.
- matching tags: in languages that have pairs of tags -like HTML- having the mouse cursor over one will highlight the other one.
Pressing Ctrl/Cmd+J will jump to the matching tag.
- matching words: when a word is selected, this highlight all other occurrences in the document.
Lint syntaxes Enable/disable linting of the following syntaxes :
json, javascript, cson, yaml, jade, stylus, css.

Using a custom theme

Copy one of the themes you can find the the plugin's public/editors/fText/codemirror-themes folder.

Edit the file name and the theme name inside the CSS classes, as well as all values to you likings.

In the editor settings, add the theme's name in the custom theme input field then select Custom at the top of the list in the select field.

Syntax

The syntax of the asset defines the data-type of its content and thus change how the syntactic coloration behave and how the asset's content is parsed and linted, if at all.

To set a syntax, just add an extension at the end of the asset's name just like for any standard file.
Ie: "styles/main.styl".

Supported extensions (and syntaxes) are : json, js (javascript), cson, yml (Yaml), md (Markdown), html, jade, css, styl (stylus), xml and shader.

Other features

  • Code folding
  • Basic autocompletion via the Ctrl/Cmd + Space command.
  • json supports standard // comments

Includes

You can include a text asset's content into another with the include instruction.
Just write in your asset :

[ftext: include: path/to/the/asset]

Replace path/to/the/asset by the path to the asset to include inside this one.

The specified asset content will then be included when the asset is parsed with the fText.parse() method.

Since assets are usually parsed before the inclusion is performed, it is best to have comment characters immediately before the command.

//[ftext: include: path/to/the/asset]

In-game usage

fText is the type of the text assets inside your game's code. Get an asset like this:

let asset = Sup.get( "My Text Asset", fText );
// or
let asset = <fText>Sup.get( "My Text Asset" );

You can access the raw text content of the asset via the readonly property text :

let asset = Sup.get( "My Text Asset", fText );
let data = asset.text;

You can parse the asset's content with the parse() method as well as access all parsers through the static property fText.parsers :

Ie:

let asset = Sup.get( "My Jade Asset", fText );

let html = asset.parse();

let elt = fText.parsers.domify( html );

document.body.appendChild( elt ); 
// note that document is not accessible inside your game's code
// without the DOM plugin you can find at:
// https://github.com/florentpoujol/superpowers-dom-plugin
  • json, cson and yml are parsed to JS object.
  • jade and md > HTML string
  • html > DOM object
  • styl > CSS string

Index

Classes

Classes

fText

fText:

constructor

  • new fText(inner: object): fText
  • Parameters

    • inner: object

      The asset's pub as defined in the asset's class.

      • [key: string]: any

    Returns fText

___inner

___inner: any

children

children: Array<string>

instructions

instructions: object

The set of instructions which can be found in the asset's content.

Type declaration

  • [key: string]: string | string[]

name

name: string

syntax

syntax: string

The asset's syntax, defined by the extension (if any) found at the end of its name.

type

type: string

parsers

parsers: object

Type declaration

  • csonparser: any
  • domify: function
      • (text: string): any
      • Parameters

        • text: string

        Returns any

  • jade: any
  • jsonlint: any
  • jsyaml: any
  • markdown: any
  • stylus: any

text

text:
readonly

The raw content of the asset.

_parseInstructions

  • _parseInstructions(): void
  • Read the [ftext: instruction: value] instructions in the asset's text then build the this.instructions object. Called once from the constructor

    Returns void

parse

  • parse(options?: object): any
  • Returns the content of the asset, after having parsed and processed it

    Parameters

    • Optional options: object

      An object with options.

      • Optional include?: boolean

    Returns any

    JavaScript or DOM object, or string.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc