Permalink
Browse files

moved classFromShorts to utils and fixed decoration uses tables

  • Loading branch information...
mikejsavage committed Apr 2, 2011
1 parent 1368878 commit f40587aeebe1b6ae162ce2675e0953a4c1aeb26d
Showing with 77 additions and 85 deletions.
  1. +3 −13 armory.lua
  2. +34 −0 inc/utils.lua
  3. +39 −51 templates/items/uses.lua
  4. +1 −21 weapons.lua
View
@@ -9,16 +9,6 @@ itemNameURL = loadTemplate( "itemNameURL" )
-local function classFromShort( short )
- for _, class in ipairs( Armors ) do
- if class.short == short then
- return class
- end
- end
-
- return nil
-end
-
local function pieceFromName( class, name )
for _, piece in ipairs( class.pieces ) do
-- convert every piece name to a url and not the other
@@ -34,9 +24,9 @@ end
local function decorFromName( name )
for _, decor in ipairs( Decorations ) do
- local urlName = urlFromName( decor.name )
+ local urlName = urlFromName( decor.name ) .. "_" .. decor.slots
- if urlName == name or urlName .. "_" .. decor.slots == name then
+ if urlName == name then
return decor
end
end
@@ -74,7 +64,7 @@ if Get.class then
state = "decorations"
end
else
- local class = classFromShort( Get.class )
+ local class = armorClassFromShort( Get.class )
if class then
state = "class"
View
@@ -112,6 +112,40 @@ function T( translation )
return translation[ DefaultLanguage ]
end
+-- classFromShort functions
+-- all return the class object where class.short == short
+-- or nil if nothing matched
+
+function weaponClassFromShort( short )
+ for _, class in ipairs( Weapons ) do
+ if class.short == short then
+ return class
+ end
+ end
+
+ return nil
+end
+
+function gunClassFromShort( short )
+ for _, class in ipairs( Guns ) do
+ if class.short == short then
+ return class
+ end
+ end
+
+ return nil
+end
+
+function armorClassFromShort( short )
+ for _, class in ipairs( Armors ) do
+ if class.short == short then
+ return class
+ end
+ end
+
+ return nil
+end
+
-- templates and helper functions
-- TODO: perhaps the templates module should be
-- rewritten so this is done automatically
View
@@ -1,15 +1,3 @@
-{%
-local function classFromShort( equipment, short )
- for _, class in ipairs( equipment ) do
- if class.short == short then
- return class
- end
- end
-
- return nil
-end
-%}
-
<h2>Used for</h2>
<table class="data">
@@ -20,56 +8,56 @@ end
</tr>
{%
- if item.uses.weapons then
- local weaponNameURL = loadTemplate( "weapons/weaponNameURL" )
-
- for _, weaponUse in ipairs( item.uses.weapons ) do
- local class = classFromShort( Weapons, weaponUse.short )
-
- printf( "<tr><td>%s</td><td>%s</td><td>%d</td></tr>",
- weaponUse.type == "create" and "Creating" or "Upgrading to",
- weaponNameURL( { class = class, weapon = class.weapons[ weaponUse.id ] } ),
- weaponUse.count
- )
+ if item.uses.weapons then
+ local weaponNameURL = loadTemplate( "weapons/weaponNameURL" )
+
+ for _, weaponUse in ipairs( item.uses.weapons ) do
+ local class = weaponClassFromShort( weaponUse.short )
+
+ printf( "<tr><td>%s</td><td>%s</td><td>%d</td></tr>",
+ weaponUse.type == "create" and "Creating" or "Upgrading to",
+ weaponNameURL( { class = class, weapon = class.weapons[ weaponUse.id ] } ),
+ weaponUse.count
+ )
+ end
end
- end
- if item.uses.guns then
- local weaponNameURL = loadTemplate( "weapons/weaponNameURL" )
+ if item.uses.guns then
+ local weaponNameURL = loadTemplate( "weapons/weaponNameURL" )
- for _, gunUse in ipairs( item.uses.guns ) do
- local class = classFromShort( Guns, gunUse.short )
+ for _, gunUse in ipairs( item.uses.guns ) do
+ local class = gunClassFromShort( gunUse.short )
- printf( "<tr><td>%s</td><td>%s</td><td>%d</td></tr>",
- gunUse.type == "create" and "Creating" or "Upgrading to",
- weaponNameURL( { class = class, weapon = class.weapons[ gunUse.id ] } ),
- gunUse.count
- )
+ printf( "<tr><td>%s</td><td>%s</td><td>%d</td></tr>",
+ gunUse.type == "create" and "Creating" or "Upgrading to",
+ weaponNameURL( { class = class, weapon = class.weapons[ gunUse.id ] } ),
+ gunUse.count
+ )
+ end
end
- end
- if item.uses.armors then
- local pieceNameURL = loadTemplate( "armory/pieceNameURL" )
+ if item.uses.armors then
+ local pieceNameURL = loadTemplate( "armory/pieceNameURL" )
- for _, armorUse in ipairs( item.uses.armors ) do
- local class = classFromShort( Armors, armorUse.short )
+ for _, armorUse in ipairs( item.uses.armors ) do
+ local class = armorClassFromShort( armorUse.short )
- printf( "<tr><td>Creating</td><td>%s</td><td>%d</td></tr>",
- pieceNameURL( { class = class, piece = class.pieces[ armorUse.id ] } ),
- armorUse.count
- )
+ printf( "<tr><td>Creating</td><td>%s</td><td>%d</td></tr>",
+ pieceNameURL( { class = class, piece = class.pieces[ armorUse.id ] } ),
+ armorUse.count
+ )
+ end
end
- end
- --[[if item.uses.decorations then
- local decorNameURL = loadTemplate( "armory/decorNameURL" )
+ if item.uses.decorations then
+ local decorNameURL = loadTemplate( "armory/decorNameSlotsURL" )
- for _, decorUse in ipairs( item.uses.decorations ) do
- printf( "<tr><td>Creating</td><td>%s</td><td>%d</td></tr>",
- decorNameURL( { decor = Decorations[ decorUse.id ] } ),
- decorUse.count
- )
+ for _, decorUse in ipairs( item.uses.decorations ) do
+ printf( "<tr><td>Creating</td><td>%s</td><td>%d</td></tr>",
+ decorNameURL( { decor = Decorations[ decorUse.id ] } ),
+ decorUse.count
+ )
+ end
end
- end]]
%}
</table>
View
@@ -26,26 +26,6 @@ function getTATP( weapon )
return math.round( weapon.attack * ( 1 + 0.0025 * weapon.affinity ) * sharpMult( weapon ) )
end
-local function classFromShort( short )
- for _, class in ipairs( Weapons ) do
- if class.short == short then
- return class
- end
- end
-
- return nil
-end
-
-local function gunClassFromShort( short )
- for _, class in ipairs( Guns ) do
- if class.short == short then
- return class
- end
- end
-
- return nil
-end
-
local function weaponFromName( class, name )
for _, weapon in ipairs( class.weapons ) do
-- convert every weapon name to a url and not the other
@@ -64,7 +44,7 @@ end
local state = "nothing"
if Get.class then
- local class = classFromShort( Get.class )
+ local class = weaponClassFromShort( Get.class )
if class then
sharpness = loadTemplate( "weapons/sharpness" )

0 comments on commit f40587a

Please sign in to comment.