Skip to content

Commit a906b43

Browse files
committed
Beta-2 Fixes and Improvements
1 parent 66ec332 commit a906b43

File tree

3 files changed

+127
-59
lines changed

3 files changed

+127
-59
lines changed

module.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"changelog": "https://raw.githubusercontent.com/NiceTSY/nice-cypher-add-ons/master/CHANGELOG.md",
88
"author": "Alec (Nice to see you#6655 / NiceTSY)",
99

10-
"version": "0.3.0-Beta",
10+
"version": "0.3.0-Beta-2",
1111
"minimumCoreVersion": "0.8.5",
1212
"compatibleCoreVersion": "0.8.9",
1313
"systems": ["cyphersystem"],
@@ -36,5 +36,5 @@
3636

3737
"url": "https://github.com/NiceTSY/nice-cypher-add-ons",
3838
"manifest": "https://raw.githubusercontent.com/NiceTSY/nice-cypher-add-ons/develop/module.json",
39-
"download": "https://github.com/NiceTSY/nice-cypher-add-ons/releases/download/0.3.0-Beta/module.zip"
39+
"download": "https://github.com/NiceTSY/nice-cypher-add-ons/releases/download/0.3.0-Beta-2/module.zip"
4040
}

scripts/module_creation.js

Lines changed: 124 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const typeSentenceCheck = [
4040
`${quantifier}descriptor`,
4141
`${quantifier}focus`,
4242
`${quantifier}type`,
43-
`${quantifier}additional`
43+
`${quantifier}additional`,
44+
`${quantifier}additionalSentence`
4445
];
4546

4647
const typeStatCheck = [
@@ -49,7 +50,7 @@ const typeStatCheck = [
4950
`${quantifier}intellect`,
5051
`${quantifier}additional`,
5152
`${quantifier}effort`
52-
]
53+
];
5354

5455
const typeItemsCheck = [
5556
`${quantifier}skill`,
@@ -62,7 +63,7 @@ const skillLevels = [
6263
'Trained',
6364
'Practiced',
6465
'Inability'
65-
]
66+
];
6667

6768
/*------------------------------------------------------------------------------------------------
6869
------------------------------------------- Class(es) --------------------------------------------
@@ -77,9 +78,11 @@ class creationSentence {
7778
};
7879

7980
class creationStat {
80-
constructor(value = 10, edge = 0) {
81-
this.value = value;
82-
this.edge = edge;
81+
constructor(value = 10, edge = 0, poolModificator = 0, edgeModificator = 0) {
82+
this.value = (Number.isInteger(value)) ? value : 10;
83+
this.edge = (Number.isInteger(edge)) ? edge : 0;
84+
this.poolModificator = poolModificator;
85+
this.edgeModificator = edgeModificator;
8386
};
8487
};
8588

@@ -125,6 +128,7 @@ class creationData {
125128

126129
this.tier = 1;
127130
this.effort = 0;
131+
this.effortModificator = 0;
128132

129133
this.stats = new creationStats();
130134

@@ -143,15 +147,37 @@ class creationData {
143147
this.tier = tier;
144148
};
145149

146-
setEffort(effort) {
147-
if (!Number.isInteger(effort)) return;
148-
this.effort = effort;
150+
changeStat(stat, value) {
151+
if (stat === 'effort') {
152+
console.log(Number.isInteger(value))
153+
if (!Number.isInteger(value)) return;
154+
this.effort = value;
155+
} else {
156+
value = Object.assign(new creationStat(), value);
157+
if (!stat in this.stats) return;
158+
this.stats[stat] = value;
159+
};
149160
};
150161

151-
changeStat(type, stat) {
152-
stat = Object.assign(new creationStat(), stat);
153-
if (!type in this.stats) return;
154-
this.stats[type] = stat;
162+
addStatModificator(stat, type, modificator) {
163+
if (stat === 'effort') {
164+
const current = this.effortModificator,
165+
mathExpression = current + modificator;
166+
167+
this.effortModificator = mathExpression;
168+
} else if (!stat in this.stats) return;
169+
170+
if (type === 'pool') {
171+
const current = this.stats[stat].poolModificator,
172+
mathExpression = current + modificator;
173+
174+
this.stats[stat].poolModificator = mathExpression;
175+
} else if (type === 'edge') {
176+
const current = this.stats[stat].edgeModificator,
177+
mathExpression = current + modificator;
178+
179+
this.stats[stat].edgeModificator = mathExpression;
180+
};
155181
};
156182

157183
skillExists(idOrName) {
@@ -243,25 +269,25 @@ export async function checkJournalType(actor, html, journal) {
243269
let journals = game.journal.filter(j => buttons.includes(j.id));
244270
journal = await game.journal.get(journal.id);
245271

246-
const journalContent = journal.data.content.split('\n');
272+
const journalContent = returnArrayOfHtmlContent(journal.data.content);
247273
let journalType = journalContent[0].replace(/ .*/, '').toLowerCase();
248274

249275
for (const j of journals) {
250-
const jContent = j.data.content.split('\n'),
251-
jType = jContent[0].replace(/ .*/, '').toLowerCase()
276+
const jContent = returnArrayOfHtmlContent(j.data.content),
277+
jType = jContent[0].replace(/ .*/, '').toLowerCase();
252278

253279
if (jType === journalType) {
254-
journalType = UTILITIES.sanitizeString(UTILITIES.removeTags(journalType))
255-
ui.notifications.warn(game.i18n.format('NICECYPHER.CreationAlreadySentence', { type: `${journalType} (${j.name})` }))
280+
journalType = UTILITIES.sanitizeString(journalType);
281+
ui.notifications.warn(game.i18n.format('NICECYPHER.CreationAlreadySentence', { type: `${journalType} (${j.name})` }));
256282
return;
257-
}
258-
}
283+
};
284+
};
259285

260286
journals.push(journal);
261-
getContent(journals, actor)
287+
getContent(journals, actor);
262288
};
263289

264-
export function checkIfLinkedData(html, actor) {
290+
export async function checkIfLinkedData(html, actor) {
265291
const nameCheck = [
266292
actor.data.data.basic.descriptor,
267293
actor.data.data.basic.focus,
@@ -270,23 +296,24 @@ export function checkIfLinkedData(html, actor) {
270296
];
271297

272298
for (const name of nameCheck) {
273-
const journal = game.journal.getName(name);
299+
if (!name || name === '') continue;
300+
301+
const id = getJournalIdInName(name),
302+
journal = await game.journal.get(id);
274303

275304
if (journal) {
276-
const content = journal.data.content.split('\n');
277-
updateActorSheet(html, content[0].replace(/ .*/, '').toLowerCase(), journal)
305+
const content = returnArrayOfHtmlContent(journal.data.content);
306+
updateActorSheet(html, content[0].replace(/ .*/, '').toLowerCase(), journal);
278307
};
279-
}
280-
281-
// updateActorSheet(html, type.substring(1), journal)
308+
};
282309
};
283310

284311
function updateActorSheet(html, toUpdate, data) {
285-
toUpdate = UTILITIES.removeTags(toUpdate).substring(1);
312+
toUpdate = (toUpdate === `${quantifier}additional`) ? 'additionalSentence' : UTILITIES.sanitizeString(toUpdate);
286313
const newNode = (`
287314
<button id="${data.id}" name="data.basic.${toUpdate}" class="linkedButton"><i class="fas fa-book-open"></i> ${data.name}</button>
288-
`);
289-
const oldNode = $(`input[name="data.basic.${toUpdate}"`);
315+
`),
316+
oldNode = $(`input[name="data.basic.${toUpdate}"`);
290317

291318
oldNode.replaceWith(newNode);
292319
$(`#${data.id}`).click(e => {
@@ -303,12 +330,9 @@ function updateActorSheet(html, toUpdate, data) {
303330
});
304331
};
305332

306-
function isGoodJournalType(journal) {
307-
const lines = journal.data.content.split('\n');
308-
const checkFirstLine = UTILITIES.removeTags(lines[0].toLowerCase());
309-
310-
if (!UTILITIES.doesArrayContains(checkFirstLine, typeSentenceCheck)) return false;
311-
return checkFirstLine;
333+
function isGoodJournalType(type) {
334+
if (!UTILITIES.doesArrayContains(type, typeSentenceCheck)) return false;
335+
return type;
312336
}
313337

314338
async function getContent(journals, actor, remove = false) {
@@ -321,16 +345,16 @@ async function getContent(journals, actor, remove = false) {
321345

322346
for (const journal of journals) {
323347
const del = (removeJournal == currentJournal) ? true : false,
324-
lines = journal.data.content.split('\n'),
325-
checkFirstLine = isGoodJournalType(journal);
348+
lines = returnArrayOfHtmlContent(journal.data.content),
349+
checkFirstLine = isGoodJournalType(lines[0].toLowerCase());
326350

327351
if (!checkFirstLine) continue;
328-
const s = (checkFirstLine === 'additional') ? 'additionalSentence' : UTILITIES.sanitizeString(checkFirstLine);
352+
const s = (checkFirstLine === `${quantifier}additional`) ? 'additionalSentence' : UTILITIES.sanitizeString(checkFirstLine);
329353

330-
creationActor.changeSentence(s, (!del) ? journal.name : '');
354+
creationActor.changeSentence(s, (!del) ? `${journal.name} {${journal.id}}` : '');
331355

332356
for (const line of lines) {
333-
const l = UTILITIES.removeTags(line);
357+
const l = line;
334358

335359
if (l === checkFirstLine) continue;
336360
if (!l.startsWith(quantifier)) continue;
@@ -345,16 +369,34 @@ async function getContent(journals, actor, remove = false) {
345369
// Stats
346370
if (UTILITIES.doesArrayContains(type, typeStatCheck)) {
347371
const stat = type.substring(1),
348-
value = l.match(/\d+/g);
372+
value = l.match(/\d+/g),
373+
operation = l.match(/[+\-](\.\d+|\d+(\.\d+)?)/g);
349374

350-
if (stat === 'effort') creationActor.setEffort(value[0])
351-
else {
352-
const statValue = (!del) ? new creationStat(parseInt(value[0]), parseInt(value[1])) : new creationStat();
353-
creationActor.changeStat(stat, statValue);
375+
if (stat === 'effort' && !operation) creationActor.changeStat(stat, (!del) ? parseInt(value[0]) : 0);
376+
else if (operation) {
377+
let op = operation[0];
378+
379+
if (stat === 'effort') {
380+
if (del) op = (op.includes('+')) ? op.replace('+', '-') : op.replace('-', '+');
381+
creationActor.addStatModificator(stat, 'effort', op)
382+
} else {
383+
if (del) op = (op.includes('+')) ? op.replace('+', '-') : op.replace('-', '+');
384+
creationActor.addStatModificator(stat, 'pool', op);
385+
386+
op = operation[1];
387+
if(!op) continue
388+
if (del) op = (op.includes('+')) ? op.replace('+', '-') : op.replace('-', '+');
389+
creationActor.addStatModificator(stat, 'edge', op);
390+
};
391+
} else if (Number.isInteger(parseInt(value[0]))) {
392+
const statValue = (!del)
393+
? new creationStat(parseInt(value[0]), parseInt(value[1]), creationActor.stats[stat].poolModificator, creationActor.stats[stat].edgeModificator)
394+
: new creationStat(10, 0, creationActor.stats[stat].poolModificator, creationActor.stats[stat].edgeModificator);
395+
creationActor.changeStat((stat === 'additionalPool') ? 'additionalPool' : stat, statValue);
354396
};
355397
}
356-
// Skills, Abilities and Equipment
357-
else if (UTILITIES.doesArrayContains(type, typeItemsCheck)) {
398+
// Abilities / Skills / Equipments
399+
else if (type === `${quantifier}item` || UTILITIES.doesArrayContains(type, typeItemsCheck)) {
358400
const id = object.match(/\[(.*?)\]/)[1],
359401
compendium = id.split('.');
360402

@@ -406,8 +448,6 @@ async function getContent(journals, actor, remove = false) {
406448
} else {
407449
const oldJournalSkill = allSkills.filter(s => s.skill === duplicatedItem.name);
408450

409-
console.log(allSkills)
410-
411451
if (oldJournalSkill.length > 1) {
412452
let newLevel = 0;
413453
for (const s of oldJournalSkill) if (s.journal != journal.name) newLevel += s.level;
@@ -447,7 +487,6 @@ async function getContent(journals, actor, remove = false) {
447487

448488
if (del) {
449489
const oldJournalItem = allItems.filter(i => i.item === duplicatedItem.name);
450-
console.log(duplicatedItem.name)
451490

452491
if (oldJournalItem.length >= 1) {
453492
const oldItem = creationActor.items.find(i => i.name === duplicatedItem.name)
@@ -483,10 +522,17 @@ async function getContent(journals, actor, remove = false) {
483522
*/
484523
async function updateActorDataV3(actor, data) {
485524
let itemsToCreate = [],
486-
itemsToDelete = [],
487-
updatedData = { [`data.basic.effort`]: data.effort };
525+
itemsToDelete = [];
488526

489527
// Effort
528+
const checkEffortModificator = eval(data.effortModificator);
529+
if (checkEffortModificator > 0) {
530+
const newEffortValue = eval(`${data.effort}+${checkEffortModificator}`);
531+
console.log(newEffortValue)
532+
data.changeStat('effort', newEffortValue);
533+
};
534+
535+
let updatedData = { [`data.basic.effort`]: data.effort };
490536
await actor.update(updatedData);
491537

492538
// Sentence
@@ -497,6 +543,18 @@ async function updateActorDataV3(actor, data) {
497543

498544
// Stats
499545
for (const s in data.stats) {
546+
const checkPoolModificator = eval(data.stats[s].poolModificator),
547+
checkEdgeModificator = eval(data.stats[s].edgeModificator);
548+
549+
if (checkPoolModificator > 0 || checkEdgeModificator > 0) {
550+
const newPoolValue = eval(`${data.stats[s].value}+${checkPoolModificator}`),
551+
newEdgeValue = eval(`${data.stats[s].edge}+${checkEdgeModificator}`),
552+
statValue = new creationStat(parseInt(newPoolValue), parseInt(newEdgeValue));
553+
554+
data.changeStat(s, statValue);
555+
};
556+
557+
500558
updatedData = [
501559
{ [`data.pools.${s}.value`]: data.stats[s].value },
502560
{ [`data.pools.${s}.max`]: data.stats[s].value },
@@ -541,6 +599,17 @@ async function updateActorDataV3(actor, data) {
541599
if (itemsToCreate.length > 0) await actor.createEmbeddedDocuments('Item', itemsToCreate);
542600
};
543601

602+
function returnArrayOfHtmlContent(str) {
603+
return UTILITIES.removeTags(str).split('\n').filter(n => n);
604+
};
605+
544606
function getObject(start, str) {
545607
return str.substring(start).replace(/ .*/, '');
546-
}
608+
};
609+
610+
function getJournalIdInName(str) {
611+
return str.substring(
612+
str.indexOf("{") + 1,
613+
str.lastIndexOf("}")
614+
);
615+
};

styles/addons.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ button[data-key="cyphersheets.cyphersheetsconfig"]:hover {
5151

5252
/* Own Css */
5353
.linkedButton {
54-
width: 100%;
55-
height: 100%;
54+
height: 26px;
5655
margin: 0;
5756
border: 0.5px solid lightgrey;
5857
}

0 commit comments

Comments
 (0)