This commit is contained in:
Gabor Körber 2014-06-11 12:37:56 +02:00
parent 224fdcd1b5
commit 4e23027719
42 changed files with 912 additions and 4 deletions

79
dejaqt/folders.py Normal file
View File

@ -0,0 +1,79 @@
import logging, os
try:
from django.conf import settings
except:
logging.error('Django Settings could not be loaded. Maybe Django has not been initialized?')
settings = None
class FolderLibrary(object):
def __init__(self, folders=None):
self._folders = {}
try:
if settings:
self.folders.update( getattr(settings, 'DEJAQT_DIRS', {}) )
except:
logging.error('DEJAQT_DIRS in django settings is corrupt.')
if folders:
# no try here: if this fails, you got yourself a programming error.
self.folders.update(folders)
self._keys = []
self.build_keycache()
def get_folders(self):
return self._folders
def set_folders(self, folders):
self._folders = folders
self.build_keycache()
folders = property(get_folders, set_folders)
def build_keycache(self):
self._keys = self._folders.keys()
self._keys.sort(key=lambda item: (-len(item), item))
def add_folder(self, url, folder):
if not url:
url = ''
self._folders[url] = folder
self.build_keycache()
def match(self, url):
# run down our keycache, first match wins.
for key in self._keys:
if url.startswith(key):
return key
def matched_folder(self, url):
m = self.match(url)
if m is not None:
real_folder = self._folders[m]
print m
print url
print url[len(m):]
print os.path.split(real_folder)
print os.path.split(url)
return real_folder
def print_folders(self):
print '{'
for k in self._keys:
print "'%s': '%s'" % (k, self._folders[k])
print '}'
if __name__ == "__main__":
# test this:
f = FolderLibrary({'abc/dab/': 'c:/dab',
'abc': 'd:/abc',
'abc/dab/tmp': '/tmp',
'uiuiui': 'x:/',
'abc/vul/no': 'x:/2',
'abc/vul': 'x:/3',
'abc/vul/yes': 'x:/1',
})
f.add_folder('abc/dub/', 'c:/dubdub')
f.print_folders()
print f.matched_folder('abc/dab/okokok/hurnkint.pdf')

View File

@ -1,3 +1,6 @@
from django.contrib import admin from django.contrib import admin
import models
# Register your models here. # Register your models here.
admin.site.register(models.Crafting)
admin.site.register(models.CraftingInput)
admin.site.register(models.Item)

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,565 @@
"""
Generate Fixtures for Crafting.
Simple generator, does not integrate well into existing stuff, so please use
only for bootstrapping.
"""
import os, json
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DIR = os.path.join(BASE_DIR, 'scon', 'fixtures')
def write_fixture(data):
f = open(os.path.join(DIR, 'generated.json'), 'w')
f.write(json.dumps(data))
f.close()
def build_pk_cache(data, models=None):
pk_cache = {}
# fill cache from existing
for d in data:
if 'pk' in d.keys():
# has pk
pk_cache[d['model']] = max(pk_cache.get('model', 0), d['pk'])
for d in data:
m = d['model']
if models:
if m not in models:
continue
if 'pk' in d.keys():
#print "PK was already in there! %s" % d
pass
else:
if m not in pk_cache.keys():
pk_cache[m] = 1
i = 1
else:
i = pk_cache[m] + 1
pk_cache[m] = i
d['pk'] = i
return data
def lookup_pk(data, name, mdl='scon.item'):
for d in data:
if d['model'] == mdl:
if d['fields'].get('name', '').lower() == name.lower():
return d['pk']
def generate_fixtures():
data = []
ORES = [
{'name': 'Tungsten ore', 'sell_price': 6600, 'icon': 'resource_tungsten_ore'},
{'name': 'Osmium ore', 'sell_price': 4500, 'icon': 'resource_osmium_ore'},
{'name': 'Silicon ore', 'sell_price': 600, 'icon': 'resource_silicon_ore'},
{'name': 'Vanadium', 'sell_price': 500, 'icon': 'resource_vanadium'},
{'name': 'Crystal shard', 'sell_price': 3500, 'icon': 'resource_crystal_shard'},
]
MATERIALS = [
{'name': 'Tungsten plate', 'description': 'Durable tungsten plate', 'sell_price': 20000,
'icon': 'component_tungsten_plate'},
{'name': 'Screened battery', 'sell_price': 42000, 'icon': 'component_screened_battery'},
{'name': 'Osmium crystals', 'sell_price': 5500, 'icon': 'component_osmium_crystals'},
{'name': 'Pure Silicon', 'sell_price': 2500, 'icon': 'component_pure_silicon'},
{'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 = [
{'name': 'Explosive Shells',
'quality': 4,
'sell_price': 1000,
'icon': 'ammo_explosive_shells_mk4',
},
{'name': 'Double Deflector',
'quality': 4,
'sell_price': 1000,
'icon': 'ammo_double_deflector_mk4',
},
{'name': 'Xenon Lamp',
'quality': 4,
'sell_price': 1000,
'icon': 'ammo_xenon_lamp_mk4',
},
{'name': 'Attack Drone',
'quality': 10,
'sell_price': 1092,
'icon': 'ammo_attack_drone',
},
{'name': 'Focusing Lens',
'quality': 4,
'sell_price': 1000,
'icon': 'ammo_focusing_lens',
},
{'name': 'Iridium Slugs',
'quality': 4,
'sell_price': 1000,
'icon': 'ammo_iridium_slugs',
},
{'name': 'Supercooled Charges',
'quality': 4,
'sell_price': 1000,
'icon': 'ammo_supercooled_charges',
},
{'name': 'Doomsday Missile',
'quality': 1,
'sell_price': 1000,
'tech': 5,
'icon': 'ammo_doomsday_missile',
}
]
ITEMS_NON_CRAFTING = [
{'name': 'Target Tracking Coprocessor III',
'typ': 5, # cpu
'tech': 3,
'sell_price': 20188,
'description': 'Increases Critical Damage',
'icon': 'cpu_target_tracking_coprocessor',
},
{'name': 'Plasma Gun III',
'typ': 7, # weap
'quality': 4,
'tech': 3,
'icon': 'weapon_plasma_gun',
},
{'name': 'Plasma Gun IV',
'typ': 7, # weap
'quality': 4,
'tech': 4,
'icon': 'weapon_plasma_gun',
},
{'name': 'Plasma Gun V',
'typ': 7, # weap
'quality': 4,
'tech': 5,
'icon': 'weapon_plasma_gun',
},
# assault rails:
{'name': 'Assault Railgun III',
'typ': 7, # weap
'quality': 4,
'tech': 3,
'icon': 'weapon_assault_railgun',
},
{'name': 'Assault Railgun IV',
'typ': 7, # weap
'quality': 4,
'tech': 4,
'icon': 'weapon_assault_railgun',
},
{'name': 'Assault Railgun V',
'typ': 7, # weap
'quality': 4,
'tech': 5,
'icon': 'weapon_assault_railgun',
},
# beam cannon:
{'name': 'Beam Cannon III',
'typ': 7, # weap
'quality': 4,
'tech': 3,
'icon': 'weapon_beam_cannon',
},
{'name': 'Beam Cannon IV',
'typ': 7, # weap
'quality': 4,
'tech': 4,
'icon': 'weapon_beam_cannon',
},
{'name': 'Beam Cannon V',
'typ': 7, # weap
'quality': 4,
'tech': 5,
'icon': 'weapon_beam_cannon',
},
]
ITEMS = [
{'name': 'Duplicator',
'typ': 0,
'sell_price': 8000,
'buy_price_premium': 200,
'description': 'Revives in Invasion with Cargo once.',
'icon': 'duplicator',
},
{'name': 'A1MA IV',
'quality': 1,
'tech': 4,
'typ': 8, # active.
'role': 0, # multipurp.
'sell_price': 26910,
'icon': 'active_a1ma',
},
{'name': 'Pirate "Orion" Targeting Complex V',
'quality': 14,
'tech': 5,
'typ': 8, # active.
'role': 3, # covops
'icon': 'active_t5_orion_targeting_complex_pirate',
},
{'name': 'Pirate Engine Overcharge V',
'quality': 14,
'tech': 5,
'typ': 8, # active.
'role': 6, # gunship
'icon': 'active_t5_engine_overcharge_pirate',
},
{'name': 'Pirate Mass Shield Generator V',
'quality': 14,
'tech': 5,
'typ': 8, # active.
'role': 7, # engi
'icon': 'active_t5_mass_shield_generator_pirate',
},
{'name': 'Reverse Thruster III',
'quality': 1,
'tech': 3,
'typ': 8, # active.
'role': 9, # LRF
'icon': 'active_reverse_thruster',
},
{'name': 'Reverse Thruster IV',
'quality': 1,
'tech': 4,
'typ': 8, # active.
'role': 9, # LRF
'icon': 'active_reverse_thruster',
},
{'name': 'Reverse Thruster V',
'quality': 1,
'tech': 5,
'typ': 8, # active.
'role': 9, # LRF
'icon': 'active_reverse_thruster',
},
{'name': 'Alien Plasma Gun III',
'quality': 5,
'tech': 3,
'typ': 7, # weap
'icon': 'weapon_plasma_gun_mk5',
},
{'name': 'Alien Plasma Gun IV',
'quality': 5,
'tech': 4,
'typ': 7, # weap
'icon': 'weapon_plasma_gun_mk5',
},
{'name': 'Alien Plasma Gun V',
'quality': 5,
'tech': 5,
'typ': 7, # weap
'icon': 'weapon_plasma_gun_mk5',
},
{'name': 'Alien Assault Railgun III',
'quality': 5,
'tech': 3,
'typ': 7, # weap
'icon': 'weapon_assault_rail_mk5',
},
{'name': 'Alien Assault Railgun IV',
'quality': 5,
'tech': 4,
'typ': 7, # weap
'icon': 'weapon_assault_rail_mk5',
},
{'name': 'Alien Assault Railgun V',
'quality': 5,
'tech': 5,
'typ': 7, # weap
'icon': 'weapon_assault_rail_mk5',
},
{'name': 'Alien Beam Cannon III',
'quality': 5,
'tech': 3,
'typ': 7, # weap
'icon': 'weapon_beam_cannon_mk5',
},
{'name': 'Alien Beam Cannon IV',
'quality': 5,
'tech': 4,
'typ': 7, # weap
'icon': 'weapon_beam_cannon_mk5',
},
{'name': 'Alien Beam Cannon V',
'quality': 5,
'tech': 5,
'typ': 7, # weap
'icon': 'weapon_beam_cannon_mk5',
},
]
BLUEPRINTS = [
{'name': 'Focusing Lens Blueprint'},
{'name': 'Iridium Slugs Blueprint'},
{'name': 'Supercooled Charges Blueprint'},
{'name': 'A1MA T4 Blueprint'},
{'name': 'Orion-2 Targeting Complex Blueprint',
'description': 'Module works twice as long but much weaker.'},
{'name': 'Engine Warp Overcharge Blueprint'},
{'name': 'Mass Shield Energizer Blueprint'},
{'name': 'Reverse Thruster T3 Blueprint'},
{'name': 'Reverse Thruster T4 Blueprint'},
{'name': 'Reverse Thruster T5 Blueprint'},
{'name': 'Beam Cannon Prototype T3 Blueprint'},
{'name': 'Beam Cannon Prototype T4 Blueprint'},
{'name': 'Beam Cannon Prototype T5 Blueprint'},
{'name': 'Assault Railgun Prototype T3 Blueprint'},
{'name': 'Assault Railgun Prototype T4 Blueprint'},
{'name': 'Assault Railgun Prototype T5 Blueprint'},
{'name': 'Plasma Gun Prototype T3 Blueprint'},
{'name': 'Plasma Gun Prototype T4 Blueprint'},
{'name': 'Plasma Gun Prototype T5 Blueprint'},
{'name': 'Doomsday Missile Blueprint'},
]
CRAFTING = [
{'item': 'Duplicator',
'recipee': [(1, 'Processing Block'), (2,'Computing chip'), (2, 'Metal blank')]},
{'item': 'Tungsten plate',
'recipee': [(2, 'Tungsten ore'),]},
{'item': 'Screened battery',
'recipee': [(1, 'Tungsten plate'), (2, 'Computing chip')]},
{'item': 'Osmium crystals',
'recipee': [(1, 'Osmium ore'),]},
{'item': 'Pure Silicon',
'recipee': [(1, 'Silicon ore'),]},
{'item': 'Computing chip',
'recipee': [(1, 'Crystal shard'),]},
{'item': 'Processing block',
'recipee': [(4, 'Pure Silicon'), (2, 'Computing chip')]},
{'item': 'Metal blank',
'recipee': [(2, 'Vanadium'),]},
{'item': 'Target Tracking Coprocessor III',
'recipee': [(1, 'Screened battery'), (7, 'Metal blank'), (5, 'Pure silicon')]},
{'item': 'Explosive Shells',
'amount': 2,
'recipee': [(1, 'Metal blank'),(2, 'Pure Silicon')]},
{'item': 'Attack drone',
'recipee': [(1, 'Alien Monocrystal'), (1,'Computing chip')]},
{'item': 'Double Deflector',
'amount': 2,
'recipee': [(1, 'Osmium crystals'),]},
{'item': 'Xenon Lamp',
'amount': 2,
'recipee': [(1, 'Computing chip'), (1, 'Pure Silicon')]},
{'item': 'Focusing Lens',
'amount': 2,
'recipee': [(1, 'Focusing Lens Blueprint'), (1, 'Osmium crystals')]},
{'item': 'Supercooled Charges',
'amount': 2,
'recipee': [(1, 'Supercooled Charges Blueprint'), (1, 'Computing chip')]},
{'item': 'Iridium Slugs',
'amount': 2,
'recipee': [(1, 'Iridium Slugs Blueprint'), (1, 'Metal blank')]},
{'item': 'A1MA IV',
'recipee': [(1, 'A1MA T4 Blueprint'), (2, 'Processing block'),
(14, 'Metal blank'), (2, 'Screened battery'),
(20, 'Alien Monocrystal')]},
{'item': 'Pirate "Orion" Targeting Complex V',
'recipee': [(1, 'Orion-2 Targeting Complex Blueprint'),
(3, 'Tungsten plate'),
(4, 'Computing chip'),
(2, 'Processing block'),
(30, 'Alien Monocrystal')
]},
{'item': 'Pirate Engine Overcharge V',
'recipee': [(1, 'Engine Warp Overcharge Blueprint'),
(3, 'Tungsten plate'),
(2, 'Osmium crystals'),
(2, 'Processing block'),
(30, 'Alien Monocrystal')
]},
{'item': 'Pirate Mass Shield Generator V',
'recipee': [(1, 'Mass Shield Energizer Blueprint'),
(10, 'Metal blank'),
(3, 'Computing chip'),
(3, 'Processing block'),
(30, 'Alien Monocrystal')
]},
# lrf reverse blink:
{'item': 'Reverse Thruster III',
'recipee': [(1, 'Reverse Thruster T3 Blueprint'),
(7, 'Metal blank'),
(1, 'Screened battery'),
(4, 'Computing chip'),
(15, 'Alien Monocrystal')
]},
{'item': 'Reverse Thruster IV',
'recipee': [(1, 'Reverse Thruster T4 Blueprint'),
(12, 'Metal blank'),
(2, 'Screened battery'),
(5, 'Computing chip'),
(20, 'Alien Monocrystal')
]},
{'item': 'Reverse Thruster V',
'recipee': [(1, 'Reverse Thruster T5 Blueprint'),
(7, 'Tungsten plate'),
(3, 'Screened battery'),
(6, 'Computing chip'),
(30, 'Alien Monocrystal')
]},
# plasma
{'item': 'Alien Plasma Gun III',
'recipee': [(1, 'Plasma Gun Prototype T3 Blueprint'),
(1, 'Plasma Gun III'),
(6, 'Metal blank'),
(3, 'Screened battery'),
(30, 'Alien Monocrystal')
]},
{'item': 'Alien Plasma Gun IV',
'recipee': [(1, 'Plasma Gun Prototype T4 Blueprint'),
(1, 'Plasma Gun IV'),
(1, 'Tungsten plate'),
(4, 'Screened battery'),
(50, 'Alien Monocrystal')
]},
{'item': 'Alien Plasma Gun V',
'recipee': [(1, 'Plasma Gun Prototype T5 Blueprint'),
(1, 'Plasma Gun V'),
(3, 'Tungsten plate'),
(5, 'Screened battery'),
(70, 'Alien Monocrystal')
]},
# assault
{'item': 'Alien Assault Railgun III',
'recipee': [(1, 'Assault Railgun Prototype T3 Blueprint'),
(1, 'Assault Railgun III'),
(6, 'Metal blank'),
(3, 'Screened battery'),
(30, 'Alien Monocrystal')
]},
{'item': 'Alien Assault Railgun IV',
'recipee': [(1, 'Assault Railgun Prototype T4 Blueprint'),
(1, 'Assault Railgun IV'),
(1, 'Tungsten plate'),
(4, 'Screened battery'),
(50, 'Alien Monocrystal')
]},
{'item': 'Alien Assault Railgun V',
'recipee': [(1, 'Assault Railgun Prototype T5 Blueprint'),
(1, 'Assault Railgun V'),
(3, 'Tungsten plate'),
(5, 'Screened battery'),
(70, 'Alien Monocrystal')
]},
# beam
{'item': 'Alien Beam Cannon III',
'recipee': [(1, 'Beam Cannon Prototype T3 Blueprint'),
(1, 'Beam Cannon III'),
(6, 'Metal blank'),
(3, 'Screened battery'),
(30, 'Alien Monocrystal')
]},
{'item': 'Alien Beam Cannon IV',
'recipee': [(1, 'Beam Cannon Prototype T4 Blueprint'),
(1, 'Beam Cannon IV'),
(1, 'Tungsten plate'),
(4, 'Screened battery'),
(50, 'Alien Monocrystal')
]},
{'item': 'Alien Beam Cannon V',
'recipee': [(1, 'Beam Cannon Prototype T5 Blueprint'),
(1, 'Beam Cannon V'),
(3, 'Tungsten plate'),
(5, 'Screened battery'),
(70, 'Alien Monocrystal')
]},
# missiles
{'item': 'Doomsday Missile',
'recipee': [(1, 'Doomsday Missile Blueprint'),
(2, 'Osmium crystals'),
(1, 'Computing chip'),
(1, 'Metal blank'),
]},
]
for ore in ORES:
fields = {'typ': 12,
'tech': 0,
'craftable': True,
}
fields.update(ore)
data.append({'model': 'scon.item', 'fields': fields})
for mat in MATERIALS:
fields = {'typ': 13,
'tech': 0,
'craftable': True,
}
fields.update(mat)
data.append({'model': 'scon.item', 'fields': fields})
for ammo in AMMOS:
fields = {'typ': 8,
'tech': 0,
'craftable': True,
}
fields.update(ammo)
data.append({'model': 'scon.item', 'fields': fields})
for item in ITEMS:
fields = {
# items define typ and tech!
'craftable': True,
}
fields.update(item)
data.append({'model': 'scon.item', 'fields': fields})
for item in ITEMS_NON_CRAFTING:
fields = {
# items define typ and tech!
'craftable': False,
}
fields.update(item)
data.append({'model': 'scon.item', 'fields': fields})
for bluep in BLUEPRINTS:
fields = {
'typ': 11, # blueprint
'tech': 0,
'craftable': True,
'icon': 'blueprint',
}
fields.update(bluep)
data.append({'model': 'scon.item', 'fields': fields})
build_pk_cache(data)
# now to the crafting recipees:
i = 1 # counter for crafting
j = 1 # counter for input
for craft in CRAFTING:
try:
crafting = {'model': 'scon.crafting',
'pk': i,
'fields': { 'output': lookup_pk(data, craft['item']),
'amount': craft.get('amount', 1) }}
data.append(crafting)
primary = True
for amount, recipee in craft['recipee']:
crafting_input = {'model': 'scon.craftinginput',
'pk': j,
'fields': {'crafting': i,
'item': lookup_pk(data, recipee),
'amount': amount,
'primary': primary}
}
primary = False
j = j + 1
data.append(crafting_input)
i = i + 1
except:
raise
build_pk_cache(data)
return data
if __name__ == "__main__":
fixes = generate_fixtures()
from pprint import pprint
pprint( fixes )
# check pks:
for d in fixes:
if d.get('pk', None) is None:
print "%s is fail." % d
write_fixture(fixes)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -1,3 +1,117 @@
from django.db import models from django.db import models
from django.utils.text import slugify
ITEM_TYPES = (
(0, 'Misc'),
(1, 'Engine'),
(2, 'Capacitor'),
(3, 'Shield'),
(4, 'Hull'),
(5, 'Cpu'),
(6, 'Active'),
(7, 'Weapon'),
(8, 'Ammo'),
(9, 'Missile'),
(10, 'Class'),
(11, 'Blueprint'),
(12, 'Resource'),
(13, 'Component'),
)
QUALITY_TYPES = (
(0, '-'),
(1, 'Mk1'),
(2, 'Mk2'),
(3, 'Mk3'),
(4, 'Mk4'),
(5, 'Mk5'),
(10, 'Universal'),
(14, 'Pirate Mk4'),
)
D_QUALITY = dict(QUALITY_TYPES)
TECH_TYPES = (
(0, ''),
(1, 'I'),
(2, 'II'),
(3, 'III'),
(4, 'IV'),
(5, 'V'),
)
ROLE_TYPES = (
(-1, ''),
(0, 'Multipurpose'),
(1, 'Recon'),
(2, 'ECM'),
(3, 'Covert Ops'),
(4, 'Tackler'),
(5, 'Command'),
(6, 'Gunship'),
(7, 'Engineer'),
(8, 'Guard'),
(9, 'Longrange')
)
# Create your models here. # Create your models here.
class Item(models.Model):
name = models.CharField(max_length=128)
description = models.TextField(blank=True, null=True)
tech = models.IntegerField(default=0, blank=True)
quality = models.IntegerField(default=0, blank=True, choices=QUALITY_TYPES)
icon = models.CharField(max_length=128, blank=True, null=True)
typ = models.IntegerField(default=0, choices=ITEM_TYPES)
craftable = models.BooleanField(default=False, blank=True)
sell_price = models.IntegerField(default=0, blank=True)
buy_price = models.IntegerField(default=0, blank=True)
buy_price_premium = models.IntegerField(default=0, blank=True)
role = models.IntegerField(default=-1, blank=True)
def save(self, *args, **kwargs):
if self.icon is None or self.icon == '':
if self.typ>0:
item_types = dict(ITEM_TYPES)
try:
s = item_types[self.typ]
s = s.lower()
except:
s = 'unknown'
self.icon = '%s_t%s_%s' % (s, self.tech, slugify(self.name))
else:
self.icon = 't%s_%s' % (self.tech, slugify(self.name))
return super(Item, self).save(*args, **kwargs)
def primary_recipee(self):
f=CraftingInput.objects.filter(primary=True, item=self)
if len(f) == 1:
return f[0].crafting
def crafting_used_in(self):
return CraftingInput.objects.filter(item=self)
def __unicode__(self):
if self.quality:
return '%s (%s)' % (self.name, D_QUALITY.get(self.quality, ''))
return '%s' % (self.name,)
class Crafting(models.Model):
output = models.ForeignKey(Item, related_name='crafting')
amount = models.IntegerField(default=1, blank=True)
input = models.ManyToManyField(Item, related_name='recipees', through='CraftingInput')
def ingredients(self):
return CraftingInput.objects.filter(crafting=self)
def __unicode__(self):
return 'Recipee for %s' % (self.output.name,)
class CraftingInput(models.Model):
crafting = models.ForeignKey(Crafting)
item = models.ForeignKey(Item)
amount = models.IntegerField(default=1)
primary = models.BooleanField(default=False, blank=True)
def __unicode__(self):
return 'Part of Recipee for %s (x%s): %s (x%s)' % (self.crafting.output, self.crafting.amount, self.item, self.amount)

View File

@ -1 +1,61 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block css %}
<style>
<!--
.panel {
background-color: #2d2d2d;
color: #fafafa;
}
.panel-light {
background-color: #3c3c3c;
color: #afafaf;
}
.item {
font-size:0.8em;
margin-top:-0.8em;
padding: 2px;
padding-left: 54px;
position: relative;
height: 56px;
-moz-border-radius: 2px;
border-radius: 2px;
}
.item-sub {
margin-top: -17px;
-moz-border-radius: 2px;
border-radius: 2px;
}
.item img {
left: 3px;
position: absolute;
border: 1px solid #3c3c3c;
}
.arrowright {
background: #2C2C2C;
font-size: 12px;
position: relative;
width: 1em;
height: 1em;
margin-left: -0.7em;
color: #ffffff;
font-size: 1.1em;
}
.arrowright::before {
bottom: -0.666em;
left: 0.8em;
position: absolute;
border-left: 1.2em solid #2C2C2C;
border-top: 1.2em solid rgba(44, 44, 44, 0);
border-bottom: 1.2em solid rgba(44, 44, 44, 0);
content: "";
}
-->
</style>
{% endblock css %}

View File

@ -0,0 +1,60 @@
{% extends "scon/base.html" %}
{% block context %}
<img src="{{MEDIA_URL}}scon/conflict-logo.png" style="float:right;">
<h1>Star Conflict Crafting Cheat Sheet</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th style="width: 1em;">&nbsp;</th>
<th>Crafts to</th>
<th>Also used in Crafting</th>
</tr>
</thead>
<tbody>
{% for item in items %}
{% if item.primary_recipee %}
<tr>
<td>
<div class="panel item">
{% if item.icon %}<img src="{{ MEDIA_URL }}scon/icons/{{ item.icon }}.png">{% endif %} {{ item.name }}
{% if item.sell_price %}<br><i>Sell: {{item.sell_price}} cr</i>{% endif %}
</div>
</td>
{% with item.primary_recipee as recipee %}
<td>
<div class="arrowright">{% if recipee.amount > 1 %}{{ recipee.amount }}{% endif %}</div>
</td>
<td>
<div class="panel item">
{% if recipee.output.icon %}<img src="{{ MEDIA_URL }}scon/icons/{{ recipee.output.icon }}.png">{% endif %} {{ recipee.output }}
{% if recipee.output.sell_price %}<br><i>Sell: {{recipee.output.sell_price}} cr</i>{% endif %}
</div>
<div class="panel-light item-sub">
<ul>
{% for ingredient in recipee.ingredients %}
<li>{{ ingredient.item.name }} x {{ ingredient.amount }}</li>
{% endfor %}
</ul>
</div>
</td>
<td>
<ul>
{% for i1 in item.crafting_used_in %}
{% with i1.crafting.output as ci %}
<li>{{ ci.name }}</li>
{% for i2 in ci.crafting_used_in %}
<li><i>{{ i2.crafting.output.name }} ({{ci.name}})</i></li>
{% endfor %}
{% endwith %}
{% endfor %}
</ul>
</td>
{% endwith %}
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endblock context %}

View File

@ -3,8 +3,17 @@ from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.template import RequestContext, loader from django.template import RequestContext, loader
import logic import logic
import models
def config(request): def config(request):
t = loader.get_template('scon/config.html') t = loader.get_template('scon/config.html')
c = RequestContext(request, logic.config({'title': 'Configure your Client'})) c = RequestContext(request, logic.config({'title': 'Configure your Client'}))
return HttpResponse(t.render(c)) return HttpResponse(t.render(c))
def crafting(request):
t = loader.get_template('scon/crafting/overview.html')
items = models.Item.objects.filter(craftable=True)
tree = None
c = RequestContext(request, {'tree': tree,
'items': items})
return HttpResponse(t.render(c))

View File

@ -36,6 +36,14 @@ INSTALLED_APPS = (
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'dj.scon',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.media",
"django.core.context_processors.static",
) )
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
@ -47,7 +55,7 @@ MIDDLEWARE_CLASSES = (
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
) )
ROOT_URLCONF = 'scon.dj.urls' ROOT_URLCONF = 'dj.urls'
WSGI_APPLICATION = 'dj.wsgi.application' WSGI_APPLICATION = 'dj.wsgi.application'
@ -80,6 +88,8 @@ USE_TZ = True
# https://docs.djangoproject.com/en/1.6/howto/static-files/ # https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = r'D:\work\workspace\scon\src\scon\dj\scon\media'
DEJAQT_DIRS = { DEJAQT_DIRS = {
STATIC_URL: '', STATIC_URL: '',

View File

@ -1,5 +1,5 @@
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin from django.contrib import admin
admin.autodiscover() admin.autodiscover()
@ -8,5 +8,12 @@ urlpatterns = patterns('',
# url(r'^$', 'dj.views.home', name='home'), # url(r'^$', 'dj.views.home', name='home'),
# url(r'^blog/', include('blog.urls')), # url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
#url(r'^scon/', include('scon.urls')), url(r'^crafting/', 'dj.scon.views.crafting', name='scon_crafting'),
) )
if settings.DEBUG :
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
)