Skip to content

Commit

Permalink
Add 'family' tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Oct 8, 2024
1 parent dc2d8e3 commit 5eb40b3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/bbcodetext/font-family.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
set main=./examples/bbcodetext/font-family.js
cd ..
cd ..
npm run watch
44 changes: 44 additions & 0 deletions examples/bbcodetext/font-family.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import phaser from 'phaser/src/phaser.js';
import BBCodeTextPlugin from '../../plugins/bbcodetext-plugin.js';

class Demo extends Phaser.Scene {
constructor() {
super({
key: 'examples'
})
}

preload() {
}

create() {
var s = 'Hello [family=Roboto Condensed, fantasy]Hello[/family] Hello'
this.add.rexBBCodeText(200, 300, s, {
fontFamily: 'Papyrus',
fontSize: 40
})
}

update() { }
}

var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
},
scene: Demo,
plugins: {
global: [{
key: 'BBCodeTextPlugin',
plugin: BBCodeTextPlugin,
start: true
}]
}
};

var game = new Phaser.Game(config);
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var PropToTagText = function (text, prop, prevProp) {

case 'color':
case 'weight':
case 'family':
case 'stroke':
case 'bgcolor':
case 'y':
Expand Down
8 changes: 8 additions & 0 deletions plugins/gameobjects/tagtext/bbcodetext/parser/TagRegex.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ var SetDelimiters = function (delimiterLeft, delimiterRight) {
var SIZE_OPEN = GetOpenTagRegString(delimiterLeft, delimiterRight, SIZE, NUMBER_PARAM);
var SIZE_CLOSE = GetCloseTagRegString(delimiterLeft, delimiterRight, SIZE);

var FAMILY = 'family';
var FAMILY_OPEN = GetOpenTagRegString(delimiterLeft, delimiterRight, FAMILY, STR_PARAM);
var FAMILY_CLOSE = GetCloseTagRegString(delimiterLeft, delimiterRight, FAMILY);

var COLOR = 'color';
var COLOR_OPEN = GetOpenTagRegString(delimiterLeft, delimiterRight, COLOR, COLOR_PARAM);
var COLOR_CLOSE = GetCloseTagRegString(delimiterLeft, delimiterRight, COLOR);
Expand Down Expand Up @@ -140,6 +144,9 @@ var SetDelimiters = function (delimiterLeft, delimiterRight) {
TagRegexSave.RE_SIZE_OPEN = new RegExp(SIZE_OPEN, 'i');
TagRegexSave.RE_SIZE_CLOSE = new RegExp(SIZE_CLOSE, 'i');

TagRegexSave.RE_FAMILY_OPEN = new RegExp(FAMILY_OPEN, 'i');
TagRegexSave.RE_FAMILY_CLOSE = new RegExp(FAMILY_CLOSE, 'i');

TagRegexSave.RE_COLOR_OPEN = new RegExp(COLOR_OPEN, 'i');
TagRegexSave.RE_COLOR_CLOSE = new RegExp(COLOR_CLOSE, 'i');

Expand Down Expand Up @@ -189,6 +196,7 @@ var SetDelimiters = function (delimiterLeft, delimiterRight) {
WEIGHT_OPEN, WEIGHT_CLOSE,

SIZE_OPEN, SIZE_CLOSE,
FAMILY_OPEN, FAMILY_CLOSE,
COLOR_OPEN, COLOR_CLOSE,
UNDERLINE_OPEN, UNDERLINE_OPENC, UNDERLINE_CLOSE,
STRIKETHROUGH_OPEN, STRIKETHROUGH_OPENC, STRIKETHROUGH_CLOSE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ var TagTextToProp = function (text, prevProp) {
} else if (TagRegex.RE_SIZE_CLOSE.test(text)) {
UpdateProp(prevProp, PROP_REMOVE, 'size');

} else if (TagRegex.RE_FAMILY_OPEN.test(text)) {
var innerMatch = text.match(TagRegex.RE_FAMILY_OPEN);
UpdateProp(prevProp, PROP_ADD, 'family', innerMatch[1]);
} else if (TagRegex.RE_FAMILY_CLOSE.test(text)) {
UpdateProp(prevProp, PROP_REMOVE, 'family');

} else if (TagRegex.RE_COLOR_OPEN.test(text)) {
var innerMatch = text.match(TagRegex.RE_COLOR_OPEN);
UpdateProp(prevProp, PROP_ADD, 'color', innerMatch[1]);
Expand Down

0 comments on commit 5eb40b3

Please sign in to comment.