3.3.3 • Published 12 months ago

react-native-runescape-text v3.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

react-native-runescape-text

npm version npm downloads npm licence Platform

Discord Twitter Follow

Convert text to a text GIF image with RuneScape chat effects.

Refer to this wikiHow guide on How to Write Text Effects on RuneScape.

Getting started

npm install react-native-runescape-text

Examples

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, TouchableOpacity, View} from 'react-native';
import {GCanvasView} from '@flyskywhy/react-native-gcanvas';
import getRuneScapeText from 'react-native-runescape-text';

export default class WebglCubeMaps extends Component {
  constructor(props) {
    super(props);
    this.canvas = null;
    this.state = {
      debugInfo: 'hello world',
      hasOc1: false,
    };
  }

  takePicture = () => {
    const options = {
      scale: 1,
      fps: 10,
      motion: 'scroll',
    };
    const {width, height, extension, buffer} = getRuneScapeText(this.state.debugInfo, options);

    console.warn(width, height, extension);
    console.warn(buffer);
  };

  render() {
    return (
      <View style={styles.container}>
        {Platform.OS !== 'web' && (
          <GCanvasView
            style={{
              width: 1000, // 1000 should enough for offscreen canvas usage
              height: 1000,
              position: 'absolute',
              left: 1000, // 1000 should enough to not display on screen means offscreen canvas :P
              top: 0,
              zIndex: -100, // -100 should enough to not bother onscreen canvas
            }}
            offscreenCanvas={true}
            onCanvasCreate={(canvas) => this.setState({hasOc1: true})}
            devicePixelRatio={1} // should not 1 < devicePixelRatio < 2 as float to avoid pixel offset flaw when GetImageData with PixelsSampler in @flyskywhy/react-native-gcanvas/core/src/support/GLUtil.cpp
            isGestureResponsible={false}
          />
        )}
        {Platform.OS === 'web' || this.state.hasOc1 && (
          <TouchableOpacity onPress={this.takePicture}>
            <Text style={styles.welcome}>Click me console.warn()</Text>
          </TouchableOpacity>
        )}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    marginVertical: 20,
  },
});

Syntax

getRuneScapeText(string, [options], [wordWrapOptions]);

Parameters

ParameterTypeRequiredDefaultDescription
stringstringYesnoneText to convert
optionsObjectNo{}Options to configure script behavior
wordWrapOptionsObjectNo{}Options to configure word-wrap behavior

Options

PropertyTypeRequiredDefaultDescription
versionstringNo"osrs"Game version to use, either: osrs or rs3
colorstringNo"yellow"Default color effect of the text, either: yellow, red, green, cyan, purple, white, glow1, glow2, glow3, flash1, flash2, flash3, or any other color format in tinycolor2
motionstringNo"none"Default motion effect of the text, either: none, wave, wave2, shake, scroll, or slide
widthnumberNo0Image width want to clip on center, 0 means no clip and width of Return value depend on string text length
heightnumberNo0Image height want to clip on center, 0 means no clip and height of Return value depend on font height
suffixstringNo":"String that should suffix each color and motion string
replacementstringNo""String to replace characters the font does not support when supportNonAscii is false
supportNonAsciibooleanNotrueDetermines whether the text support Non-ASCII characters like Chinese
trimStartbooleanNofalseDetermines whether the text will be trimStart()
maxMessageLengthnumberNo280Max message length allowed after the string has been sanitized
scalenumberNo2Scale factor of the font (multiples of 16px), prefer integer values greater than or equal to 1, decimal values will render blurry text
fontstringNorunescape_uffont name
fpsnumberNo20Frames per second to render animations at, prefer integer values less than or equal to 60
cycleDurationnumberNo3000Duration in milliseconds of one cycle before the animation loops
imageSmoothingEnabledbooleanNotrueDetermines whether to linear filter the text image
imageGradientEnabledbooleanNotrueDetermines whether to let the color in text image be gradient, if false, it's better also set imageSmoothingEnabled be false
gradientThresholdnumberNo100When imageGradientEnabled is false, if pixel's a > gradientThreshold, a will be modified to 255, otherwise rgba will be modified to 00000000
showLogsbooleanNofalseDetermines whether to print runtime logs or not
returnBufferTypestringNoBufferDetermines return buffer type, either: Buffer, Array or ArrayOfImageData

WordWrapOptions

Property information can be found here. The defaults chosen by this module are listed below:

PropertyDefault
width50
indent""
newline"\n"
escape(str) => str.trimEnd()
trimfalse
cutfalse

Return value

The return value is an Object with the following properties:

PropertyTypeDescription
widthnumberImage width
heightnumberImage height
framesLengthnumberGIF frames length
extensionstringFile extension gif
buffer<Buffer>, <Array> or ArrayOfImageDataresult in a buffer or array of a GIF image, or an array contains many ImageData

Install custom Font

Ref to custom fonts in README.md of @flyskywhy/react-native-gcanvas to install custom fonts and registerFont() if on Android, e.g. install from src/assets/runescape_uf.ttf and

if (Platform.OS === 'android') {
  registerFont(`${RNFS.ExternalDirectoryPath}/fonts/runescape_uf.ttf`);
}

then options.font = 'runescape_uf' before run getRuneScapeText().

Consider react-native-font-picker, and here is the result of Font Picker to fillText on @flyskywhy/react-native-gcanvas.

Exceptions

ErrorDescription
InvalidArgumentErrorThrown if required string argument is missing
TypeErrorThrown if argument type is unexpected
ValueErrorThrown if string is empty
ValueErrorThrown if the parsed message string is empty
3.3.3

12 months ago

3.3.2

12 months ago

3.3.1

1 year ago

3.3.0

1 year ago

3.2.0

1 year ago

3.1.0

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago