updated fixture creation for crafting.

This commit is contained in:
Gabor Körber 2014-06-12 17:27:22 +02:00
parent 4e23027719
commit b6cb354446
6 changed files with 129 additions and 53 deletions

File diff suppressed because one or more lines are too long

View File

@ -37,11 +37,17 @@ def build_pk_cache(data, models=None):
d['pk'] = i d['pk'] = i
return data return data
def lookup_pk(data, name, mdl='scon.item'): def lookup_pk(data, name, mdl='scon.item', kwargs=None):
for d in data: for d in data:
if d['model'] == mdl: if d['model'] == mdl:
if d['fields'].get('name', '').lower() == name.lower(): if d['fields'].get('name', '').lower() == name.lower():
return d['pk'] found = True
if kwargs is not None:
for key, val in kwargs.items():
if not d['fields'].get(key, None) == val:
found = False
if found:
return d['pk']
def generate_fixtures(): def generate_fixtures():
data = [] data = []
@ -54,15 +60,24 @@ def generate_fixtures():
{'name': 'Crystal shard', 'sell_price': 3500, 'icon': 'resource_crystal_shard'}, {'name': 'Crystal shard', 'sell_price': 3500, 'icon': 'resource_crystal_shard'},
] ]
MATERIALS = [ MATERIALS = [
{'name': 'Tungsten plate', 'description': 'Durable tungsten plate', 'sell_price': 20000, {'name': 'Tungsten plate',
'description': 'Durable tungsten plate',
'sell_price': 20000,
'icon': 'component_tungsten_plate'}, 'icon': 'component_tungsten_plate'},
{'name': 'Screened battery', 'sell_price': 42000, 'icon': 'component_screened_battery'}, {'name': 'Screened battery', 'sell_price': 42000,
{'name': 'Osmium crystals', 'sell_price': 5500, 'icon': 'component_osmium_crystals'}, 'icon': 'component_screened_battery'},
{'name': 'Pure Silicon', 'sell_price': 2500, 'icon': 'component_pure_silicon'}, {'name': 'Osmium crystals', 'sell_price': 5500,
{'name': 'Processing block', 'sell_price': 22000, 'icon': 'component_processing_block'}, 'icon': 'component_osmium_crystals'},
{'name': 'Metal blank', 'sell_price': 1600, 'icon': 'component_metal_blank'}, {'name': 'Pure Silicon', 'sell_price': 2500,
{'name': 'Alien Monocrystal', 'sell_price': 25000, 'icon': 'component_alien_monocrystal'}, 'icon': 'component_pure_silicon'},
{'name': 'Computing chip', 'sell_price': 4500, 'icon': 'component_computing_chip'}, {'name': 'Processing block', 'sell_price': 22000,
'icon': 'component_processing_block'},
{'name': 'Metal blank', 'sell_price': 1600,
'icon': 'component_metal_blank'},
{'name': 'Alien Monocrystal', 'sell_price': 25000,
'icon': 'component_alien_monocrystal'},
{'name': 'Computing chip', 'sell_price': 4500,
'icon': 'component_computing_chip'},
] ]
AMMOS = [ AMMOS = [
{'name': 'Explosive Shells', {'name': 'Explosive Shells',
@ -103,7 +118,7 @@ def generate_fixtures():
{'name': 'Doomsday Missile', {'name': 'Doomsday Missile',
'quality': 1, 'quality': 1,
'sell_price': 1000, 'sell_price': 1000,
'tech': 5, #'tech': 5,
'icon': 'ammo_doomsday_missile', 'icon': 'ammo_doomsday_missile',
} }
] ]
@ -232,55 +247,55 @@ def generate_fixtures():
'role': 9, # LRF 'role': 9, # LRF
'icon': 'active_reverse_thruster', 'icon': 'active_reverse_thruster',
}, },
{'name': 'Alien Plasma Gun III', {'name': 'Plasma Gun III',
'quality': 5, 'quality': 5,
'tech': 3, 'tech': 3,
'typ': 7, # weap 'typ': 7, # weap
'icon': 'weapon_plasma_gun_mk5', 'icon': 'weapon_plasma_gun_mk5',
}, },
{'name': 'Alien Plasma Gun IV', {'name': 'Plasma Gun IV',
'quality': 5, 'quality': 5,
'tech': 4, 'tech': 4,
'typ': 7, # weap 'typ': 7, # weap
'icon': 'weapon_plasma_gun_mk5', 'icon': 'weapon_plasma_gun_mk5',
}, },
{'name': 'Alien Plasma Gun V', {'name': 'Plasma Gun V',
'quality': 5, 'quality': 5,
'tech': 5, 'tech': 5,
'typ': 7, # weap 'typ': 7, # weap
'icon': 'weapon_plasma_gun_mk5', 'icon': 'weapon_plasma_gun_mk5',
}, },
{'name': 'Alien Assault Railgun III', {'name': 'Assault Railgun III',
'quality': 5, 'quality': 5,
'tech': 3, 'tech': 3,
'typ': 7, # weap 'typ': 7, # weap
'icon': 'weapon_assault_rail_mk5', 'icon': 'weapon_assault_rail_mk5',
}, },
{'name': 'Alien Assault Railgun IV', {'name': 'Assault Railgun IV',
'quality': 5, 'quality': 5,
'tech': 4, 'tech': 4,
'typ': 7, # weap 'typ': 7, # weap
'icon': 'weapon_assault_rail_mk5', 'icon': 'weapon_assault_rail_mk5',
}, },
{'name': 'Alien Assault Railgun V', {'name': 'Assault Railgun V',
'quality': 5, 'quality': 5,
'tech': 5, 'tech': 5,
'typ': 7, # weap 'typ': 7, # weap
'icon': 'weapon_assault_rail_mk5', 'icon': 'weapon_assault_rail_mk5',
}, },
{'name': 'Alien Beam Cannon III', {'name': 'Beam Cannon III',
'quality': 5, 'quality': 5,
'tech': 3, 'tech': 3,
'typ': 7, # weap 'typ': 7, # weap
'icon': 'weapon_beam_cannon_mk5', 'icon': 'weapon_beam_cannon_mk5',
}, },
{'name': 'Alien Beam Cannon IV', {'name': 'Beam Cannon IV',
'quality': 5, 'quality': 5,
'tech': 4, 'tech': 4,
'typ': 7, # weap 'typ': 7, # weap
'icon': 'weapon_beam_cannon_mk5', 'icon': 'weapon_beam_cannon_mk5',
}, },
{'name': 'Alien Beam Cannon V', {'name': 'Beam Cannon V',
'quality': 5, 'quality': 5,
'tech': 5, 'tech': 5,
'typ': 7, # weap 'typ': 7, # weap
@ -399,67 +414,67 @@ def generate_fixtures():
]}, ]},
# plasma # plasma
{'item': 'Alien Plasma Gun III', {'item': ('Plasma Gun III', {'quality': 5}),
'recipee': [(1, 'Plasma Gun Prototype T3 Blueprint'), 'recipee': [(1, 'Plasma Gun Prototype T3 Blueprint'),
(1, 'Plasma Gun III'), (1, ('Plasma Gun III', {'quality': 4})),
(6, 'Metal blank'), (6, 'Metal blank'),
(3, 'Screened battery'), (3, 'Screened battery'),
(30, 'Alien Monocrystal') (30, 'Alien Monocrystal')
]}, ]},
{'item': 'Alien Plasma Gun IV', {'item': ('Plasma Gun IV', {'quality': 5}),
'recipee': [(1, 'Plasma Gun Prototype T4 Blueprint'), 'recipee': [(1, 'Plasma Gun Prototype T4 Blueprint'),
(1, 'Plasma Gun IV'), (1, ('Plasma Gun IV', {'quality': 4})),
(1, 'Tungsten plate'), (1, 'Tungsten plate'),
(4, 'Screened battery'), (4, 'Screened battery'),
(50, 'Alien Monocrystal') (50, 'Alien Monocrystal')
]}, ]},
{'item': 'Alien Plasma Gun V', {'item': ('Plasma Gun V', {'quality': 5}),
'recipee': [(1, 'Plasma Gun Prototype T5 Blueprint'), 'recipee': [(1, 'Plasma Gun Prototype T5 Blueprint'),
(1, 'Plasma Gun V'), (1, ('Plasma Gun V', {'quality': 4})),
(3, 'Tungsten plate'), (3, 'Tungsten plate'),
(5, 'Screened battery'), (5, 'Screened battery'),
(70, 'Alien Monocrystal') (70, 'Alien Monocrystal')
]}, ]},
# assault # assault
{'item': 'Alien Assault Railgun III', {'item': ('Assault Railgun III', {'quality': 5}),
'recipee': [(1, 'Assault Railgun Prototype T3 Blueprint'), 'recipee': [(1, 'Assault Railgun Prototype T3 Blueprint'),
(1, 'Assault Railgun III'), (1, ('Assault Railgun III', {'quality': 4})),
(6, 'Metal blank'), (6, 'Metal blank'),
(3, 'Screened battery'), (3, 'Screened battery'),
(30, 'Alien Monocrystal') (30, 'Alien Monocrystal')
]}, ]},
{'item': 'Alien Assault Railgun IV', {'item': ('Assault Railgun IV', {'quality': 5}),
'recipee': [(1, 'Assault Railgun Prototype T4 Blueprint'), 'recipee': [(1, 'Assault Railgun Prototype T4 Blueprint'),
(1, 'Assault Railgun IV'), (1, ('Assault Railgun IV', {'quality': 4})),
(1, 'Tungsten plate'), (1, 'Tungsten plate'),
(4, 'Screened battery'), (4, 'Screened battery'),
(50, 'Alien Monocrystal') (50, 'Alien Monocrystal')
]}, ]},
{'item': 'Alien Assault Railgun V', {'item': ('Assault Railgun V', {'quality': 5}),
'recipee': [(1, 'Assault Railgun Prototype T5 Blueprint'), 'recipee': [(1, 'Assault Railgun Prototype T5 Blueprint'),
(1, 'Assault Railgun V'), (1, ('Assault Railgun V', {'quality': 4})),
(3, 'Tungsten plate'), (3, 'Tungsten plate'),
(5, 'Screened battery'), (5, 'Screened battery'),
(70, 'Alien Monocrystal') (70, 'Alien Monocrystal')
]}, ]},
# beam # beam
{'item': 'Alien Beam Cannon III', {'item': ('Beam Cannon III', {'quality': 5}),
'recipee': [(1, 'Beam Cannon Prototype T3 Blueprint'), 'recipee': [(1, 'Beam Cannon Prototype T3 Blueprint'),
(1, 'Beam Cannon III'), (1, ('Beam Cannon III', {'quality': 4})),
(6, 'Metal blank'), (6, 'Metal blank'),
(3, 'Screened battery'), (3, 'Screened battery'),
(30, 'Alien Monocrystal') (30, 'Alien Monocrystal')
]}, ]},
{'item': 'Alien Beam Cannon IV', {'item': ('Beam Cannon IV', {'quality': 5}),
'recipee': [(1, 'Beam Cannon Prototype T4 Blueprint'), 'recipee': [(1, 'Beam Cannon Prototype T4 Blueprint'),
(1, 'Beam Cannon IV'), (1, ('Beam Cannon IV', {'quality': 4})),
(1, 'Tungsten plate'), (1, 'Tungsten plate'),
(4, 'Screened battery'), (4, 'Screened battery'),
(50, 'Alien Monocrystal') (50, 'Alien Monocrystal')
]}, ]},
{'item': 'Alien Beam Cannon V', {'item': ('Beam Cannon V', {'quality': 5}),
'recipee': [(1, 'Beam Cannon Prototype T5 Blueprint'), 'recipee': [(1, 'Beam Cannon Prototype T5 Blueprint'),
(1, 'Beam Cannon V'), (1, ('Beam Cannon V', {'quality': 4})),
(3, 'Tungsten plate'), (3, 'Tungsten plate'),
(5, 'Screened battery'), (5, 'Screened battery'),
(70, 'Alien Monocrystal') (70, 'Alien Monocrystal')
@ -529,17 +544,29 @@ def generate_fixtures():
j = 1 # counter for input j = 1 # counter for input
for craft in CRAFTING: for craft in CRAFTING:
try: try:
item = craft['item']
kwargs = None
if isinstance(item, tuple) or isinstance(item, list):
kwargs = item[1]
item = item[0]
crafting = {'model': 'scon.crafting', crafting = {'model': 'scon.crafting',
'pk': i, 'pk': i,
'fields': { 'output': lookup_pk(data, craft['item']), 'fields': { 'output': lookup_pk(data, item, kwargs=kwargs ),
'amount': craft.get('amount', 1) }} 'amount': craft.get('amount', 1) }}
data.append(crafting) data.append(crafting)
primary = True primary = True
for amount, recipee in craft['recipee']: for amount, recipee in craft['recipee']:
item = recipee
kwargs = None
if isinstance(item, tuple) or isinstance(item, list):
print item
kwargs = item[1]
item = item[0]
crafting_input = {'model': 'scon.craftinginput', crafting_input = {'model': 'scon.craftinginput',
'pk': j, 'pk': j,
'fields': {'crafting': i, 'fields': {'crafting': i,
'item': lookup_pk(data, recipee), 'item': lookup_pk(data, item, kwargs=kwargs),
'amount': amount, 'amount': amount,
'primary': primary} 'primary': primary}
} }

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.safestring import mark_safe
ITEM_TYPES = ( ITEM_TYPES = (
(0, 'Misc'), (0, 'Misc'),
@ -89,11 +90,25 @@ class Item(models.Model):
def crafting_used_in(self): def crafting_used_in(self):
return CraftingInput.objects.filter(item=self) return CraftingInput.objects.filter(item=self)
def __unicode__(self): def get_full_name(self):
if self.quality: if self.quality:
return '%s (%s)' % (self.name, D_QUALITY.get(self.quality, '')) return '%s (%s)' % (self.name, D_QUALITY.get(self.quality, ''))
return '%s' % (self.name,) return '%s' % (self.name,)
def __unicode__(self):
return self.get_full_name()
def html(self):
# returns a html coded span with the items name.
classes = []
if self.quality:
classes.append('quality-%s' % self.quality)
ret = '<span'
if classes:
ret += ' class="%s"' % ' '.join(classes)
ret += '/>%s</span>' % self.name
return mark_safe(ret)
class Crafting(models.Model): class Crafting(models.Model):
output = models.ForeignKey(Item, related_name='crafting') output = models.ForeignKey(Item, related_name='crafting')

View File

@ -2,6 +2,7 @@
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="author" content="g4b.org">
<title>{{ title }}</title> <title>{{ title }}</title>
{% block extrahead %}{% endblock extrahead%} {% block extrahead %}{% endblock extrahead%}
{% block css %}{% endblock css %} {% block css %}{% endblock css %}

View File

@ -36,6 +36,14 @@
border: 1px solid #3c3c3c; border: 1px solid #3c3c3c;
} }
.remarks {
background-color: #444444;
color: #afafaf;
font-size: 0.6em;
-moz-border-radius: 3px;
border-radius: 3px;
}
.arrowright { .arrowright {
background: #2C2C2C; background: #2C2C2C;
font-size: 12px; font-size: 12px;
@ -56,6 +64,29 @@ border-top: 1.2em solid rgba(44, 44, 44, 0);
border-bottom: 1.2em solid rgba(44, 44, 44, 0); border-bottom: 1.2em solid rgba(44, 44, 44, 0);
content: ""; content: "";
} }
.quality-1 {
color: #e3e3e3;
}
.quality-2 {
color: #42d100;
}
.quality-3 {
color: #a9b8df;
}
.quality-4 {
color: #975aa0;
}
.quality-5 {
color: #d76d39;
}
.quality-14 {
color: #975aa0;
}
.quality-15 {
color: #d76d39;
}
--> -->
</style> </style>
{% endblock css %} {% endblock css %}

View File

@ -1,15 +1,15 @@
{% extends "scon/base.html" %} {% extends "scon/base.html" %}
{% block context %} {% block context %}
<img src="{{MEDIA_URL}}scon/conflict-logo.png" style="float:right;"> <img src="{{MEDIA_URL}}scon/conflict-logo.png" style="position: absolute; float:left; top: -42px;">
<h1>Star Conflict Crafting Cheat Sheet</h1> <h1 style="margin-left: 160px;">Crafting Overview</h1>
<table> <table>
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Source</th>
<th style="width: 1em;">&nbsp;</th> <th style="width: 1em;">&nbsp;</th>
<th>Crafts to</th> <th>Crafts into</th>
<th>Also used in Crafting</th> <th>Also used in</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -28,24 +28,26 @@
</td> </td>
<td> <td>
<div class="panel item"> <div class="panel item">
{% if recipee.output.icon %}<img src="{{ MEDIA_URL }}scon/icons/{{ recipee.output.icon }}.png">{% endif %} {{ recipee.output }} {% if recipee.output.icon %}<img src="{{ MEDIA_URL }}scon/icons/{{ recipee.output.icon }}.png">{% endif %} {{ recipee.output.html }}
{% if recipee.output.sell_price %}<br><i>Sell: {{recipee.output.sell_price}} cr</i>{% endif %} {% if recipee.output.sell_price %}<br><i>Sell: {{recipee.output.sell_price}} cr</i>{% endif %}
</div> </div>
<div class="panel-light item-sub"> <div class="panel-light item-sub">
<ul> <ul>
{% for ingredient in recipee.ingredients %} {% for ingredient in recipee.ingredients %}
<li>{{ ingredient.item.name }} x {{ ingredient.amount }}</li> <li>{{ ingredient.amount }} x {{ ingredient.item.html }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
</td> </td>
<td> <td>
<ul> <ul class="remarks">
{% for i1 in item.crafting_used_in %} {% for i1 in item.crafting_used_in %}
{% with i1.crafting.output as ci %} {% with i1.crafting.output as ci %}
<li>{{ ci.name }}</li> {% if ci.pk != recipee.output.pk %}
<li>{{ ci.html }}</li>
{% endif %}
{% for i2 in ci.crafting_used_in %} {% for i2 in ci.crafting_used_in %}
<li><i>{{ i2.crafting.output.name }} ({{ci.name}})</i></li> <li><i>{{ i2.crafting.output.html }} ({{ci.html}})</i></li>
{% endfor %} {% endfor %}
{% endwith %} {% endwith %}
{% endfor %} {% endfor %}