Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multiple choice and numberinputs #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
6 changes: 4 additions & 2 deletions editor/components/sectionView.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ <h2 class="card-title">
<div class="collapse-content">
<textarea data-role="sceneActions" class="form-control"></textarea>
<div class="btn-group" role="group" aria-label="Add Action">
<button class="btn" data-role="action">Action</button>
<button class="btn" data-role="action" data-action="button">Button</button>
<button class="btn" data-role="action" data-action="multipleChoice">Multiple Choice</button>
<button class="btn" data-role="action" data-action="numberInput">Number Input</button>
</div>
</div>
</details>
Expand Down Expand Up @@ -83,4 +85,4 @@ <h2 class="card-title">
</div>

</div>
</template>
</template>
24 changes: 12 additions & 12 deletions editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,17 @@ <h5 class="sidebar-title">Developer</h5>
<button class="close" data-dismiss="modal" type="button" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h5 class="modal-title">New state item </h5>
<h5 class="modal-title">New State Change</h5>
<div>
<input id="newStateItemKey" type="text" class="form-control alt-dm" placeholder="state item id">
<input id="newStateItemValue" type="text" class="form-control alt-dm" placeholder="state value">
<select id="newStateItemType" class="form-control alt-dm">
<option value="set" selected>set value</option>
<option value="incr">increment value</option>
<option value="dec">decrement value</option>
<option value="apend">append</option>
<option value="remove">remove</option>
<option value="set" selected>Set value</option>
<option value="incr">Increment</option>
<option value="decr">Decrement</option>
<option value="append">Append</option>
<option value="remove">Remove value</option>
</select>
<input id="newStateItemKey" type="text" class="form-control alt-dm" placeholder="Identificator">
<input id="newStateItemValue" type="text" class="form-control alt-dm" placeholder="Value">
</div>
<div class="text-right mt-20">
<!-- text-right = text-align: right, mt-20 = margin-top: 2rem (20px) -->
Expand All @@ -153,11 +153,11 @@ <h5 class="modal-title">New state item </h5>
<button class="close" data-dismiss="modal" type="button" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h5 class="modal-title">New Badge </h5>
<h5 class="modal-title">New Badge</h5>
<div>
<input id="newBadgeTitle" type="text" class="form-control alt-dm" placeholder="Title">
<input id="newBadgeDescription" type="text" class="form-control alt-dm" placeholder="description">
<input id="newBadgeRules" type="text" class="form-control alt-dm" placeholder="Rules">
<input id="newBadgeDescription" type="text" class="form-control alt-dm" placeholder="Description">
<input id="newBadgeRules" type="text" class="form-control alt-dm" placeholder="Rules (key:value,key:value,…)">
<input id="newBadgeImage" type="text" class="form-control alt-dm" placeholder="Image">
</div>
<div class="text-right mt-20">
Expand All @@ -178,4 +178,4 @@ <h5 class="modal-title">New Badge </h5>

</body>

</html>
</html>
66 changes: 31 additions & 35 deletions editor/js/views/badgesView.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { HTMLUtilityTools, HTMLSelectorTools } from '../uiExt.js'
import { HTMLUtilityTools, HTMLSelectorTools } from "../uiExt.js";

export default class BadgesView {
constructor(source, container, delegates) {
this.view = HTMLUtilityTools.createInstanceOfTemplate("badgesSectionTemplate");
this.view = HTMLUtilityTools.createInstanceOfTemplate(
"badgesSectionTemplate"
);
container.appendChild(this.view);
this.delegates = delegates
this.delegates = delegates;
this.addBadgeButton = document.getElementById("addNewBadgeBt");
this.badgesDisplay = document.getElementById("regBadges");

Expand All @@ -13,48 +15,42 @@ export default class BadgesView {
if (source.badges == null || source.badges == undefined) {
source.badges = [];
}
source.badges.push(badge)
source.badges.push(badge);
await delegates.onChange();
this.populateBadges(this.badgesDisplay, source)
}

this.populateBadges(this.badgesDisplay, source);
};
}


populateBadges(tbl, source) {
let tbody = tbl.getElementsByTagName("tbody")[0];
tbody.innerHTML = ""; ///TODO: Fiks dette, til å slette elementer riktig.

if (source.badges) {

console.log(source.badges)
const badges = source.badges || [];

source.badges.forEach(badge => {

const row = tbody.insertRow();
const titleCell = row.insertCell();
const descriptionCell = row.insertCell();
const rulesCell = row.insertCell();
const imageCell = row.insertCell();
imageCell.classList.add("text-right");

titleCell.appendChild(document.createTextNode(badge.name))
descriptionCell.appendChild(document.createTextNode(badge.description))

const conditions = badge.conditions.reduce((acc, val, index, arr) => {

acc += val.target + " : " + val.value;
return acc;
}, "");
tbody.innerHTML = ""; ///TODO: Fiks dette, til å slette elementer riktig.

rulesCell.appendChild(document.createTextNode(conditions))
console.log({ badges: badges });

imageCell.appendChild(document.createTextNode(badge.img));
badges.forEach((badge) => {
const row = tbody.insertRow();
const titleCell = row.insertCell();
const descriptionCell = row.insertCell();
const rulesCell = row.insertCell();
const imageCell = row.insertCell();
imageCell.classList.add("text-right");

});
titleCell.appendChild(document.createTextNode(badge.name));
descriptionCell.appendChild(
document.createTextNode(badge.description)
);

const conditions = badge.conditions
.map((condition) =>
[condition.target, condition.value].join(" : ")
)
.join(", ");

}
rulesCell.appendChild(document.createTextNode(conditions));

imageCell.appendChild(document.createTextNode(badge.img));
});
}
}
}
Loading