added support for multiple experiences
This commit is contained in:
parent
f5153485af
commit
3b2ff4b436
2 changed files with 26 additions and 11 deletions
|
|
@ -279,16 +279,31 @@ export class DHImporter {
|
|||
}
|
||||
|
||||
static _parseExperienceLine(line, data) {
|
||||
// "Ambusher +3"
|
||||
const match = line.match(/(.+?)\s+([+-]?\d+)$/);
|
||||
if (match) {
|
||||
const currentCount = Object.keys(data.system.experiences).length;
|
||||
const key = "exp" + currentCount;
|
||||
data.system.experiences[key] = {
|
||||
name: match[1].trim(),
|
||||
value: parseInt(match[2])
|
||||
};
|
||||
// Handle "Experience: Manipulate +2, Infiltrate +2" or "Knowledge (Arcana, History) +2"
|
||||
const parts = line.split(",");
|
||||
let buffer = "";
|
||||
|
||||
for (let part of parts) {
|
||||
buffer = buffer ? buffer + "," + part : part;
|
||||
|
||||
// Check if buffer matches "Name +Value"
|
||||
// We trim to handle spaces around commas
|
||||
const trimmed = buffer.trim();
|
||||
// Regex to match "Name +Value" at the end of the string
|
||||
const match = trimmed.match(/(.+?)\s+([+-]?\d+)$/);
|
||||
|
||||
if (match) {
|
||||
const currentCount = Object.keys(data.system.experiences).length;
|
||||
const key = "exp" + currentCount;
|
||||
data.system.experiences[key] = {
|
||||
name: match[1].trim(),
|
||||
value: parseInt(match[2])
|
||||
};
|
||||
// Reset buffer as we found a complete experience
|
||||
buffer = "";
|
||||
}
|
||||
}
|
||||
// If buffer remains (e.g. "Some Trait" without number), it is ignored, consistent with previous behavior.
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue