WIP: Cleanup
This commit is contained in:
parent
715224653d
commit
6ee942f8dc
37 changed files with 547 additions and 2591 deletions
19
gurps_character/TestData/characters.py
Normal file
19
gurps_character/TestData/characters.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
def create_users():
|
||||
User.objects.create(
|
||||
username="neill",
|
||||
is_superuser=True,
|
||||
first_name="Neill",
|
||||
last_name="Cox",
|
||||
email="neill@neill.id.au",
|
||||
is_staff=True,
|
||||
is_active=True,
|
||||
date_joined="2024-07-31T00:00:00.000Z",
|
||||
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_users()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,7 +1,8 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from .models import GURPSCharacter, GameSystem
|
||||
from .models import GURPSCharacter, GameSystem, Campaign
|
||||
|
||||
admin.site.register(GURPSCharacter)
|
||||
admin.site.register(GameSystem)
|
||||
admin.site.register(Campaign)
|
||||
|
|
|
|||
0
gurps_character/management/__init__.py
Normal file
0
gurps_character/management/__init__.py
Normal file
0
gurps_character/management/commands/__init__.py
Normal file
0
gurps_character/management/commands/__init__.py
Normal file
24
gurps_character/management/commands/clear_data.py
Normal file
24
gurps_character/management/commands/clear_data.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
|
||||
def create_users():
|
||||
user = User.objects.create_user(
|
||||
username="neill",
|
||||
is_superuser=True,
|
||||
first_name="Neill",
|
||||
last_name="Cox",
|
||||
email="neill@neill.id.au",
|
||||
is_staff=True,
|
||||
is_active=True,
|
||||
date_joined="2024-07-31T00:00:00.000Z",
|
||||
password="password",
|
||||
)
|
||||
# user.save()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Load some initial data"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
create_users()
|
||||
24
gurps_character/management/commands/load_data.py
Normal file
24
gurps_character/management/commands/load_data.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
|
||||
def create_users():
|
||||
user = User.objects.create_user(
|
||||
username="neill",
|
||||
is_superuser=True,
|
||||
first_name="Neill",
|
||||
last_name="Cox",
|
||||
email="neill@neill.id.au",
|
||||
is_staff=True,
|
||||
is_active=True,
|
||||
date_joined="2024-07-31T00:00:00.000Z",
|
||||
password="password",
|
||||
)
|
||||
# user.save()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Load some initial data"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
create_users()
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
# Generated by Django 5.0.6 on 2024-07-14 09:14
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("gurps_character", "0003_gamesystem"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="gurpscharacter",
|
||||
name="player",
|
||||
field=models.ForeignKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="Campaign",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=255, unique=True)),
|
||||
("description", models.TextField(null=True)),
|
||||
(
|
||||
"game_system",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="gurps_character.gamesystem",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="gurpscharacter",
|
||||
name="campaign",
|
||||
field=models.ForeignKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="gurps_character.campaign",
|
||||
),
|
||||
),
|
||||
]
|
||||
20
gurps_character/migrations/0005_campaign_gm.py
Normal file
20
gurps_character/migrations/0005_campaign_gm.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 5.0.6 on 2024-07-14 09:25
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("gurps_character", "0004_gurpscharacter_player_campaign_and_more"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="campaign",
|
||||
name="gm",
|
||||
field=models.ManyToManyField(to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,49 +1,83 @@
|
|||
from django.db import models
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class GameSystem(models.Model):
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
description = models.TextField(null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class GM(models.Model):
|
||||
gm = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
campaign = models.ForeignKey("Campaign", null=True, on_delete=models.CASCADE, related_name='campaign')
|
||||
|
||||
|
||||
class Player(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
status = models.CharField(max_length=255, unique=True)
|
||||
|
||||
#
|
||||
# class Players(models.Model):
|
||||
# player = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
# status = models.CharField(max_length=255, unique=True)
|
||||
|
||||
|
||||
class Campaign(models.Model):
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
description = models.TextField(null=True)
|
||||
game_system = models.ForeignKey(GameSystem, on_delete=models.CASCADE)
|
||||
gm = models.ManyToManyField('GM', related_name='GM')
|
||||
player = models.ManyToManyField('Player')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class GURPSCharacter(models.Model):
|
||||
uuid = models.CharField(max_length=128, unique=True)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
player = models.ForeignKey(Player, null=True, on_delete=models.CASCADE)
|
||||
campaign = models.ForeignKey(Campaign, null=True, on_delete=models.CASCADE)
|
||||
details = models.JSONField()
|
||||
# owner => user
|
||||
# campaign => campaign
|
||||
|
||||
def __str__(self):
|
||||
return self.name + " Player " + str(self.player) + " Campaign " + str(self.campaign)
|
||||
|
||||
def adv_points(self):
|
||||
return sum([ a['calc']['points'] for a in self.details.get('advantages',[]) if a['calc']['points'] > 0 ])
|
||||
return sum([a['calc']['points'] for a in self.details.get('advantages', []) if a['calc']['points'] > 0])
|
||||
|
||||
def disadv_points(self):
|
||||
return sum([ a['calc']['points'] for a in self.details.get('advantages', []) if a['calc']['points'] < -1 ])
|
||||
return sum([a['calc']['points'] for a in self.details.get('advantages', []) if a['calc']['points'] < -1])
|
||||
|
||||
def quirks_points(self):
|
||||
return sum([ a['calc']['points'] for a in self.details.get('advantages',[]) if a['calc']['points'] == -1 ])
|
||||
return sum([a['calc']['points'] for a in self.details.get('advantages', []) if a['calc']['points'] == -1])
|
||||
|
||||
def attr_points(self):
|
||||
return sum([ a['calc']['points'] for a in self.details['attributes'] ])
|
||||
return sum([a['calc']['points'] for a in self.details['attributes']])
|
||||
|
||||
def skills_points(self):
|
||||
return sum([ s['points'] for s in self.details.get('skills',[]) ])
|
||||
return sum([s['points'] for s in self.details.get('skills', [])])
|
||||
|
||||
def spells_points(self):
|
||||
return 0
|
||||
return sum([s['points'] for s in self.details.get('spells', [])])
|
||||
|
||||
def race_points(self):
|
||||
return 0
|
||||
return sum([s['points'] for s in self.details.get('race', [])]) # Are we sure?
|
||||
|
||||
def unspent_points(self):
|
||||
return self.details['total_points'] - self.adv_points() - \
|
||||
return self.details['total_points'] - self.adv_points() - \
|
||||
self.disadv_points() - self.attr_points() - \
|
||||
self.skills_points() - self.spells_points() - \
|
||||
self.race_points() - self.quirks_points()
|
||||
|
||||
def get_primary_attr(self, attr_id):
|
||||
return [ a['calc'] for a in self.details['attributes'] if a['attr_id'] == attr_id ][0]
|
||||
return [a['calc'] for a in self.details['attributes'] if a['attr_id'] == attr_id][0]
|
||||
|
||||
def st(self):
|
||||
return self.get_primary_attr('st')
|
||||
|
|
@ -91,7 +125,7 @@ class GURPSCharacter(models.Model):
|
|||
return self.get_primary_attr('fp')
|
||||
|
||||
def weight_carried(self):
|
||||
items = [ i['calc']['extended_weight'] for i in self.details['equipment'] ]
|
||||
items = [i['calc']['extended_weight'] for i in self.details['equipment']]
|
||||
|
||||
total_weight = 0
|
||||
for i in items:
|
||||
|
|
@ -116,11 +150,36 @@ class GURPSCharacter(models.Model):
|
|||
dodge = self.details["calc"]["dodge"][0]
|
||||
basic_move = self.basic_move()["value"]
|
||||
return [
|
||||
{ "max_load": round(self.basic_lift()), "move": basic_move, "dodge": dodge, "current": "current" * (enc_level == 0) },
|
||||
{ "max_load": round(self.basic_lift()) * 2, "move": basic_move -2, "dodge": dodge -1, "current": "current" * (enc_level == 1) },
|
||||
{ "max_load": round(self.basic_lift()) * 3, "move": basic_move -3, "dodge": dodge -2, "current": "current" * (enc_level == 2) },
|
||||
{ "max_load": round(self.basic_lift()) * 6, "move": basic_move -4, "dodge": dodge -3, "current": "current" * (enc_level == 3) },
|
||||
{ "max_load": round(self.basic_lift()) * 10, "move": basic_move -5, "dodge": dodge -4, "current": "current" * (enc_level == 4) },
|
||||
{
|
||||
"max_load": round(self.basic_lift()),
|
||||
"move": basic_move,
|
||||
"dodge": dodge,
|
||||
"current": "current" * (enc_level == 0)
|
||||
},
|
||||
{
|
||||
"max_load": round(self.basic_lift()) * 2,
|
||||
"move": basic_move - 2,
|
||||
"dodge": dodge - 1,
|
||||
"current": "current" * (enc_level == 1)
|
||||
},
|
||||
{
|
||||
"max_load": round(self.basic_lift()) * 3,
|
||||
"move": basic_move - 3,
|
||||
"dodge": dodge - 2,
|
||||
"current": "current" * (enc_level == 2)
|
||||
},
|
||||
{
|
||||
"max_load": round(self.basic_lift()) * 6,
|
||||
"move": basic_move - 4,
|
||||
"dodge": dodge - 3,
|
||||
"current": "current" * (enc_level == 3)
|
||||
},
|
||||
{
|
||||
"max_load": round(self.basic_lift()) * 10,
|
||||
"move": basic_move - 5,
|
||||
"dodge": dodge - 4,
|
||||
"current": "current" * (enc_level == 4)
|
||||
},
|
||||
]
|
||||
|
||||
def basic_lift(self):
|
||||
|
|
@ -131,25 +190,26 @@ class GURPSCharacter(models.Model):
|
|||
|
||||
def lift_table(self):
|
||||
return [
|
||||
{"value": round(self.basic_lift()), "label":"Basic Lift"},
|
||||
{"value": round(self.basic_lift()) * 2, "label": "One-Handed Lift" },
|
||||
{"value": round(self.basic_lift()) * 8, "label":"Two-Handed Lift"},
|
||||
{"value": round(self.basic_lift()) * 12, "label":"Shove &ersand; Knock Over"},
|
||||
{"value": round(self.basic_lift()) * 24, "label":"Running Shove & Knock Over"},
|
||||
{"value": round(self.basic_lift()) * 15, "label":"Carry on Back"},
|
||||
{"value": round(self.basic_lift()) * 50, "label":"Shift Slightly"},
|
||||
{"value": round(self.basic_lift()), "label": "Basic Lift"},
|
||||
{"value": round(self.basic_lift()) * 2, "label": "One-Handed Lift"},
|
||||
{"value": round(self.basic_lift()) * 8, "label": "Two-Handed Lift"},
|
||||
{"value": round(self.basic_lift()) * 12, "label": "Shove &ersand; Knock Over"},
|
||||
{"value": round(self.basic_lift()) * 24, "label": "Running Shove & Knock Over"},
|
||||
{"value": round(self.basic_lift()) * 15, "label": "Carry on Back"},
|
||||
{"value": round(self.basic_lift()) * 50, "label": "Shift Slightly"},
|
||||
]
|
||||
|
||||
def reaction_modifiers(self):
|
||||
modifiers = []
|
||||
|
||||
for a in self.details.get('advantages',[]):
|
||||
for a in self.details.get('advantages', []):
|
||||
if "features" in a:
|
||||
for f in a["features"]:
|
||||
if f["type"] == "reaction_bonus":
|
||||
modifiers.append(f)
|
||||
|
||||
return modifiers
|
||||
|
||||
def conditional_modifiers(self):
|
||||
modifiers = []
|
||||
|
||||
|
|
@ -162,10 +222,10 @@ class GURPSCharacter(models.Model):
|
|||
return modifiers
|
||||
|
||||
def weapons(self):
|
||||
return [ w for w in self.details['equipment'] if "weapons" in w] + \
|
||||
[ a for a in self.details.get("advantages",[]) if "weapons" in a ] + \
|
||||
[ a for a in self.details.get("traits",[]) if "weapons" in a ] + \
|
||||
[ s for s in self.details.get("spells", []) if "weapons" in s ]
|
||||
return [w for w in self.details['equipment'] if "weapons" in w] + \
|
||||
[a for a in self.details.get("advantages", []) if "weapons" in a] + \
|
||||
[a for a in self.details.get("traits", []) if "weapons" in a] + \
|
||||
[s for s in self.details.get("spells", []) if "weapons" in s]
|
||||
|
||||
def melee_weapons(self):
|
||||
mw = []
|
||||
|
|
@ -178,14 +238,14 @@ class GURPSCharacter(models.Model):
|
|||
name = item["name"]
|
||||
mw.append(
|
||||
{
|
||||
"name":name,
|
||||
"name": name,
|
||||
"usage": weapon["usage"],
|
||||
"skill_level":weapon["calc"].get("level", 0),
|
||||
"parry":weapon["calc"].get("parry", "No"),
|
||||
"block":weapon["calc"].get("block", "No"),
|
||||
"damage":weapon["calc"]["damage"],
|
||||
"reach":weapon["calc"].get("reach", ""),
|
||||
"strength":weapon.get("strength", " ")
|
||||
"skill_level": weapon["calc"].get("level", 0),
|
||||
"parry": weapon["calc"].get("parry", "No"),
|
||||
"block": weapon["calc"].get("block", "No"),
|
||||
"damage": weapon["calc"]["damage"],
|
||||
"reach": weapon["calc"].get("reach", ""),
|
||||
"strength": weapon.get("strength", " ")
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -207,7 +267,6 @@ class GURPSCharacter(models.Model):
|
|||
else:
|
||||
return wpn_range
|
||||
|
||||
|
||||
rw = []
|
||||
for item in self.weapons():
|
||||
for weapon in item["weapons"]:
|
||||
|
|
@ -218,13 +277,13 @@ class GURPSCharacter(models.Model):
|
|||
name = item["name"]
|
||||
rw.append(
|
||||
{
|
||||
"name":name,
|
||||
"name": name,
|
||||
"bulk": weapon.get("bulk", " "),
|
||||
"usage": weapon.get("usage", " "),
|
||||
"skill_level":weapon["calc"]["level"],
|
||||
"damage":weapon["calc"]["damage"],
|
||||
"strength":weapon.get("strength", " "),
|
||||
"acc":weapon.get("accuracy", 0),
|
||||
"skill_level": weapon["calc"]["level"],
|
||||
"damage": weapon["calc"]["damage"],
|
||||
"strength": weapon.get("strength", " "),
|
||||
"acc": weapon.get("accuracy", 0),
|
||||
"range": muscle_range(weapon.get("range", " ")),
|
||||
"rof": weapon.get("rate_of_fire", " "),
|
||||
"shots": weapon.get("shots", " "),
|
||||
|
|
@ -236,12 +295,12 @@ class GURPSCharacter(models.Model):
|
|||
|
||||
def traits(self):
|
||||
traits = []
|
||||
for advantage in self.details.get("advantages",[]):
|
||||
for advantage in self.details.get("advantages", []):
|
||||
cost = advantage["calc"]["points"]
|
||||
name = advantage["name"]
|
||||
|
||||
if "categories" in advantage and "Language" in advantage["categories"]:
|
||||
levels = [ m for m in advantage['modifiers'] if "disabled" not in m ]
|
||||
levels = [m for m in advantage['modifiers'] if "disabled" not in m]
|
||||
|
||||
notes = ""
|
||||
for level in levels:
|
||||
|
|
@ -256,24 +315,24 @@ class GURPSCharacter(models.Model):
|
|||
elif "notes" in advantage:
|
||||
notes = advantage["notes"]
|
||||
elif "modifiers" in advantage:
|
||||
notes = [ m for m in advantage['modifiers'] if m["cost"] == cost ][0]["name"]
|
||||
notes = [m for m in advantage['modifiers'] if m["cost"] == cost][0]["name"]
|
||||
else:
|
||||
notes = ""
|
||||
|
||||
traits.append({"name":name, "notes":notes, "points":cost, "reference":advantage["reference"]})
|
||||
traits.append({"name": name, "notes": notes, "points": cost, "reference": advantage["reference"]})
|
||||
|
||||
return traits
|
||||
|
||||
def spells(self):
|
||||
def get_casting_details(spell):
|
||||
level = spell['calc']['level']
|
||||
def get_casting_details(spell_details):
|
||||
level = spell_details['calc']['level']
|
||||
|
||||
if level < 10:
|
||||
descr = (
|
||||
"Ritual: Need both hands and both feet "
|
||||
"free, and must speak .Time: 2x."
|
||||
)
|
||||
elif level <15:
|
||||
elif level < 15:
|
||||
descr = (
|
||||
"Ritual: Must speak a few quiet words "
|
||||
"and make a gesture."
|
||||
|
|
@ -287,13 +346,13 @@ class GURPSCharacter(models.Model):
|
|||
elif level < 25:
|
||||
descr = "Ritual: None. Time: / 2 (round up). Cost: -2."
|
||||
elif level < 30:
|
||||
descr = (
|
||||
descr = (
|
||||
"Ritual: None. Time: / 4 (round up). Cost: -3."
|
||||
)
|
||||
else:
|
||||
delta = int((level - 25) / 5)
|
||||
power = 2 + delta
|
||||
divisor = 2**power
|
||||
# divisor = 2**power
|
||||
cost = 3 + delta
|
||||
descr = (
|
||||
f"Ritual: None. Time: / {power} round up. Cost: "
|
||||
|
|
@ -302,56 +361,62 @@ class GURPSCharacter(models.Model):
|
|||
|
||||
return descr
|
||||
|
||||
|
||||
spells = []
|
||||
for spell in self.details.get('spells',[]):
|
||||
for spell in self.details.get('spells', []):
|
||||
notes = (
|
||||
f"{get_casting_details(spell)}<br> Class: {spell['spell_class']}; "
|
||||
f"Cost: {spell['casting_cost']}; Maintain: {spell['maintenance_cost']}; Time: {spell['casting_time']}; Duration: {spell['duration']}; "
|
||||
f"Cost: {spell['casting_cost']}; Maintain: {spell['maintenance_cost']};"
|
||||
f" Time: {spell['casting_time']}; Duration: {spell['duration']}; "
|
||||
)
|
||||
spells.append(
|
||||
{
|
||||
'name': spell["name"],
|
||||
"college":", ".join(spell["college"]),
|
||||
"college": ", ".join(spell["college"]),
|
||||
"level": spell["calc"]["level"],
|
||||
"rsl":spell["calc"]["rsl"],
|
||||
"points":spell["points"],
|
||||
"reference":spell["reference"],
|
||||
"notes":notes
|
||||
"rsl": spell["calc"]["rsl"],
|
||||
"points": spell["points"],
|
||||
"reference": spell["reference"],
|
||||
"notes": notes
|
||||
}
|
||||
)
|
||||
return spells
|
||||
|
||||
def skills(self):
|
||||
skills = []
|
||||
for skill in self.details.get('skills',[]):
|
||||
skills.append({'name': skill["name"], "level": skill["calc"]["level"], "rsl":skill["calc"]["rsl"], "points":skill["points"], "reference":skill["reference"] })
|
||||
for skill in self.details.get('skills', []):
|
||||
skills.append({
|
||||
'name': skill["name"],
|
||||
"level": skill["calc"]["level"],
|
||||
"rsl": skill["calc"]["rsl"],
|
||||
"points": skill["points"],
|
||||
"reference": skill["reference"]
|
||||
})
|
||||
return skills
|
||||
|
||||
def equipment(self):
|
||||
def get_children(parent, level=1):
|
||||
children = []
|
||||
|
||||
for item in parent["children"]:
|
||||
equipment = {
|
||||
"name": item["description"],
|
||||
"uses":"",
|
||||
"tech_level":item["tech_level"],
|
||||
"lc":"",
|
||||
"value":item["value"],
|
||||
"weight":item["weight"],
|
||||
"quantity":item.get("quantity",1),
|
||||
"ref":item["reference"],
|
||||
"ext_weight": item["calc"]["extended_weight"],
|
||||
"ext_value": item["calc"]["extended_value"],
|
||||
"notes": item.get("notes",""),
|
||||
"equipped": item["equipped"],
|
||||
for item_details in parent["children"]:
|
||||
equipment_details = {
|
||||
"name": item_details["description"],
|
||||
"uses": "",
|
||||
"tech_level": item_details["tech_level"],
|
||||
"lc": "",
|
||||
"value": item_details["value"],
|
||||
"weight": item_details["weight"],
|
||||
"quantity": item_details.get("quantity", 1),
|
||||
"ref": item_details["reference"],
|
||||
"ext_weight": item_details["calc"]["extended_weight"],
|
||||
"ext_value": item_details["calc"]["extended_value"],
|
||||
"notes": item_details.get("notes", ""),
|
||||
"equipped": item_details["equipped"],
|
||||
"level": level
|
||||
}
|
||||
children.append(equipment)
|
||||
children.append(equipment_details)
|
||||
|
||||
if "children" in item:
|
||||
children += get_children(item, level +1)
|
||||
if "children" in item_details:
|
||||
children += get_children(item_details, level + 1)
|
||||
|
||||
return children
|
||||
equipment = self.details['equipment']
|
||||
|
|
@ -361,17 +426,17 @@ class GURPSCharacter(models.Model):
|
|||
equipment_list.append(
|
||||
{
|
||||
"name": item["description"],
|
||||
"uses":"",
|
||||
"tech_level":item["tech_level"],
|
||||
"lc":"",
|
||||
"uses": "",
|
||||
"tech_level": item["tech_level"],
|
||||
"lc": "",
|
||||
"level": 0,
|
||||
"value":item["value"],
|
||||
"weight":item["weight"],
|
||||
"quantity":item.get("quantity",1),
|
||||
"ref":item.get("reference",""),
|
||||
"value": item["value"],
|
||||
"weight": item["weight"],
|
||||
"quantity": item.get("quantity", 1),
|
||||
"ref": item.get("reference", ""),
|
||||
"ext_weight": item["calc"]["extended_weight"],
|
||||
"ext_value": item["calc"]["extended_value"],
|
||||
"notes": item.get("notes",""),
|
||||
"notes": item.get("notes", ""),
|
||||
"equipped": item["equipped"]
|
||||
}
|
||||
)
|
||||
|
|
@ -388,4 +453,3 @@ class GURPSCharacter(models.Model):
|
|||
except KeyError:
|
||||
# v4
|
||||
return self.details["settings"]["body_type"]["locations"]
|
||||
|
||||
|
|
|
|||
89
gurps_character/templates/allauth/layouts/base.html
Normal file
89
gurps_character/templates/allauth/layouts/base.html
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
{% load i18n %}
|
||||
{% load bootstrap_icons %}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>
|
||||
{% block head_title %}
|
||||
{% endblock head_title %}
|
||||
</title>
|
||||
{% block extra_head %}
|
||||
{% endblock extra_head %}
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
</head>
|
||||
...
|
||||
</head>
|
||||
<body class="bg-gray-50 font-serif leading-normal tracking-normal">
|
||||
{% block body %}
|
||||
{% include "navbar.html" %}
|
||||
{% if messages %}
|
||||
<div>
|
||||
<strong>{% trans "Messages:" %}</strong>
|
||||
<ul>
|
||||
{% for message in messages %}<li>{{ message }}</li>{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="container mx-auto">
|
||||
<section class="flex items-center justify-center h-screen">
|
||||
Modified template
|
||||
<strong>{% trans "Menu:" %}</strong>
|
||||
<ul>
|
||||
{% if user.is_authenticated %}
|
||||
{% url 'account_email' as email_url %}
|
||||
{% if email_url %}
|
||||
<li>
|
||||
<a href="{{ email_url }}">{% trans "Change Email" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% url 'account_change_password' as change_password_url %}
|
||||
{% if change_password_url %}
|
||||
<li>
|
||||
<a href="{{ change_password_url }}">{% trans "Change Password" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% url 'mfa_index' as mfa_url %}
|
||||
{% if mfa_url %}
|
||||
<li>
|
||||
<a href="{{ mfa_url }}">{% trans "Two-Factor Authentication" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% url 'usersessions_list' as usersessions_list_url %}
|
||||
{% if usersessions_list_url %}
|
||||
<li>
|
||||
<a href="{{ usersessions_list_url }}">{% trans "Sessions" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% url 'account_logout' as logout_url %}
|
||||
{% if logout_url %}
|
||||
<li>
|
||||
<a href="{{ logout_url }}">{% trans "Sign Out" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% url 'account_login' as login_url %}
|
||||
{% if login_url %}
|
||||
<li>
|
||||
<a href="{{ login_url }}">{% trans "Sign In" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% url 'account_signup' as signup_url %}
|
||||
{% if signup_url %}
|
||||
<li>
|
||||
<a href="{{ signup_url }}">{% trans "Sign Up" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% block content %}
|
||||
{% endblock content %}
|
||||
</section>
|
||||
</div>
|
||||
{% endblock body %}
|
||||
{% block extra_body %}
|
||||
{% endblock extra_body %}
|
||||
</body>
|
||||
</html>
|
||||
27
gurps_character/templates/base.html
Normal file
27
gurps_character/templates/base.html
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Django GURPS</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
<style>
|
||||
a { text-decoration: underline }
|
||||
</style>
|
||||
{% block extra_css %}{% endblock %}
|
||||
|
||||
</head>
|
||||
|
||||
<body class="bg-gray-50 font-serif leading-normal tracking-normal">
|
||||
<!--- Start Nav Bar -->
|
||||
{% include "navbar.html" %}
|
||||
<!--- End Nav Bar --->
|
||||
<div class="container mx-auto">
|
||||
<section class="flex items-center justify-center h-screen">
|
||||
{% block content %}{% endblock %}
|
||||
</section>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,8 +1,37 @@
|
|||
{% extends "base.html" %}
|
||||
{% load bootstrap_icons %}
|
||||
{% block content %}
|
||||
<h3>Welcome to the character store</h3>
|
||||
<h3>Welcome to the character store</h3>
|
||||
|
||||
<p<This is a webapp for storing characters.<p>
|
||||
<p>This is a webapp for storing characters.</p>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<h1>Welcome {% if user.first_name %}{{ user.first_name }}{% else %}{{ user.username }}{% endif %}</h1>
|
||||
|
||||
{% if user.campaign_set.all %}
|
||||
<h2>Campaigns you run</h2>
|
||||
<ul>
|
||||
{% for campaign in user.campaign_set.all %}
|
||||
<li><a href="{% url 'campaign' campaign.id %}">{{ campaign.name }}</a></li>
|
||||
{% endfor %}
|
||||
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
<h2>Characters you play</h2>
|
||||
<ul>
|
||||
{% for character in user.gurpscharacter_set.all %}
|
||||
<li>
|
||||
{{ character.name }} in {{ character.campaign }}
|
||||
<a href="{% url 'details' character.uuid %}" title="view {{ character.name }}">{% bs_icon 'eye' %}</a>
|
||||
<a href="{% url 'download' character.uuid %}" title="download {{ character.name }}">{% bs_icon 'download' %}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>Please sign in to see your characters and campaigns</p>
|
||||
{% endif %}
|
||||
Add a character?
|
||||
|
||||
<p>Currently it works with GURPS, specifically characters created by GCS</p>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="#">Navbar</a>
|
||||
<a class="navbar-brand" href="/">Character Database</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item"><a class="nav-link active" aria-current="page" href="/">Home</a></li>
|
||||
<li class="nav-item"><a class="nav-link active" aria-current="page" href="/gurps">GURPS</a></li>
|
||||
<li class="nav-item"><a class="nav-link disabled" aria-current="page" href="/rq">RuneQuest</a></li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/admin">Admin</a>
|
||||
</li>
|
||||
{% if user.is_staff %}
|
||||
{# <li class="nav-item"><a class="nav-link active" aria-current="page" href="/gurps">GURPS</a></li>#}
|
||||
{# <li class="nav-item"><a class="nav-link disabled" aria-current="page" href="/rq">RuneQuest</a></li>#}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/admin">Admin</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<!--<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Dropdown
|
||||
|
|
@ -35,14 +36,21 @@
|
|||
|
||||
</div>
|
||||
<div class="navbar-text float-end">
|
||||
{% if user.is_authenticated %}
|
||||
<form method="post" action="{% url 'logout' %}">
|
||||
{% csrf_token %}
|
||||
<button type="submit">logout</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<a class="nav-link" href="{% url 'login' %}">Login</a>
|
||||
{% endif %}
|
||||
{% if user.is_authenticated %}
|
||||
{% url 'account_email' as email_url %}
|
||||
{% url 'socialaccount_connections' as socialaccount_url %}
|
||||
{% if email_url or socialaccount_url %}
|
||||
<a href="{% if email_url %}{{ email_url }}{% else %}{{ socialaccount_url }}{% endif %}"
|
||||
class="btn btn-secondary">Manage Account</a>
|
||||
{% endif %}
|
||||
<a href="{% url 'account_logout' %}" class="btn btn-danger">Sign Out </a>
|
||||
{% else %}
|
||||
<a href="{% url 'account_login' %}" class="btn btn-outline-light">Sign In</a>
|
||||
{% url 'account_signup' as signup_url %}
|
||||
{% if signup_url %}
|
||||
<a href="{{ signup_url }}" class="btn btn-success">Sign Up</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
|
|||
|
|
@ -7,4 +7,6 @@ urlpatterns = [
|
|||
path("details/<str:uuid>/", views.details, name="details"),
|
||||
path("upload", views.upload_file, name="upload"),
|
||||
path("download/<str:uuid>/", views.download, name="download"),
|
||||
path("character/<str:uuid>/", views.character, name="character"),
|
||||
path("campaign/<str:uuid>", views.campaign, name="campaign"),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ from django.urls import reverse
|
|||
from .models import GURPSCharacter
|
||||
from .forms import UploadFileForm
|
||||
|
||||
|
||||
def index(request):
|
||||
characters = GURPSCharacter.objects.all()
|
||||
context = {"characters":characters}
|
||||
context = {"characters": characters}
|
||||
|
||||
if request.method == "POST":
|
||||
form = UploadFileForm(request.POST, request.FILES)
|
||||
|
|
@ -22,11 +23,11 @@ def index(request):
|
|||
context['form'] = form
|
||||
return render(request, "characters/list.html", context)
|
||||
|
||||
|
||||
def details(request, uuid):
|
||||
character = GURPSCharacter.objects.get(uuid=uuid)
|
||||
|
||||
context = {"character": character}
|
||||
#import bpdb;bpdb.set_trace()
|
||||
|
||||
return render(request, "characters/embedded.html", context)
|
||||
|
||||
|
|
@ -41,27 +42,37 @@ def upload_file(request):
|
|||
form = UploadFileForm()
|
||||
return render(request, "characters/upload.html", {"form": form})
|
||||
|
||||
|
||||
def handle_uploaded_file(f):
|
||||
import bpdb;bpdb.set_trace()
|
||||
f.seek(0) # We read the file in the validator
|
||||
f.seek(0) # We read the file in the validator
|
||||
data = json.loads(f.read())
|
||||
|
||||
uuid = data['id']
|
||||
name = data["profile"]["name"]
|
||||
|
||||
|
||||
try:
|
||||
character = GURPSCharacter.objects.get(uuid=uuid)
|
||||
character.details = data
|
||||
character.name = name
|
||||
character.save()
|
||||
except GURPSCharacter.DoesNotExist:
|
||||
character = GURPSCharacter(uuid=uuid, name=name, details = data)
|
||||
character = GURPSCharacter(uuid=uuid, name=name, details=data)
|
||||
character.save()
|
||||
|
||||
def download(irequest, uuid):
|
||||
|
||||
def download(request, uuid):
|
||||
mime_type = "application/x-gcs-gcs"
|
||||
character = GURPSCharacter.objects.get(uuid=uuid)
|
||||
response = HttpResponse(json.dumps(character.details), content_type=mime_type)
|
||||
response['Content-Disposition'] = "attachment; filename=%s.gcs" % character.name
|
||||
return response
|
||||
|
||||
|
||||
def character(request, uuid):
|
||||
response = HttpResponse("Charcater")
|
||||
return response
|
||||
|
||||
|
||||
def campaign(request, uuid):
|
||||
response = HttpResponse("Campaign")
|
||||
return response
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue