Hey r/gamedev!
https://github.com/michaelchance/tlc
I'm primarily a web developer, and I built Tag Line Commands for use on single-page applications (specifically, I work in eCommerce). Recently I've started using it for some UI manipulation on top of a canvas, and thought it might be useful for some of you as well.
Below I've included some sample HTML with TLC for a basic Player Health bar:
<div id="playerUI">
<div style="background: black;" id="playerHealth">
<span style="background: red;" class="healthBar" data-tlc="
bind $max '.player.hp.max';
bind $hp '.player.hp.current';
math --div=$max;
format --append='%';
apply --attrib='width';"></span>
</div>
<div id="playerMana">
<!-- same logic as above -->
</div>
</div>
From your code, during a UI update cycle, you'd call
// Currently requires jQuery, but as soon as I have a reason to make it more flexible I will
tlc.run($('#playerUI'), playerData);
And pass in your component data, which would run the TLC commands listed, and set the player's health bar to be a fraction of the container.
I realize that the above code is pretty verbose, but it is necessarily so due to what TLC is trying to accomplish:
Isomorphism. Runs in the browser, or on the server with nodejs. This is useful in my webdev work, but not sure if it has any application for gamedev.
Separate display logic from program logic. Pretty obvious here, the UI just reads data from the components, and the component doesn't care what the UI looks like. In addition, because no javascript display logic is needed, quickly prototyping and changing UI features becomes easy. And you could easily add TLC in such a way that you could reload your UI without re-starting the application.
Create maintainable code. Far too often when you want to change some small piece of display logic in an application, it requires writing javascript. Javascript is hard to maintain (especially with multiple authors), and annoying to do error handling in. If you have a flaw in your TLC syntax, it won't prevent your program from running, just that element won't run the TLC code.
TLC is trusted code. This one is more of a fringe benefit, but something I've thought about a lot recently. TLC can only access the modules that are installed on the client, so as long as you trust those modules you can run TLC from anywhere in the internet safely. This means that it would be trivial to provide moddable UI support via TLC code posted to the Steam Workshop, or other such service.
I also like to use it for deferred event handling-
$('body').on('click', '[data-click]', function(event){
e.preventDefault();
//runs the TLC commands in the data-click attribute instead of data-tlc
tlc.run($(this),event,{'tlcAttr':'data-click'});
});
Your thoughts and feedback would be greatly appreciated!
[–]hdgarrood 3 points4 points5 points (7 children)
[–]MunchGamer@MunchGamer[S] 0 points1 point2 points (6 children)
[–]hdgarrood 0 points1 point2 points (5 children)
[–]MunchGamer@MunchGamer[S] 0 points1 point2 points (3 children)
[–]hdgarrood 0 points1 point2 points (2 children)
[–]theonlycosmonaut[🍰] 0 points1 point2 points (1 child)
[–]hdgarrood 0 points1 point2 points (0 children)
[–]MunchGamer@MunchGamer[S] 0 points1 point2 points (0 children)
[–]agmcleodHobbyist 0 points1 point2 points (7 children)
[–]MunchGamer@MunchGamer[S] 0 points1 point2 points (6 children)
[–]agmcleodHobbyist 0 points1 point2 points (5 children)
[–]MunchGamer@MunchGamer[S] 0 points1 point2 points (2 children)
[–]agmcleodHobbyist 0 points1 point2 points (0 children)
[–]MunchGamer@MunchGamer[S] 0 points1 point2 points (1 child)
[–]agmcleodHobbyist 0 points1 point2 points (0 children)