Created
July 12, 2012 11:24
-
-
Save zulman/3097560 to your computer and use it in GitHub Desktop.
ResourcesTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Предмет приносящий деньги: | |
var someItem = | |
{ | |
name:"name" | |
... | |
resources: | |
{ | |
gold:5, | |
silver:25, | |
gems:0 | |
} | |
} | |
//UI таблица с параметрами отображения ресурсов: | |
var resourcesIcons = { | |
gold: "/icons/ololo.png", | |
silver:"/icons/ololo2.png" | |
} | |
//Преобразуем таблицу значений ресурсов(цифры) в таблицу отображения(цифры+иконки) | |
function PrepareResources(resources, icons) | |
{ | |
var result = {}; | |
for(var idx in resources) | |
result[idx] = {value: resources[idx], img:icons[idx]} | |
return result; | |
} | |
function render() = { | |
var uiResourcesRepresentation = PrepareResources(this.resources, resourcesIcons); | |
// генерим кнопку с капельками | |
elem = soy.renderAsElement(green.view.template.weapon, | |
{ | |
'imagePath': this._loadRes(this.data.staticWeapon.img), | |
'cooldown': time, | |
// отдаем сразу все ресурсы и в шаблоне обрабатываем их циклом | |
'resources': uiResourcesRepresentation | |
}) | |
} | |
//Где то внутри шаблона | |
<div id=resourceItem> | |
<p id="value">${resources[index].value}</p> | |
<img src="${resources[index].img}"> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment