Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(() => {
- class Story {
- constructor() {
- this.current_chapter = 1
- this.max_chapters = max_chapters
- this.chapter = chapter
- this.book = book
- this.chapter_title = $("#story_chapter")
- this.chapter_text = $("#story_text")
- this.chapter_image = $("#story_image")
- }
- next_chapter() {
- if (this.current_chapter < this.max_chapters) {
- this.current_chapter += 1;
- load_chapter(this.current_chapter)
- } else {
- console.log("last chapter!")
- }
- }
- previous_chapter() {
- if (this.current_chapter > 1) {
- this.current_chapter -= 1;
- load_chapter(this.current_chapter)
- } else {
- console.log("chapter 1!")
- }
- }
- }
- var story = new Story;
- function get_chapter(current_chapter) {
- $.get("assets/story.json", (json) => {
- story.book = json
- story.chapter = json[`${current_chapter}`]
- console.log(chapter)
- story.max_chapters = Object.keys(book).length
- })
- .then(load_chapter())
- }
- function load_chapter() {
- story.chapter_title.text(chapter["title"])
- story.chapter_text.text(chapter["text"])
- story.chapter_image.text(chapter["image"])
- console.log(chapter)
- console.log(book)
- }
- get_chapter(3)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement