This commit is contained in:
sladecraven 2022-01-07 20:40:40 +01:00
parent a8a27d1924
commit f3bc082e8c
13 changed files with 309 additions and 30 deletions

View File

@ -477,10 +477,24 @@ export class PegasusActor extends Actor {
}
}
/* -------------------------------------------- */
async deleteAllItemsByType( itemType) {
let items = this.data.items.filter( item => item.type == itemType);
await this.deleteEmbeddedDocuments( 'Item', items);
}
/* -------------------------------------------- */
async modStat( key, inc=1) {
let stat = duplicate(this.data.data.statistics[key])
stat.mod += parseInt(inc)
await this.update( { [`data.statistics.${key}`] : stat } )
}
/* -------------------------------------------- */
async applyRace( race ) {
let updates = { 'data.racename':race.name }
let newItems = []
await this.deleteAllItemsByType( 'race')
newItems.push(race);
for (let ability of race.data.abilities) {
@ -501,8 +515,26 @@ export class PegasusActor extends Actor {
}
/* -------------------------------------------- */
applyRole( role ) {
getIncreaseStatValue( updates, statKey) {
let stat = duplicate(this.data.data.statistics[statKey])
stat.value += 1;
updates[`data.statistics.${statKey}`] = stat
}
/* -------------------------------------------- */
async applyRole( role ) {
console.log("ROLE", role)
let updates = { 'data.rolename': role.name }
let newItems = []
await this.deleteAllItemsByType( 'role')
newItems.push(role);
this.getIncreaseStatValue( updates, role.data.statincrease1)
this.getIncreaseStatValue( updates, role.data.statincrease2)
await this.update( updates )
await this.createEmbeddedDocuments('Item', newItems)
}
/* -------------------------------------------- */

View File

@ -27,7 +27,14 @@ export class PegasusActorCreate {
img: this.actor.img,
step: step,
races: this.races,
roles: this.roles
roles: this.roles,
nboptionnal: this.raceOptionnalAbilities?.nboptionnal?? 0,
optionnalabilities: this.raceOptionnalAbilities?.optionnalabilities?? [],
}
if ( this.raceSelectableStats ) {
formData.numberstats = this.raceSelectableStats.numberstats;
formData.statsonlyonce = this.raceSelectableStats.statsonlyonce;
formData.stats = this.raceSelectableStats.stats;
}
return formData;
}
@ -39,8 +46,103 @@ export class PegasusActorCreate {
console.log("Create chat evet", event, itemId, step)
if ( step == "select-race") {
let race = this.races.find( item => item._id == itemId);
this.actor.applyRace( race)
this.actor.applyRace( race);
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
if ( race.data.nboptionnal > 0 && race.data.optionnalabilities.length > 0) {
this.manageOptionnalAbilities(race);
} else {
if ( race.data.selectablestats ) {
this.manageSelectableStats(race);
} else {
this.showRoles()
}
}
}
if ( step == 'select-race-optionnal') {
let ability = this.raceOptionnalAbilities.optionnalabilities.find( item => item._id == itemId);
this.actor.createEmbeddedDocuments( 'Item', [ability]);
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
this.raceOptionnalAbilities.optionnalabilities = this.raceOptionnalAbilities.optionnalabilities.filter( item => item._id != itemId);
this.raceOptionnalAbilities.nboptionnal -= 1;
this.processOptionnalAbilitiesStep();
}
if (step == 'select-race-stats') {
let statKey = $(event.currentTarget).data("stat-key");
this.actor.modStat( statKey, 1);
this.raceSelectableStats.stats[statKey].used = true;
this.raceSelectableStats.numberstats -=1;
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
this.processSelectableStats();
}
if ( step == 'select-role') {
let role = this.roles.find( item => item._id == itemId);
this.actor.applyRole( role );
}
}
/* -------------------------------------------- */
manageSelectableStats( race ) {
this.raceSelectableStats = {
"race": race,
"statsonlyonce": race.data.statsonlyonce,
"numberstats": race.data.numberstats,
"stats": duplicate(this.actor.data.data.statistics)
}
this.processSelectableStats()
}
/* --------------- ----------------------------- */
async processSelectableStats() {
// End of race options choice
if ( this.raceSelectableStats.numberstats == 0) {
this.showRoles()
return;
}
let formData = this.createFormData("select-race-stats")
let chatData = {
user: game.user.id,
alias : this.actor.name,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat( ChatMessage.getWhisperRecipients('GM') ),
content: await renderTemplate('systems/fvtt-pegasus-rpg/templates/chat-create-actor.html', formData)
};
//console.log("Apply damage chat", chatData );
await ChatMessage.create( chatData );
}
/* --------------- ----------------------------- */
manageOptionnalAbilities( race) {
this.raceOptionnalAbilities = {
"nboptionnal": race.data.nboptionnal,
"optionnalabilities": duplicate(race.data.optionnalabilities),
}
this.processOptionnalAbilitiesStep()
}
/* -------------------------------------------- */
async processOptionnalAbilitiesStep() {
// End of race options choice
if ( this.raceOptionnalAbilities.nboptionnal == 0) {
if ( this.raceSelectableStats ) {
this.manageSelectableStats(this.raceSelectableStats.race);
} else {
this.showRoles()
}
}
let formData = this.createFormData("select-race-optionnal")
let chatData = {
user: game.user.id,
alias : this.actor.name,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat( ChatMessage.getWhisperRecipients('GM') ),
content: await renderTemplate('systems/fvtt-pegasus-rpg/templates/chat-create-actor.html', formData)
};
//console.log("Apply damage chat", chatData );
await ChatMessage.create( chatData );
}
/* -------------------------------------------- */
@ -59,8 +161,14 @@ export class PegasusActorCreate {
/* -------------------------------------------- */
async showRoles() {
console.log("Available roles", roles);
// TODO : display buttons
let formData = this.createFormData("select-role")
let chatData = {
user: game.user.id,
alias : this.actor.name,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat( ChatMessage.getWhisperRecipients('GM') ),
content: await renderTemplate('systems/fvtt-pegasus-rpg/templates/chat-create-actor.html', formData)
};
await ChatMessage.create( chatData );
}
}

View File

@ -207,14 +207,22 @@ export class PegasusItemSheet extends ItemSheet {
return item;
}
/* -------------------------------------------- */
async addAbility(item, dataItem) {
let abilityArray = duplicate(this.object.data.data.abilities);
async addAbility(event, item, dataItem) {
let newItem = duplicate(item.data);
newItem._id = randomID( dataItem.id.length );
abilityArray.push( newItem);
await this.object.update( { 'data.abilities': abilityArray} );
console.log("ABB", event, item, dataItem)
if ( event.toElement.className == 'drop-abilities') {
let abilityArray = duplicate(this.object.data.data.abilities);
abilityArray.push( newItem);
await this.object.update( { 'data.abilities': abilityArray} );
}
if ( event.toElement.className == 'drop-optionnal-abilities') {
let abilityArray = duplicate(this.object.data.data.optionnalabilities);
abilityArray.push( newItem);
await this.object.update( { 'data.optionnalabilities': abilityArray} );
}
}
/* -------------------------------------------- */
async addSpecialisation(item, dataItem) {
let newItem = duplicate(item.data);
@ -306,13 +314,13 @@ export class PegasusItemSheet extends ItemSheet {
/* -------------------------------------------- */
async _onDrop(event) {
//console.log(event);
if (this.object.type == 'race' ) {
if (this.object.type == 'race' ) {
let data = event.dataTransfer.getData('text/plain');
if (data) {
let dataItem = JSON.parse( data );
let item = await this.searchItem( dataItem);
if ( item.data.type == 'ability') {
return this.addAbility( item, dataItem);
return this.addAbility( event, item, dataItem);
}
}
}

View File

@ -3,7 +3,7 @@ import { PegasusUtility } from "./pegasus-utility.js";
export const defaultItemImg = {
specialisation: "systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp",
perk: "systems/fvtt-pegasus-rpg/images/icons/icon_perk.webp",
ability: "systems/fvtt-pegasus-rpg/images/icons/icon_ability.webp",
ability: "systems/fvtt-pegasus-rpg/images/icons/icon_raceability.webp",
armor: "systems/fvtt-pegasus-rpg/images/icons/icon_armor.webp",
weapon: "systems/fvtt-pegasus-rpg/images/icons/icon_weapon.webp",
equipment: "systems/fvtt-pegasus-rpg/images/icons/icon_equipment.webp",

View File

@ -137,6 +137,35 @@ export class PegasusUtility {
return loadTemplates(templatePaths);
}
/* -------------------------------------------- */
static removeChatMessageId(messageId) {
if (messageId){
game.messages.get(messageId)?.delete();
}
}
static findChatMessageId(current) {
return PegasusUtility.getChatMessageId(PegasusUtility.findChatMessage(current));
}
static getChatMessageId(node) {
return node?.attributes.getNamedItem('data-message-id')?.value;
}
static findChatMessage(current) {
return PegasusUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'));
}
static findNodeMatching(current, predicate) {
if (current) {
if (predicate(current)) {
return current;
}
return PegasusUtility.findNodeMatching(current.parentElement, predicate);
}
return undefined;
}
/* -------------------------------------------- */
static templateData(it) {
return PegasusUtility.data(it)?.data ?? {}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -44,7 +44,7 @@
{"_id":"dj3C9tFq5PKJ9t9x","name":"Endurance [PHY]","type":"specialisation","img":"systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp","data":{"statistic":"phy","level":1,"ispowergroup":false,"powersource":"","powers":[],"description":"<p><span style=\"color: #191813; font-size: 12.8px; letter-spacing: 1px; text-align: justify;\">See Pegasus Engine CORE RPG</span></p>"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"iNL4aGohJ8v6YrUk":3},"flags":{}}
{"_id":"e13r56dJ1LYnUHve","name":"Initiative [MR] *requires MR*","type":"specialisation","img":"systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp","data":{"statistic":"agi","level":1,"ispowergroup":false,"powersource":"","powers":[],"description":"<p><span style=\"color: #191813; font-size: 12.8px; letter-spacing: 1px; text-align: justify;\">See Pegasus Engine CORE RPG</span></p>"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"iNL4aGohJ8v6YrUk":3},"flags":{}}
{"_id":"enBLBr5wOfUF4Nb0","name":"Driving [AGI]","type":"specialisation","img":"systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp","data":{"statistic":"agi","level":1,"ispowergroup":false,"powersource":"","powers":[],"description":"<p><span style=\"color: #191813; font-size: 12.8px; letter-spacing: 1px; text-align: justify;\">See Pegasus Engine CORE RPG</span></p>"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"iNL4aGohJ8v6YrUk":3},"flags":{}}
{"_id":"fnvq4eGEhS2ziGUa","name":"Illusionist [MND]","type":"specialisation","img":"systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp","data":{"statistic":"mnd","level":1,"ispowergroup":true,"powersource":"","powers":[],"description":"<p><span style=\"color: #191813; font-size: 12.8px; letter-spacing: 1px; text-align: justify;\">See Pegasus Engine CORE RPG</span></p>","MR":0},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"iNL4aGohJ8v6YrUk":3},"flags":{}}
{"_id":"fnvq4eGEhS2ziGUa","name":"Illusion [MND]","type":"specialisation","img":"systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp","data":{"statistic":"mnd","level":1,"ispowergroup":true,"powersource":"","powers":[],"description":"<p><span style=\"color: #191813; font-size: 12.8px; letter-spacing: 1px; text-align: justify;\">See Pegasus Engine CORE RPG</span></p>"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"iNL4aGohJ8v6YrUk":3},"flags":{}}
{"_id":"h65ID9PFleXY2iXJ","name":"Track [PER]","type":"specialisation","img":"systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp","data":{"statistic":"per","level":1,"ispowergroup":false,"powersource":"","powers":[],"description":"<p><span style=\"color: #191813; font-size: 12.8px; letter-spacing: 1px; text-align: justify;\">See Pegasus Engine CORE RPG</span></p>"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"iNL4aGohJ8v6YrUk":3},"flags":{}}
{"_id":"h8QppkFNsguuRupJ","name":"Taunt [SOC]","type":"specialisation","img":"systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp","data":{"statistic":"soc","level":1,"ispowergroup":false,"powersource":"","powers":[],"description":"<p><span style=\"color: #191813; font-size: 12.8px; letter-spacing: 1px; text-align: justify;\">See Pegasus Engine CORE RPG</span></p>"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"iNL4aGohJ8v6YrUk":3},"flags":{}}
{"_id":"id44rFWhRLazyAwl","name":"Arcane Lore [MND]","type":"specialisation","img":"systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp","data":{"statistic":"mnd","level":1,"ispowergroup":false,"powersource":"","powers":[],"description":"<p><span style=\"color: #191813; font-size: 12.8px; letter-spacing: 1px; text-align: justify;\">See Pegasus Engine CORE RPG</span></p>"},"effects":[],"folder":null,"sort":0,"permission":{"default":0,"iNL4aGohJ8v6YrUk":3},"flags":{}}

View File

@ -177,6 +177,10 @@ table {border: 1px solid #7a7971;}
text-align: center;
}
.table-create-actor {
font-size: 0.8rem;
}
.flex-between {
-webkit-box-pack: justify;
-ms-flex-pack: justify;
@ -1161,6 +1165,7 @@ ul, li {
.drop-ability-spec,
.drop-spec-power,
.drop-abilities,
.drop-optionnal-abilities,
.drop-specialperk1,
.drop-perk2,
.drop-spec1 ,

View File

@ -100,9 +100,9 @@
"styles": [
"styles/simple.css"
],
"templateVersion": 30,
"templateVersion": 33,
"title": "Pegasus RPG",
"url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg",
"version": "0.0.30",
"version": "0.0.33",
"background" : "./images/ui/pegasus_welcome_page.webp"
}

View File

@ -22,7 +22,8 @@
"cdp": 0,
"notes": "",
"gmnotes": "",
"racename": ""
"racename": "",
"rolename": ""
}
},
"core": {
@ -146,7 +147,12 @@
"environment": "",
"society_culture": "",
"outlook": "",
"selectablestats": false,
"statsonlyonce": false,
"numberstats": 0,
"abilities": [],
"optionnalabilities": [],
"nboptionnal": 0,
"statistics": ""
},
"role": {

View File

@ -7,11 +7,67 @@
<div class="flexcol">
{{#if (eq step "select-race")}}
{{#each races as |race index|}}
<span class="flexrow">
{{race.name}} : <a class="chat-card-button chat-create-actor" data-step-name="{{@root.step}}" data-item-id="{{race._id}}" >Select it !</a>
</span>
<div>Select a race from the list below</div>
<table class="table-create-actor">
{{#each races as |race index|}}
<tr>
<td>{{race.name}}</td>
<td><a class="chat-card-button chat-create-actor" data-step-name="{{@root.step}}" data-item-id="{{race._id}}" >Select it !</a></td>
</tr>
{{/each}}
</table>
{{/if}}
{{#if (eq step "select-race-optionnal")}}
<div>The selected Race has some optionnal abilities. Select one ability by clicking the relevant button below<br>
Remaining abilities to select : {{nboptionnal}}
</div>
<table class="table-create-actor">
{{#each optionnalabilities as |ability index|}}
<tr>
<td>{{ability.name}}</td>
<td><a class="chat-card-button chat-create-actor" data-step-name="{{@root.step}}" data-item-id="{{ability._id}}" >Select it !</a></td>
</tr>
{{/each}}
</table>
{{/if}}
{{#if (eq step "select-race-stats")}}
<div>Select Stats to gain +1 modifier : <br>
Remaining stats to select : {{numberstats}}
</div>
<table class="table-create-actor">
{{#each stats as |stat key|}}
{{#if @root.statsonlyonce}}
{{#if stat.used}}
{{else}}
<tr>
<td>{{stat.label}} ({{stat.abbrev}})</td>
<td><a class="chat-card-button chat-create-actor" data-step-name="{{@root.step}}" data-stat-key="{{key}}" >Select it !</a></td>
</tr>
{{/if}}
{{else}}
<tr>
<td>{{stat.label}} ({{stat.abbrev}})</td>
<td><a class="chat-card-button chat-create-actor" data-step-name="{{@root.step}}" data-stat-key="{{key}}" >Select it !</a></td>
</tr>
{{/if}}
{{/each}}
</table>
{{/if}}
{{#if (eq step "select-role")}}
<div>Now select a Role for your character.
</div>
<table class="table-create-actor">
{{#each roles as |role index|}}
<tr>
<td>{{role.name}}</td>
<td><a class="chat-card-button chat-create-actor" data-step-name="{{@root.step}}" data-item-id="{{role._id}}" >Select it !</a></td>
</tr>
{{/each}}
</table>
{{/if}}
</div>

View File

@ -26,7 +26,42 @@
{{/each}}
</ul>
</ul>
<ul>
<li class="flexrow"><label class="generic-label">Selectable Stats ?</label>
<label class="attribute-value checkbox"><input type="checkbox" name="data.selectablestats" {{checked data.selectablestats}}/></label>
</li>
{{#if data.selectablestats}}
<li class="flexrow"><label class="generic-label">Select 1 stat only once?</label>
<label class="attribute-value checkbox"><input type="checkbox" name="data.statsonlyonce" {{checked data.statsonlyonce}}/></label>
</li>
<li class="flexrow"><label class="generic-label">Number of selectable stats</label>
<input type="text" class="input-numeric-short padd-right" name="data.numberstats" value="{{data.numberstats}}" data-dtype="Number"/>
</li>
{{/if}}
</ul>
<ul>
<li class="flexrow"><label class="generic-label">Number of Optionnal Abilities</label>
<input type="text" class="input-numeric-short padd-right" name="data.nboptionnal" value="{{data.nboptionnal}}" data-dtype="Number"/>
</li>
<li class="flexrow"><label class="generic-label">Optionnal Abilities</label>
</li>
<ul class="ul-level1">
<li class="flexrow"><div class="drop-optionnal-abilities"><label>Drop Abilities here !</label></div>
</li>
{{#each data.optionnalabilities as |ability idx|}}
<li class="flexrow">
<label name="data.optionnalabilities[{{idx}}].name"><a class="view-subitem" data-type="abilities" data-index="{{idx}}">{{ability.name}}</a></label>
<div class="item-controls padd-left">
<a class="item-control delete-subitem padd-left" data-type="optionnalabilities" data-index="{{idx}}" title="Delete Ability"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ul>
</ul>
<label class="generic-label">Description</label>
<div class="small-editor item-text-long-line">
{{editor content=data.description target="data.description" button=true owner=owner editable=editable}}