Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@

<link href="style.css" rel="stylesheet">

<script src="js/oracles.js"></script>
<script src="js/state.js"></script>
<script src="js/ironwriter.js"></script>
<script src="js/translation.js"></script>
</head>

<body>
Expand Down
94 changes: 78 additions & 16 deletions js/ironwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,29 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see https://github.com/SHiLLySiT/IronWriter/blob/master/LICENSE.txt.
*/

const VERSION = "0.3.2";
const LANG = "FR";
const MAX_EXPERIENCE = 30;
const MAX_PROGRESS = 10;

function loadOracles(lang){
const oldScript = document.querySelector('script[data-dynamic="true"]');
if (oldScript) {
oldScript.remove();
}

const newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = `js/oracles_${lang}.js`; // ex: oracles_en.js
newScript.setAttribute("data-dynamic", "true");

newScript.onload = function () {
};

document.head.appendChild(newScript);
}


const CHALLENGE_RANKS = {
troublesome: 12,
dangerous: 8,
Expand Down Expand Up @@ -83,7 +101,14 @@ const BookmarkFilterTypeMapping = {
1: ['bond', 'unbond'],
2: ['fiction', 'meta'],
3: ['progress_add', 'progress_progress', 'progress_complete']
};
}

const DefaultCharacterName = {
'EN': "New character",
'FR': "Nouveau personnage"
}

let OracleIndication = "Ask the Oracle"

let statElements = {};
for (let p in STATS) {
Expand Down Expand Up @@ -134,6 +159,8 @@ let oldMode = false;

let scrolledIndex = null;

loadOracles(LANG);

let session = new Session();

window.addEventListener("load", handleInit);
Expand Down Expand Up @@ -203,6 +230,7 @@ function handleInit() {
};
confirmDialog.root.addEventListener("MDCDialog:closed", handler);
confirmDialog.content_.textContent = "Are you sure you want to import a session? Your current session will be lost.";
translateImportDialog();
confirmDialog.open();
});

Expand All @@ -219,7 +247,8 @@ function handleInit() {
};
confirmDialog.root.addEventListener("MDCDialog:closed", handler);
confirmDialog.content_.textContent = "Are you sure you want to start a new session? Your current session will be deleted.";
confirmDialog.open();
translateNewDialog();
confirmDialog.open();
});

document.getElementById("help").addEventListener("click", () => {
Expand Down Expand Up @@ -251,6 +280,20 @@ function handleInit() {
initAssets();
initInventory();
initBookmarks();

translateHeader();
translateEntryTabs();
translateStory();
translateCharacterMenu();
translateStatMenu();
translateDebilityMenu();
translateBondsMenu();
translateProgressMenu();
translateAssetsMenu();
translateInventoryMenu();
translateRollMenu();
translateDoOracle();
translateDoRoll();

window.requestAnimationFrame(() => {
let str = localStorage.getItem("session");
Expand All @@ -275,7 +318,8 @@ function newSession() {
session = new Session();

let initialMoment = new Moment("", EventType.None);
initialMoment.addAction(new CharacterNameAction("New Character"));

initialMoment.addAction(new CharacterNameAction(DefaultCharacterName[LANG]));
initialMoment.addAction(new StatAction("momentum", "=", 2));
initialMoment.addAction(new StatAction("momentumReset", "=", 2));
initialMoment.addAction(new StatAction("momentumMax", "=", 10));
Expand Down Expand Up @@ -361,7 +405,7 @@ function initRoll() {
let rollSource = document.getElementById("roll-source");
let rollStats = document.getElementById("roll-stats");
let rollAdd = document.getElementById("roll-add");

let rollButton = document.getElementById("roll");
rollButton.addEventListener("click", () => {
doRoll(rollStats.MDCSelect.value, rollAdd.value, rollSource.MDCSelect.value);
Expand All @@ -380,7 +424,7 @@ function initOracle() {
let container = template.parentElement;
template.remove();

for (let type in ORACLE) {
for (let type in window.ORACLE) {
let item = template.cloneNode(true);
item.querySelector(".js-value").textContent = type;
item.addEventListener("click", () => handleSelectOracle(type));
Expand Down Expand Up @@ -465,6 +509,8 @@ function initBookmarks() {
// While you can pass an object to the `close` call, the docs indicate it should be a string, so...
bookmarksDialog.close("bookmarkSelected:" + eventIndex);
});

translateBookmarksDialog();

document.getElementById("bookmarks").addEventListener("click", () => {
bookmarksDialog.open();
Expand Down Expand Up @@ -513,9 +559,12 @@ function createResource(resource, template) {
if (resource.properties[p] === undefined) {
continue;
}

let name = resource.properties[p].name;
name = translateQuantityProperty(name);

let e = document.createElement("div");
e.textContent = resource.properties[p].name + ": " + resource.properties[p].value;
e.textContent = name + ": " + resource.properties[p].value;
properties.appendChild(e);
}

Expand Down Expand Up @@ -556,6 +605,7 @@ function createProgressTrack(name, rank, roll) {
if (name == null && rank == null) {
newTrack.querySelector(".meta").remove();
} else {
rank = translateProgressRank(rank);
newTrack.querySelector(".name").textContent = name + " (" + rank + ")";
}
return newTrack;
Expand Down Expand Up @@ -607,7 +657,7 @@ function handleSelectOracle(type) {
}
function doOracleRoll(type) {
let result = getOracleValue(ORACLE[type]);
return "Ask the Oracle (" + type + "): " + result;
return OracleIndication + " (" + type + "): " + result;
}
function getOracleValue(value) {
if (typeof (value) == "string") {
Expand Down Expand Up @@ -984,6 +1034,8 @@ function createMoment(input, type, index) {

// Ignore case for tags
args[0] = args[0].toLowerCase();
// Translate the tag
args[0] = translateTag(args[0]);

if (args[0] == "bond") {
action = addBond(args);
Expand All @@ -993,25 +1045,31 @@ function createMoment(input, type, index) {
moment.addAction(action);
} else if (args[0] == "asset") {
moment.addAction(updateAsset(args));
} else if (args[0] == "removeasset") {
} else if (args[0] == "removeAsset") {
moment.addAction(removeAsset(args));
} else if (args[0] == "item") {
moment.addAction(updateInventory(args));
} else if (args[0] == "removeitem") {
} else if (args[0] == "removeItem") {
moment.addAction(removeInventory(args));
} else if (args[0] == "progress") {
action = progress(args);
moment.addAction(action);
} else if (args[0] == "rename") {
moment.addAction(renameCharacter(args));
} else if (args[0] == "is") {
moment.addAction(addDebility(args));
moment.addAction(new StatAction("momentumMax", "-", 1));
moment.addAction(new StatAction("momentumReset", "-", 1));
let debilityAction = addDebility(args);
if (debilityAction !== undefined) {
moment.addAction(debilityAction);
moment.addAction(new StatAction("momentumMax", "-", 1));
moment.addAction(new StatAction("momentumReset", "-", 1));
}
} else if (args[0] == "not") {
moment.addAction(removeDebility(args));
moment.addAction(new StatAction("momentumMax", "+", 1));
moment.addAction(new StatAction("momentumReset", "+", 1));
let debilityAction = removeDebility(args);
if (debilityAction !== undefined) {
moment.addAction(debilityAction);
moment.addAction(new StatAction("momentumMax", "+", 1));
moment.addAction(new StatAction("momentumReset", "+", 1));
}
} else if (args[0] == "bookmark") {
args[2] = type;
moment.addAction(addBookmark(args, index));
Expand Down Expand Up @@ -1149,6 +1207,7 @@ function removeDebility(args) {
}

let debilityName = args[1].toLowerCase();
debilityName = translateDebility(debilityName);
if (DEBILITIES[debilityName] === undefined) {
return;
}
Expand All @@ -1162,6 +1221,7 @@ function addDebility(args) {
}

let debilityName = args[1].toLowerCase();
debilityName = translateDebility(debilityName);
if (DEBILITIES[debilityName] === undefined) {
return;
}
Expand All @@ -1178,6 +1238,8 @@ function progress(args) {
let option = (args[2] === undefined) ? undefined : args[2].toLowerCase();
let progress = new ProgressAction(id);
progress.progressName = args[1];

option = translateProgressOption(option);

if (option === undefined) {
// mark progress
Expand Down
4 changes: 2 additions & 2 deletions js/oracles.js → js/oracles_EN.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
along with this program. If not, see https://github.com/SHiLLySiT/IronWriter/blob/master/LICENSE.txt.
*/

const ORACLE = {
"Generic Roll": {
window.ORACLE = {
"Generic roll": {
1: "1",
2: "2",
3: "3",
Expand Down
Loading