Skip to content

Commit

Permalink
added NPC minipages!
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelEbert committed Sep 15, 2021
1 parent 4d4cc68 commit 570585b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
33 changes: 33 additions & 0 deletions data/minipages/npc/npc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html><head>
<meta charset="UTF-8"/>
<link rel="stylesheet" type="text/css" href="../../../main.css"/>
<link rel="stylesheet" type="text/css" href="../../../guide.css"/>
<script src="./../../../progress.js"></script>
<script src="./npcpage.js"></script>
<title>NPC — Interactive Oblivion Checklist</title>
</head>
<body>

<div class="h2" id="title"></div>
<div class="section" id="section_race">
<div class="sectionTitle">Race</div>
<p id="racep"></p>
</div>
<div class="section" id="section_gameimage">
<div class="sectionTitle">In-Game Image</div>
<img id="gameImage"src=""/>
</div>
<div class="section" id="section_schedule">
<div class="sectionTitle">Schedule</div>
</div>
<div class="section" id="section_uesp">
<div class="sectionTitle"><a id="uespLink" href="">UESP Link</a></div>
</div>
<script>
document.getElementById("gameImage").addEventListener('error',fallbackIngameImage);
var id = new URLSearchParams(window.location.search).get("id")
loadJsonData("../../..").then(()=>generatePage(id));
</script>
</body>
</html>
25 changes: 25 additions & 0 deletions data/minipages/npc/npcpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

function generatePage(npcFormId){
const npc = findOnTree(jsondata.npc, (e=>e?.formId == npcFormId), (x=>!(x?.formId == null)));

document.getElementById("title").innerText = npc.name ?? "unknown";
document.getElementById("racep").innerText = npc.race ?? "unknown";
document.getElementById("gameImage").src="npc"+npcFormId+"_ingame.jpg";

var link;
if(npc.link){
link = npc.link;
}
else{
link = "https://en.uesp.net/wiki/Oblivion:"+npc.name.replaceAll(" ","_");
}
document.getElementById("uespLink").href=link;
}

var tries = 0;
function fallbackIngameImage(eventArgs){
if(tries < 3){
eventArgs.target.src = "./../in-game-placeholder.png";
tries += 1;
}
}
2 changes: 1 addition & 1 deletion injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function createLinkElement(jsonobject, classname){
usableId = jsonobject.id;
}

const useMinipage = settings.minipageCheck && classname == "book" && !(usableId == null);
const useMinipage = settings.minipageCheck && (classname == "book" || classname == "npc") && !(usableId == null);
if(useMinipage){
linky.href ="./data/minipages/"+classname+"/"+classname+".html?id="+usableId;
}
Expand Down
12 changes: 8 additions & 4 deletions progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,15 @@ function elementsUndefinedOrNull(node){
return (node.elements == null);
}

function idNotNull(e){
return !(e?.id == null)
}

//find an element of the tree.
//root: root node to run on
//findfunc: function that returns 'true' if element matches.
function findOnTree(root,findfunc){
if(root.id != null ){
function findOnTree(root,findfunc,isLeafFunc=idNotNull){
if(isLeafFunc(root)){
if(findfunc(root)){
return root;
}
Expand All @@ -134,8 +138,8 @@ function findOnTree(root,findfunc){
}
else{
for(e of root.elements){
const mayberesult = findOnTree(e, findfunc);
if(mayberesult){
const mayberesult = findOnTree(e, findfunc, isLeafFunc);
if(!(mayberesult == null)){
return mayberesult;
}
}
Expand Down

0 comments on commit 570585b

Please sign in to comment.