SHARE
TWEET

Untitled

a guest Dec 9th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(() => {
  2.  
  3. class Story {
  4.   constructor() {
  5.     this.current_chapter = 1
  6.     this.max_chapters = max_chapters
  7.     this.chapter = chapter
  8.     this.book = book
  9.  
  10.     this.chapter_title = $("#story_chapter")
  11.     this.chapter_text = $("#story_text")
  12.     this.chapter_image = $("#story_image")
  13.   }
  14.  
  15.  
  16.   next_chapter() {
  17.     if (this.current_chapter < this.max_chapters) {
  18.       this.current_chapter += 1;
  19.       load_chapter(this.current_chapter)
  20.     } else {
  21.       console.log("last chapter!")
  22.     }
  23.   }
  24.  
  25.   previous_chapter() {
  26.     if (this.current_chapter > 1) {
  27.       this.current_chapter -= 1;
  28.       load_chapter(this.current_chapter)
  29.     } else {
  30.       console.log("chapter 1!")
  31.     }
  32.   }
  33. }
  34.  
  35. var story = new Story;
  36.  
  37. function get_chapter(current_chapter) {
  38.   $.get("assets/story.json", (json) => {
  39.     story.book = json
  40.     story.chapter = json[`${current_chapter}`]
  41.     console.log(chapter)
  42.     story.max_chapters = Object.keys(book).length
  43.  
  44.   })
  45.     .then(load_chapter())
  46. }
  47.  
  48. function load_chapter() {
  49.  
  50.     story.chapter_title.text(chapter["title"])
  51.     story.chapter_text.text(chapter["text"])
  52.     story.chapter_image.text(chapter["image"])
  53.     console.log(chapter)
  54.     console.log(book)
  55.   }
  56.  
  57.  
  58.   get_chapter(3)
  59. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top