Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- 💬📐
- @file textbox customizer
- @summary
- @license MIT
- @version 1.0.0
- @requires Bitsy Version: 6.1
- @author Dana Holdampf
- @description
- This hack lets you edit the appearance, position, and other properties of the textbox.
- It lets you draw a border made of sprites, replace the continue arrow, etc.
- TODO: WRITE A MORE THOROUGH DESCRIPTION
- HOW TO USE:
- 1. Copy-paste this script into a script tag after the bitsy source
- 2. Edit hackOptions below, as needed
- TODO: WRITE A HOW-TO
- Colors are defined as 4 values, [red,green,blue,alpha], each ranging from 0-255.
- Alpha is opacity; colors can be translucent by reducing Alpha below 255. 0 is fully transparent.
- NIGHT NOTE: Maybe recalculate center position, considering textbox margins in center calculation?
- */
- this.hacks = this.hacks || {};
- (function (exports, bitsy) {
- 'use strict';
- var hackOptions = {
- // Determines where the textbox is positioned. "shift" moves the textbox based on the player's position.
- verticalPosition: "shift", // options are "top", "center", "bottom", or "shift" (moves based on player position)
- horizontalPosition: "center", // options are "left", "center", "right", or "shift" (moves based on player position)
- textboxColor: [0,0,0,255], // Colors text and textbox are drawn, in [R,G,B,A]
- textboxWidth: 124, // Width of textbox in pixels. Default 104.
- textboxMarginX: 4, // Pixels of space outside the left (or right) of the textbox. Default 12.
- textboxMarginY: 4, // Pixels of space outside the top (or bottom) of the textbox. Default 12.
- textColor: [255,255,255,255], // Default color of text.
- textMinLines: 1, // Minimum number of rows for text. Determines starting textbox height. Default 2.
- textMaxLines: 2, // Maximum number of rows for text. Determines max textbox height. Default 2.
- textScale: 2, // Scaling factor for text. Default 2.
- textSpeed: 50, // Time to print each character, in milliseconds. Default 50.
- textPaddingX: 0, // Default color of text.
- textPaddingY: 2, // Default color of text.
- // Colors the borders are drawn using, in [R,G,B,A]
- borderColor: [128,128,128,255],
- borderBGColor: [0,0,0,255],
- borderMidColor: [51,51,51,255], // Color used for middle border
- // Border is drawn past the edges of the textbox.
- borderWidth: 8, // Width of border sprites, in pixels. Default 8.
- borderHeight: 8, // Height of border sprites, in pixels. Default 8.
- borderScale: 2, // Scaling factor for border sprites. Default 2.
- // Color the continue arrow is drawn using, in [R,G,B,A]
- arrowColor: [255,255,255,255],
- arrowBGColor: [0,0,0,255],
- arrowScale: 2, // Scaling factor for arrow sprite. Default 2.
- // Position of textbox continue arrow, on bottom of textbox. Uncomment one.
- arrowAlign: "right", // Options are: "right", "center", or "left" aligned
- // Pixels of padding the arrow is inset from the edge by
- arrowInsetX: 12,
- arrowInsetY: 0,
- // Arrow Sprite. 1 draws a pixel in main Color, 0 draws in BG Color.
- arrowWidth: 8, // Width of arrow sprite below, in pixels
- arrowHeight: 5, // Height of arrow sprite below, in pixels
- arrowSprite: [
- 1,1,1,1,1,1,1,1,
- 0,1,1,1,1,1,1,0,
- 0,0,1,1,1,1,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,0,0,0,0,0,0
- ],
- borderUL: [
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,1,1,1,1,1,1,
- 0,0,1,1,1,1,1,1,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- ],
- borderU: [
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- ],
- borderUR: [
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 1,1,1,1,1,1,0,0,
- 1,1,1,1,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- ],
- borderL: [
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- ],
- borderR: [
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- ],
- borderDL: [
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,0,0,0,0,
- 0,0,1,1,1,1,1,1,
- 0,0,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- ],
- borderD: [
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- ],
- borderDR: [
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 0,0,0,0,1,1,0,0,
- 1,1,1,1,1,1,0,0,
- 1,1,1,1,1,1,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- ],
- borderM: [
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- ],
- // You can define alternate Dialog Styles here, which can override the default style above.
- // You can switch styles from dialog with the {dialogStyle "styleName"} command.
- initialDialogStyle: "none", // Initial Dialog Style used on load. Can be changed to any dialog style defined below.
- // These Dialog Styles are meant as examples. Feel free to edit, rename, or remove them.
- dialogStyle: {
- custom: {
- // Copy any hackOptions from above into this section, and modify them, to create a new style.
- // Any options you redefine here will override the default style, while this style is active.
- },
- // An example style, which emulates the original Bitsy textbox.
- vanilla: {
- verticalPosition: "shift",
- horizontalPosition: "center",
- textboxWidth: 104,
- textboxMarginX: 12,
- textboxMarginY: 12,
- textMinLines: 2,
- textMaxLines: 2,
- textPaddingX: 8,
- textPaddingY: 8,
- borderWidth: 0,
- borderHeight: 0,
- arrowScale: 4,
- arrowInsetX: 12,
- arrowInsetY: 0,
- arrowWidth: 5,
- arrowHeight: 3,
- arrowSprite: [
- 1,1,1,1,1,
- 0,1,1,1,0,
- 0,0,1,0,0,
- ],
- },
- // An example style, drawn with a transparent background.
- transparent: {
- textboxColor: [255,255,255,0],
- borderBGColor: [255,255,255,0],
- arrowBGColor: [255,255,255,0],
- },
- // An example style, that centers the textbox as with Starting or Ending text.
- centered: {
- verticalPosition: "center",
- horizontalPosition: "center",
- },
- // An example style, that positions the textbox vertically, on the left or right side.
- vertical: {
- verticalPosition: "center",
- horizontalPosition: "shift",
- textboxWidth: 32,
- textMinLines: 16,
- textMaxLines: 16,
- },
- // An example style, which positions a resizing textbox in the corner opposite the player.
- corner: {
- verticalPosition: "shift",
- horizontalPosition: "shift",
- textboxWidth: 64,
- textMinLines: 1,
- textMaxLines: 8,
- },
- // An example style, which inverts the normal textbox colors
- inverted: {
- textboxColor: [255,255,255,255],
- textColor: [0,0,0,255],
- borderColor: [128,128,128,255],
- borderBGColor: [255,255,255,255],
- borderMidColor: [204,204,204,255],
- arrowColor: [0,0,0,255],
- arrowBGColor: [255,255,255,255],
- },
- smallBorder: {
- borderWidth: 4,
- borderHeight: 4,
- borderUL: [
- 0,0,0,0,
- 0,1,1,1,
- 0,1,0,1,
- 0,1,1,1,
- ],
- borderU: [
- 0,0,0,0,
- 1,1,1,1,
- 0,0,0,0,
- 0,0,0,0,
- ],
- borderUR: [
- 0,0,0,0,
- 1,1,1,0,
- 1,0,1,0,
- 1,1,1,0,
- ],
- borderL: [
- 0,1,0,0,
- 0,1,0,0,
- 0,1,0,0,
- 0,1,0,0,
- ],
- borderR: [
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- ],
- borderDL: [
- 0,1,1,1,
- 0,1,0,1,
- 0,1,1,1,
- 0,0,0,0,
- ],
- borderD: [
- 0,0,0,0,
- 0,0,0,0,
- 1,1,1,1,
- 0,0,0,0,
- ],
- borderDR: [
- 1,1,1,0,
- 1,0,1,0,
- 1,1,1,0,
- 0,0,0,0,
- ],
- borderM: [
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- ],
- },
- },
- };
- bitsy = bitsy && bitsy.hasOwnProperty('default') ? bitsy['default'] : bitsy;
- /**
- @file utils
- @summary miscellaneous bitsy utilities
- @author Sean S. LeBlanc
- */
- /*
- Helper used to replace code in a script tag based on a search regex
- To inject code without erasing original string, using capturing groups; e.g.
- inject(/(some string)/,'injected before $1 injected after')
- */
- function inject(searchRegex, replaceString) {
- // find the relevant script tag
- var scriptTags = document.getElementsByTagName('script');
- var scriptTag;
- var code;
- for (var i = 0; i < scriptTags.length; ++i) {
- scriptTag = scriptTags[i];
- var matchesSearch = scriptTag.textContent.search(searchRegex) !== -1;
- var isCurrentScript = scriptTag === document.currentScript;
- if (matchesSearch && !isCurrentScript) {
- code = scriptTag.textContent;
- break;
- }
- }
- // error-handling
- if (!code) {
- throw 'Couldn\'t find "' + searchRegex + '" in script tags';
- }
- // modify the content
- code = code.replace(searchRegex, replaceString);
- // replace the old script tag with a new one using our modified code
- var newScriptTag = document.createElement('script');
- newScriptTag.textContent = code;
- scriptTag.insertAdjacentElement('afterend', newScriptTag);
- scriptTag.remove();
- }
- /**
- * Helper for getting an array with unique elements
- * @param {Array} array Original array
- * @return {Array} Copy of array, excluding duplicates
- */
- function unique(array) {
- return array.filter(function (item, idx) {
- return array.indexOf(item) === idx;
- });
- }
- /**
- @file kitsy-script-toolkit
- @summary makes it easier and cleaner to run code before and after Bitsy functions or to inject new code into Bitsy script tags
- @license WTFPL (do WTF you want)
- @version 4.0.1
- @requires Bitsy Version: 4.5, 4.6
- @author @mildmojo
- @description
- HOW TO USE:
- import {before, after, inject, addDialogTag, addDeferredDialogTag} from "./helpers/kitsy-script-toolkit";
- before(targetFuncName, beforeFn);
- after(targetFuncName, afterFn);
- inject(searchRegex, replaceString);
- addDialogTag(tagName, dialogFn);
- addDeferredDialogTag(tagName, dialogFn);
- For more info, see the documentation at:
- https://github.com/seleb/bitsy-hacks/wiki/Coding-with-kitsy
- */
- // Ex: inject(/(names.sprite.set\( name, id \);)/, '$1console.dir(names)');
- function inject$1(searchRegex, replaceString) {
- var kitsy = kitsyInit();
- kitsy.queuedInjectScripts.push({
- searchRegex: searchRegex,
- replaceString: replaceString
- });
- }
- function kitsyInit() {
- // return already-initialized kitsy
- if (bitsy.kitsy) {
- return bitsy.kitsy;
- }
- // Initialize kitsy
- bitsy.kitsy = {
- queuedInjectScripts: [],
- queuedBeforeScripts: {},
- queuedAfterScripts: {}
- };
- var oldStartFunc = bitsy.startExportedGame;
- bitsy.startExportedGame = function doAllInjections() {
- // Only do this once.
- bitsy.startExportedGame = oldStartFunc;
- // Rewrite scripts and hook everything up.
- doInjects();
- applyAllHooks();
- // Start the game
- bitsy.startExportedGame.apply(this, arguments);
- };
- return bitsy.kitsy;
- }
- function doInjects() {
- bitsy.kitsy.queuedInjectScripts.forEach(function (injectScript) {
- inject(injectScript.searchRegex, injectScript.replaceString);
- });
- _reinitEngine();
- }
- function applyAllHooks() {
- var allHooks = unique(Object.keys(bitsy.kitsy.queuedBeforeScripts).concat(Object.keys(bitsy.kitsy.queuedAfterScripts)));
- allHooks.forEach(applyHook);
- }
- function applyHook(functionName) {
- var functionNameSegments = functionName.split('.');
- var obj = bitsy;
- while (functionNameSegments.length > 1) {
- obj = obj[functionNameSegments.shift()];
- }
- var lastSegment = functionNameSegments[0];
- var superFn = obj[lastSegment];
- var superFnLength = superFn ? superFn.length : 0;
- var functions = [];
- // start with befores
- functions = functions.concat(bitsy.kitsy.queuedBeforeScripts[functionName] || []);
- // then original
- if (superFn) {
- functions.push(superFn);
- }
- // then afters
- functions = functions.concat(bitsy.kitsy.queuedAfterScripts[functionName] || []);
- // overwrite original with one which will call each in order
- obj[lastSegment] = function () {
- var returnVal;
- var args = [].slice.call(arguments);
- var i = 0;
- function runBefore() {
- // All outta functions? Finish
- if (i === functions.length) {
- return returnVal;
- }
- // Update args if provided.
- if (arguments.length > 0) {
- args = [].slice.call(arguments);
- }
- if (functions[i].length > superFnLength) {
- // Assume funcs that accept more args than the original are
- // async and accept a callback as an additional argument.
- return functions[i++].apply(this, args.concat(runBefore.bind(this)));
- } else {
- // run synchronously
- returnVal = functions[i++].apply(this, args);
- if (returnVal && returnVal.length) {
- args = returnVal;
- }
- return runBefore.apply(this, args);
- }
- }
- return runBefore.apply(this, arguments);
- };
- }
- function _reinitEngine() {
- // recreate the script and dialog objects so that they'll be
- // referencing the code with injections instead of the original
- bitsy.scriptModule = new bitsy.Script();
- bitsy.scriptInterpreter = bitsy.scriptModule.CreateInterpreter();
- bitsy.dialogModule = new bitsy.Dialog();
- bitsy.dialogRenderer = bitsy.dialogModule.CreateRenderer();
- bitsy.dialogBuffer = bitsy.dialogModule.CreateBuffer();
- }
- // =============================================================
- // | RE-IMPLIMENTED LONG DIALOG HACK INJECTS |/////////////////|
- // =============================================================
- // Modified from Sean leBlanc's Long Dialog hack, to include textbox borders and padding
- // Needed to recalculate textbox height, based on current style parameters.
- // Added textMinLines and textMaxLines to hackOptions parameters, to include in style swapping
- // OLD RETURN VALUE FOR REF: textboxInfo.padding_vert + (textboxInfo.padding_vert + relativeFontHeight()) * Math.max(${hackOptions.minRows}, dialogBuffer.CurPage().indexOf(dialogBuffer.CurRow())+Math.sign(dialogBuffer.CurCharCount())) + textboxInfo.arrow_height; }
- // override textbox height (and recalculate textboxWidth)
- inject$1(/textboxInfo\.height = .+;/, `Object.defineProperty(textboxInfo, 'height', {
- get() { return 2 + textPaddingY + borderHeight + (relativeFontHeight() * Math.max(${textMinLines}, dialogBuffer.CurPage().indexOf(dialogBuffer.CurRow())+Math.sign(dialogBuffer.CurCharCount()))); }
- })`);
- // prevent textbox from caching
- inject$1(/(if\(textboxInfo\.img == null\))/, '// $1');
- // rewrite hard-coded row limit
- inject$1(/(else if \(curRowIndex )== 0/g, '$1< ' + textMaxLines + ' - 1');
- inject$1(/(if\( lastPage\.length) <= 1( \) {)/, '$1 < ' + textMaxLines + ' $2');
- // Add dynamic recalculation of textbox width? may need to be added after textboxInfo.height inject?
- //inject(/textboxInfo\.width = .+;/, `Object.defineProperty(textboxInfo, 'width', {
- // get() { return textboxWidth; }
- //})`);
- // ==========================================================================================================================
- // NIGHT NOTES: So... there's scope problems of some sort? Something to do with modules, I think.
- //
- // The Dialog function can't access hackOptions, or the functions defined in the hack.
- // It's in a virtual machine or something and can't access functions/variables?
- // I probably need to inject scripts for the entire function into the Dialog hack (unless there's a way to give it access)?
- // Keep an eye out for buggy regex; specifically check the lazy line-break-inclusive wildcards, and escaped characters.
- // Hack worked fine, but haven't gotten to test injected version of the hack yet, due to the scope issue.
- //
- // Once the scope issue is resolved, there's a chance hack functionality was borked or half-implemented.
- // Keep an eye out!
- //
- // Later, test style swapping after runtime, to make sure all the parameters get updated.
- // Some of the parameters might not get updated.
- // ==========================================================================================================================
- // =============================================================
- // | HACK SCRIPT INJECTS |/////////////////////////////////////|
- // =============================================================
- // Injects textbox style variables at top of Dialog function
- var dialogInject = `function Dialog() {
- console.log ("Injected Dialog Function has been called");
- var verticalPosition = hackOptions.verticalPosition;
- var horizontalPosition = hackOptions.horizontalPosition;
- var textboxColor = hackOptions.textboxColor;
- var textboxWidth = hackOptions.textboxWidth;
- var textboxHeight = hackOptions.textboxHeight;
- var textboxMarginX = hackOptions.textboxMarginX;
- var textboxMarginY = hackOptions.textboxMarginY;
- var textColor = hackOptions.textColor;
- var textMinLines = hackOptions.textMinLines;
- var textMaxLines = hackOptions.textMaxLines;
- var textScale = hackOptions.textScale;
- var textSpeed = hackOptions.textSpeed;
- var textPaddingX = hackOptions.textPaddingX;
- var textPaddingY = hackOptions.textPaddingY;
- var borderColor = hackOptions.borderColor;
- var borderBGColor = hackOptions.borderBGColor;
- var borderMidColor = hackOptions.borderMidColor;
- var borderWidth = hackOptions.borderWidth;
- var borderHeight = hackOptions.borderHeight;
- var borderScale = hackOptions.borderScale;
- var arrowColor = hackOptions.arrowColor;
- var arrowBGColor = hackOptions.arrowBGColor;
- var arrowScale = hackOptions.arrowScale;
- var arrowAlign = hackOptions.arrowAlign;
- var arrowInsetX = hackOptions.arrowInsetX;
- var arrowInsetY = hackOptions.arrowInsetY;
- var arrowWidth = hackOptions.arrowWidth;
- var arrowHeight = hackOptions.arrowHeight;
- var arrowSprite = hackOptions.arrowSprite;
- var borderUL = hackOptions.borderUL;
- var borderU = hackOptions.borderU;
- var borderUR = hackOptions.borderUR;
- var borderL = hackOptions.borderL;
- var borderR = hackOptions.borderR;
- var borderDL = hackOptions.borderDL;
- var borderD = hackOptions.borderD;
- var borderDR = hackOptions.borderDR;
- var borderM = hackOptions.borderM;
- `;
- inject$1(/function Dialog\(\) {/, dialogInject);
- // Replaces initial textbox parameters, based on currently active style (or defaults).
- // Recalculates textbox parameters, even values no longer used with hack, for compatability.
- var textboxInfoReplace = `setTextboxStyle(hackOptions.initialDialogStyle);
- var textboxInfo = {
- img : null,
- width : textboxWidth,
- height : (textPaddingY + borderHeight + 2),
- top : textboxMarginY,
- left : textboxMarginX,
- bottom : textboxMarginY,
- font_scale : 0.5, //hackOptions.textScale/4;
- padding_vert : 2,
- padding_horz : 4,
- arrow_height : (textPaddingY + borderHeight - 4),
- };`;
- inject$1(/var textboxInfo = .+?};/s, textboxInfoReplace);
- // Replaces ClearTextbox function to include border-drawing scripts
- var clearTextboxReplace = `this.ClearTextbox = function() {
- if(context == null) return;
- //create new image none exists
- if(textboxInfo.img == null)
- textboxInfo.img = context.createImageData(textboxInfo.width*scale, textboxInfo.height*scale);
- // Draw Textbox Background based on BGColor (indices are R,G,B, and A)
- for (var i=0;i<textboxInfo.img.data.length;i+=4)
- {
- textboxInfo.img.data[i+0]=textboxColor[0];
- textboxInfo.img.data[i+1]=textboxColor[1];
- textboxInfo.img.data[i+2]=textboxColor[2];
- textboxInfo.img.data[i+3]=textboxColor[3];
- }
- drawTextboxBorder();
- };`;
- inject$1(/this.ClearTextbox = .+?};/s, clearTextboxReplace);
- // Replaces Draw Textbox function, with function that supports vertical and horizontal shifting
- var drawTextboxReplace = `this.DrawTextbox = function() {
- if(context == null) return;
- // Textbox defaults to center-aligned
- var textboxXPosition = ((width/2)-(textboxInfo.width/2))*scale;
- var textboxYPosition = ((height/2)-(textboxInfo.height/2))*scale;
- if (isCentered) {
- context.putImageData(textboxInfo.img, textboxXPosition, textboxYPosition);
- }
- else {
- if (verticalPosition.toLowerCase() = "shift") {
- if (player().y < mapsize/2) {
- //player on bottom half, so draw on top
- textboxYPosition = ((height-textboxInfo.top-textboxInfo.height)*scale);
- }
- else {
- textboxYPosition = textboxInfo.top*scale
- }
- }
- else if (verticalPosition.toLowerCase() = "top") {
- textboxYPosition = ((height-textboxInfo.top-textboxInfo.height)*scale);
- }
- else if (verticalPosition.toLowerCase() = "bottom") {
- textboxYPosition = textboxInfo.top*scale
- }
- if (horizontalPosition.toLowerCase() = "shift") {
- if (player().x < mapsize/2) {
- // player on left half, so draw on right
- textboxXPosition = ((width-textboxInfo.left-textboxInfo.width)*scale);
- }
- else {
- textboxXPosition = textboxInfo.left*scale
- }
- }
- else if (horizontalPosition.toLowerCase() = "right") {
- textboxXPosition = ((width-textboxInfo.left-textboxInfo.width)*scale);
- }
- else if (horizontalPosition.toLowerCase() = "left") {
- textboxXPosition = textboxInfo.left*scale
- }
- // Draw the Textbox
- context.putImageData(textboxInfo.img, textboxXPosition, textboxYPosition);
- }
- };`;
- inject$1(/this.DrawTextbox = .+?};/s, drawTextboxReplace);
- // Replace DrawNextArrow function, to support custom sprites, colors, and arrow repositioning
- var drawNextArrowReplace = `this.DrawNextArrow = function() {
- // Arrow sprite is center-bottom by default
- var top = ((4/arrowScale)*textboxInfo.height - arrowHeight - arrowInsetY) * arrowScale;
- var left = ((4/textboxArrowScale)*textboxInfo.width - arrowXSize) * textboxArrowScale*0.5;
- // Reposition arrow based on arrowAlign and RTL settings (flipped for RTL Languages)
- if (arrowAlign.toLowerCase() == "left") {
- if (textDirection === TextDirection.RightToLeft) {
- left = ((4/arrowScale)*textboxInfo.width - arrowWidth - arrowInsetX) * arrowScale;
- }
- else {
- left = (arrowXPadding) * textboxArrowScale;
- }
- }
- else if (arrowAlign.toLowerCase() == "right") {
- if (textDirection === TextDirection.RightToLeft) {
- left = (arrowXPadding) * textboxArrowScale;
- }
- else {
- left = ((4/arrowScale)*textboxInfo.width - arrowWidth - arrowInsetX) * arrowScale;
- }
- }
- // Draw arrow sprite pixels on textbox
- for (var y = 0; y < arrowHeight; y++) {
- for (var x = 0; x < arrowWidth; x++) {
- var i = (y * arrowWidth) + x;
- //scaling hooplah
- for (var sy = 0; sy < arrowScale; sy++) {
- for (var sx = 0; sx < arrowScale; sx++) {
- var pxl = 4 * ( ((top+(y*arrowScale)+sy) * (textboxInfo.width*4)) + (left+(x*arrowScale)+sx) );
- // Draws arrow's pixels in Arrow Color
- if (arrowSprite[i] == 1) {
- textboxInfo.img.data[pxl+0] = arrowColor[0];
- textboxInfo.img.data[pxl+1] = arrowColor[1];
- textboxInfo.img.data[pxl+2] = arrowColor[2];
- textboxInfo.img.data[pxl+3] = arrowColor[3];
- }
- // Draws arrow's bg pixels using Arrow BG Color
- else {
- textboxInfo.img.data[pxl+0] = arrowBGColor[0];
- textboxInfo.img.data[pxl+1] = arrowBGColor[1];
- textboxInfo.img.data[pxl+2] = arrowBGColor[2];
- textboxInfo.img.data[pxl+3] = arrowBGColor[3];
- }
- }
- }
- }
- }
- };`;
- inject$1(/this.DrawNextArrow = .+?};/s, drawNextArrowReplace);
- // Inject to support custom text scaling
- inject$1(/var text_scale = .+?;/, 'var text_scale = textScale;');
- // Injects to support text padding within the textbox
- var topTextPaddingReplace = `var top = (2 * textPaddingY) + (borderHeight * 2) + (row * 2 * scale) + (row * font.getHeight() * textScale) + Math.floor( char.offset.y );`;
- var leftTextPaddingReplace = `var left = (2* textPaddingX) + (borderWidth * 2) + (leftPos * textScale) + Math.floor( char.offset.x );`;
- inject$1(/var top = \(4 \* scale\) \+ \(row \* 2 \* scale\) .+?\);/, topTextPaddingReplace);
- inject$1(/var left = \(4 \* scale\) \+ \(leftPos \* text_scale\) .+?\);/, leftTextPaddingReplace);
- // Inject to support custom text speeds
- inject$1(/var nextCharMaxTime = .+?;/, 'var nextCharMaxTime = textSpeed;');
- // Inject to support custom default text color
- inject$1(/this.color = .+?};/, 'this.color = { r:textColor[0], g:textColor[1], b:textColor[2], a:textColor[3] };');
- // Inject to support dynamic textbox resizing
- inject$1(/var pixelsPerRow = .+?;/, 'var pixelsPerRow = (textboxWidth*2) - (borderWidth*2) - (textPaddingX*2);');
- exports.hackOptions = hackOptions;
- }(this.hacks.textbox_customizer = this.hacks.textbox_customizer || {}, window));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement