Skip to content

Instantly share code, notes, and snippets.

@stuartpb
Created January 20, 2013 12:02
Show Gist options
  • Save stuartpb/4578146 to your computer and use it in GitHub Desktop.
Save stuartpb/4578146 to your computer and use it in GitHub Desktop.
Page for constructing GIMP palette from TF2 resource files
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TF2 Color Kanger</title>
<style>
body {font-family: sans-serif}
textarea {width:100%; height:7em;}
#output {height: 44em;}
</style>
<script>
var qs = '"(?:\\\\.|[^"])*"';
var sp = '\\s*';
var qspair = '(?:(?:'+sp+qs+'){2})';
var regexes = {
single: {
name: '"TF_Tool_PaintCan_\\d*"'+sp+'"((?:\\\\.|[^"])*)"',
item: sp+'"\\d*"'+sp+'\\{'+sp+
'"name"'+sp+'"Paint Can \\d*"'+
qspair+'*'+sp+
'"attributes"'+sp+'\\{'+sp+
'"set item tint RGB"'+sp+'\\{'+sp+
'"attribute_class"'+sp+qs+sp+
'"value"'+sp+'"(\\d*)"'+
'(?:'+sp+'\\}){3}'
}, team: {
name: '"TF_Tool_PaintCan_TeamColor\\d*"'+sp+'"((?:\\\\.|[^"])*)"',
item: sp+'"\\d*"'+sp+'\\{'+sp+
'"name"'+sp+'"Paint Can Team Color ?\\d*"'+
qspair+'*'+sp+
'"attributes"'+sp+'\\{'+sp+
'"set item tint RGB"'+sp+'\\{'+sp+
'"attribute_class"'+sp+qs+sp+
'"value"'+sp+'"(\\d*)"'+sp+'\\}'+sp+
'"set item tint RGB 2"'+sp+'\\{'+sp+
'"attribute_class"'+sp+qs+sp+
'"value"'+sp+'"(\\d*)"'+
'(?:'+sp+'\\}){3}'
}
};
function makeColor(triplet) {
return {
r: (triplet & (255 << 16)) >> 16,
g: (triplet & (255 << 8)) >> 8,
b: triplet & 255,
hex: triplet.toString(16).toUpperCase()
};
}
var itemHandlers = {
single: function(matches){
return makeColor(parseInt(matches[1],10));
},
team: function(matches){
return {
red: makeColor(parseInt(matches[1],10)),
blu: makeColor(parseInt(matches[2],10))
};
}
};
var names = {single:[], team: []};
var colors = {single:[], team: []};
function forEachMatch(strToMatch,regexSrc,cb){
var gRegex = new RegExp(regexSrc,'g');
var capRegex = new RegExp(regexSrc);
var matches = strToMatch.match(gRegex);
for(var i = 0; i < matches.length; i++){
cb(i,matches[i].match(capRegex));
}
}
//NOTE: Doesn't actually push, I don't roll like that
function pushResult(a,cb){
return function(i,matches){
a[i] = cb(matches);
};
}
function firstCap(matches){return matches[1]}
function putjson(){
var retarr = [], i=0;
for(i = 0; i < names.team.length; i++){
retarr.push({
name: names.team[i],
red: colors.team[i].red,
blu: colors.team[i].blu});
}
for(i = 0; i < names.single.length; i++){
retarr.push({
name: names.single[i],
color: colors.single[i]});
}
document.getElementById("output").value = JSON.stringify(retarr);
}
function pad(str,size){
str = str.toString();
return Array(size + 1 - str.length).join(' ') + str;
}
function putpalette(){
var lines = [], i=0;
for(i = 0; i < names.team.length; i++){
var red = colors.team[i].red;
var blu = colors.team[i].blu;
lines.push(pad(red.r,3)+' '+pad(red.r,3)+' '+ pad(red.b,3)+
' RED '+names.team[i]+' (#'+red.hex+')');
lines.push(pad(blu.r,3)+' '+pad(blu.r,3)+' '+ pad(blu.b,3)+
' BLU '+names.team[i]+' (#'+blu.hex+')');
}
for(i = 0; i < names.single.length; i++){
var color = colors.single[i];
lines.push(pad(color.r,3)+' '+pad(color.r,3)+' '+ pad(color.b,3)+
' '+names.single[i]+' (#'+color.hex+')');
}
document.getElementById("output").value = lines.join('\n');
}
function go(){
var itemText = document.getElementById("items").value;
var nameText = document.getElementById("names").value;
for (var k in colors) {
forEachMatch(nameText,regexes[k].name,
pushResult(names[k],firstCap));
forEachMatch(itemText,regexes[k].item,
pushResult(colors[k],itemHandlers[k]));
}
putpalette();
}
</script>
</head>
<body>
<div>
<label>Items from tf/scripts/items/items_game.txt
<textarea id="items">
"5027"
{
"name" "Paint Can 1"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_1"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "7511618"
}
}
}
"5028"
{
"name" "Paint Can 2"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_2"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "4345659"
}
}
}
"5029"
{
"name" "Paint Can 3"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_3"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "5322826"
}
}
}
"5030"
{
"name" "Paint Can 4"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_4"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "14204632"
}
}
}
"5031"
{
"name" "Paint Can 5"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_5"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "8208497"
}
}
}
"5032"
{
"name" "Paint Can 6"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_6"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "13595446"
}
}
}
"5033"
{
"name" "Paint Can 7"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_7"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "10843461"
}
}
}
"5034"
{
"name" "Paint Can 8"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_8"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "12955537"
}
}
}
"5035"
{
"name" "Paint Can 9"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_9"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "6901050"
}
}
}
"5036"
{
"name" "Paint Can 10"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_10"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "8154199"
}
}
}
"5037"
{
"name" "Paint Can 11"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_11"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "15185211"
}
}
}
"5038"
{
"name" "Paint Can 12"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_12"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "8289918"
}
}
}
"5039"
{
"name" "Paint Can 13"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_13"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "15132390"
}
}
}
"5040"
{
"name" "Paint Can 14"
"prefab" "paint_can"
"first_sale_date" "2010/09/29"
"item_name" "#TF_Tool_PaintCan_14"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "1315860"
}
}
}
"5046"
{
"name" "Paint Can Team Color"
"prefab" "paint_can_team_color"
"first_sale_date" "2010/10/29"
"item_name" "#TF_Tool_PaintCan_TeamColor"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "12073019"
}
"set item tint RGB 2"
{
"attribute_class" "set_item_tint_rgb_2"
"value" "5801378"
}
}
}
"5051"
{
"name" "Paint Can 15"
"prefab" "paint_can"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_15"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "16738740"
}
}
}
"5052"
{
"name" "Paint Can 16"
"prefab" "paint_can"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_16"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "3100495"
}
}
}
"5053"
{
"name" "Paint Can 17"
"prefab" "paint_can"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_17"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "8421376"
}
}
}
"5054"
{
"name" "Paint Can 18"
"prefab" "paint_can"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_18"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "3329330"
}
}
}
"5055"
{
"name" "Paint Can 19"
"prefab" "paint_can"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_19"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "15787660"
}
}
}
"5056"
{
"name" "Paint Can 20"
"prefab" "paint_can"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_20"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "15308410"
}
}
}
"5060"
{
"name" "Paint Can Team Color 2"
"prefab" "paint_can_team_color"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_TeamColor2"
"item_description" "#TF_Tool_PaintCan_TeamColor2_Desc"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "4732984"
}
"set item tint RGB 2"
{
"attribute_class" "set_item_tint_rgb_2"
"value" "3686984"
}
}
}
"5061"
{
"name" "Paint Can Team Color 3"
"prefab" "paint_can_team_color"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_TeamColor3"
"item_description" "#TF_Tool_PaintCan_TeamColor3_Desc"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "11049612"
}
"set item tint RGB 2"
{
"attribute_class" "set_item_tint_rgb_2"
"value" "8626083"
}
}
}
"5062"
{
"name" "Paint Can Team Color 4"
"prefab" "paint_can_team_color"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_TeamColor4"
"item_description" "#TF_Tool_PaintCan_TeamColor4_Desc"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "3874595"
}
"set item tint RGB 2"
{
"attribute_class" "set_item_tint_rgb_2"
"value" "1581885"
}
}
}
"5063"
{
"name" "Paint Can Team Color 5"
"prefab" "paint_can_team_color"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_TeamColor5"
"item_description" "#TF_Tool_PaintCan_TeamColor5_Desc"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "6637376"
}
"set item tint RGB 2"
{
"attribute_class" "set_item_tint_rgb_2"
"value" "2636109"
}
}
}
"5064"
{
"name" "Paint Can Team Color 6"
"prefab" "paint_can_team_color"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_TeamColor6"
"item_description" "#TF_Tool_PaintCan_TeamColor6_Desc"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "8400928"
}
"set item tint RGB 2"
{
"attribute_class" "set_item_tint_rgb_2"
"value" "2452877"
}
}
}
"5065"
{
"name" "Paint Can Team Color 7"
"prefab" "paint_can_team_color"
"first_sale_date" "2011/05/25"
"item_name" "#TF_Tool_PaintCan_TeamColor7"
"item_description" "#TF_Tool_PaintCan_TeamColor7_Desc"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "12807213"
}
"set item tint RGB 2"
{
"attribute_class" "set_item_tint_rgb_2"
"value" "12091445"
}
}
}
"5076"
{
"name" "Paint Can 21"
"prefab" "paint_can"
"item_name" "#TF_Tool_PaintCan_21"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "12377523"
}
}
}
"5077"
{
"name" "Paint Can 22"
"prefab" "paint_can"
"item_name" "#TF_Tool_PaintCan_22"
"attributes"
{
"set item tint RGB"
{
"attribute_class" "set_item_tint_rgb"
"value" "2960676"
}
}
}
</textarea></label>
</div>
<div>
<label>Names from tf/resource/tf_english.txt
<textarea id="names">
"TF_Tool_PaintCan_TeamColor" "Team Spirit"
"TF_Tool_PaintCan_TeamColor2" "Operator's Overalls"
"TF_Tool_PaintCan_TeamColor3" "Waterlogged Lab Coat"
"TF_Tool_PaintCan_TeamColor4" "Balaclavas Are Forever"
"TF_Tool_PaintCan_TeamColor5" "An Air of Debonair"
"TF_Tool_PaintCan_TeamColor6" "The Value of Teamwork"
"TF_Tool_PaintCan_TeamColor7" "Cream Spirit"
"TF_Tool_PaintCan_1" "Indubitably Green"
"TF_Tool_PaintCan_2" "Zepheniah's Greed"
"TF_Tool_PaintCan_3" "Noble Hatter's Violet"
"TF_Tool_PaintCan_4" "Color No. 216-190-216"
"TF_Tool_PaintCan_5" "A Deep Commitment to Purple"
"TF_Tool_PaintCan_6" "Mann Co. Orange"
"TF_Tool_PaintCan_7" "Muskelmannbraun"
"TF_Tool_PaintCan_8" "Peculiarly Drab Tincture"
"TF_Tool_PaintCan_9" "Radigan Conagher Brown"
"TF_Tool_PaintCan_10" "Ye Olde Rustic Colour"
"TF_Tool_PaintCan_11" "Australium Gold"
"TF_Tool_PaintCan_12" "Aged Moustache Grey"
"TF_Tool_PaintCan_13" "An Extraordinary Abundance of Tinge"
"TF_Tool_PaintCan_14" "A Distinctive Lack of Hue"
"TF_Tool_PaintCan_15" "Pink as Hell"
"TF_Tool_PaintCan_16" "A Color Similar to Slate"
"TF_Tool_PaintCan_17" "Drably Olive"
"TF_Tool_PaintCan_18" "The Bitter Taste of Defeat and Lime"
"TF_Tool_PaintCan_19" "The Color of a Gentlemann's Business Pants"
"TF_Tool_PaintCan_20" "Dark Salmon Injustice"
"TF_Tool_PaintCan_21" "A Mann's Mint"
"TF_Tool_PaintCan_22" "After Eight"
</textarea></label>
</div>
<div>
<button type="button" onclick="go()">Punch it, Chewie!</button>
<button type="button" onclick="putjson()">JSON</button>
<button type="button" onclick="putpalette()">Palette</button>
</div>
<div>
<textarea id="output"></textarea>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment