Improved bbcode

Posted by aeron on Jan. 25, 2014, 10:09 p.m.

JoshDreamland was nice enough to write us a brand new bbcode parser to replace our old (and very messy) parser. Generally you won't notice much difference as the changes are mostly behind the scenes, but the real benefit is for the developers. It is now incredibly easy to add new tags of all shapes and sizes and arbitrary functionality, as everything is uniformly organized.

So, I've finished porting all our old tags over, and everything should behave about the same as it did before.


Section Edited:

I rewrote the tag help page such that it is always up to date with the supported tags. Take a look!

I had also updated the youtube code to the modern embed tag, which has fixed some bugs with fullscreen. However, the new style of embedding seems to slow down loading, even behind hide tags. It is up for debate whether or not we should go back to the purely flash based embed.


Last but not least: A brand new tag for… you guessed it FSX: Markdown!

Markdown
[markdown]
# Headers and *stuff*
[A link](/index.php)
 * Also, lists
 * Lists are very useful
   * These are easy to write too
 * Have another

# Using reference links
I get 10 times more traffic from [Google] [1] than from [Yahoo] [2] or [MSN] [3].

  [1]: <a rel="nofollow" href="http://google.com/">http://google.com/</a>
  [2]: <a rel="nofollow" href="http://search.yahoo.com/">http://search.yahoo.com/</a>
  [3]: <a rel="nofollow" href="http://search.msn.com/">http://search.msn.com/</a>
[/markdown]

Quote: Result

Headers and stuff

A link * Also, lists * Lists are very useful * These are easy to write too * Have another

Using reference links

I get 10 times more traffic from [Google] [1] than from [Yahoo] [2] or [MSN] [3].

[1]: http://google.com/ [2]: http://search.yahoo.com/ [3]: http://search.msn.com/

That tag is also aliased to [md[blk]].

So yeah, let me know if you find any site-breaking bugs over the next few days due to this change and I'll look into it ASAP. And if you have suggestions for new (useful) tags, I'm all ears.

Comments

aeron 10 years, 2 months ago

Added a syntax highlighter to the code tag:

Lua
local Stack = require('classes.Stack')
local State = class()
State.__name = "State"

function State:__init()
	self.state = Stack:new()
end

local function buildEvent(name)
	local capname = name:sub(1,1):upper() .. name:sub(2) 
	local handlename = "on" .. capname
	local postname = "post" .. capname
	State[handlename] = function (parent,...)
		local child = parent.state:peek()
		if(parent[name]) then parent[name](parent,...) end
		if(child) then child[handlename](child,...) end
		if(parent[postname]) then parent[postname](parent,...) end
	end
end

buildEvent("update")
buildEvent("draw")
buildEvent("mousepressed")
buildEvent("mousereleased")
buildEvent("keypressed")
buildEvent("keyreleased")
buildEvent("focus")

return State

C++
#include "Bomb.h"
#include "Explosion.h"
#include "Engine/Game.h"
#include "Engine/World.h"
#include "Engine/Light.h"

Bomb::Bomb(std::shared_ptr<World> parent) : Entity(parent), time(0), frame(0) {
	sprite.setTexture(*Game::getTexture("bomb.png"));
	sprite.setOrigin(8,8);
	radius = 5;

	light = std::shared_ptr<Light>(new Light(world(), 128));
	light->add();
}

Bomb::~Bomb() {}

void Bomb::step() {
	moveBounce();

	dy += gravity;

	time += 1.0/60;
	if(time > 2) {
		std::shared_ptr<Explosion> exp(new Explosion(world(), x, y, 24));
		exp->add();
		light->remove();
		remove();
	}
	frame = (time / 2)*6;
	
	float bright = 1-sqrt(time/2.0);
	light->setColor(Game::HSV(20,0.8, Game::randomDouble(bright/2,bright)));
	light->setPosition(sf::Vector2f(x,y));

	sprite.setTextureRect(sf::IntRect(frame*16,0,16,16));
	sprite.setPosition(round(x),round(y));
}

void Bomb::render(std::shared_ptr<sf::RenderTarget> screen) {
	screen->draw(sprite);
}

Java
package cx.uni.aeron.xame;

import java.awt.image.BufferedImage;
import java.util.TreeMap;

public class EntityDef {
	protected BufferedImage entIcon;
	protected String type;
	protected TreeMap<String, String> properties;
	
	public EntityDef(String name, BufferedImage icon) {
		properties = new TreeMap<String,String>();
		type = name;
		entIcon = icon;
	}
	
	public void addProperty(String key, String defValue) {
		properties.put(key,defValue);
	}
	
	//Getters
	public BufferedImage getImage() { return entIcon; }
	public String getType() { return type; }
	public TreeMap<String, String> getProperties() { return properties; }
}

Python
import pyglet, level, entities, video, os, collections, string

#Anything in this queue defers keyboard control from the player!
animations = collections.deque()

class Animation:
	def __init__(self):
		self.done=False
	def update(self,keys):
		pass
	def draw(self,viewport=None):
		pass

class Fade(Animation):
	def __init__(self,out=True,length=16):
		Animation.__init__(self)
		self.pos=0
		self.total=length
		self.out=out
		
	def update(self,keys):
		self.pos+=1
		if self.pos>=self.total:
			self.done=True
	def draw(self,viewport=None):
		pyglet.graphics.draw(4, pyglet.gl.GL_QUADS,
			('v2i', (0,0,viewport.width,0,viewport.width,viewport.height,0,viewport.height)),
			('c4B', (0, 0, 0, int(float(self.pos)/self.total*255) if self.out else 255 - int(<a rel="nofollow" href="http://self.pos/float(self.total)*255">self.pos/float(self.total)*255</a>) )*4 ))

class LevelSwitch(Animation):
	def __init__(self,name,px=None,py=None):
		Animation.__init__(self)
		self.name=name
		self.px=px
		self.py=py
	def update(self,keys):
		level.loadLevel(self.name,self.px,self.py)
		self.done=True
	def draw(self,viewport=None):
		pyglet.graphics.draw(4, pyglet.gl.GL_QUADS,
			('v2i', (viewport.cx,viewport.cy,viewport.cx+viewport.width,viewport.cy,viewport.cx+viewport.width,viewport.cy+viewport.height,viewport.cx,viewport.cy+viewport.height)),
			('c3B', (0, 0, 0) *4 ))

Mega 10 years, 2 months ago

Aeron, you're compelling me to want to upload random snippets of code…

aeron 10 years, 2 months ago

I didn't bump it because I wasn't finished adding to it when I made the comment.

Also side note, the library used (highlight.js) tries to detect language if you don't specify, but it's not the best (in my tests it detected JS as PHP in one snippet but got it correct in another, YMMV). When in doubt, just use
Language
.

eagly 10 years, 2 months ago

Sexy. Very sexy indeed.

Pirate-rob 10 years, 2 months ago

Vary nice, Is there a list of supported languages?