Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. $(() => {
  2.  
  3. class Story {
  4. constructor() {
  5. this.current_chapter = 1
  6. this.max_chapters = 0
  7. this.chapter = {}
  8. this.book = {}
  9.  
  10. this.chapter_title = $("#story_chapter")
  11. this.chapter_text = $("#story_text")
  12. this.chapter_image = $("#story_image")
  13. }
  14.  
  15. load_book() {
  16. $.get("assets/story.json", (json) => {
  17. this.book = json
  18. this.max_chapters = Object.keys(this.book).length
  19. })
  20. .then(this.load_chapter)
  21. .then(post_chapter)
  22. }
  23.  
  24. load_chapter() {
  25. this.chapter = this.book[`${this.current_chapter}`]
  26. }
  27.  
  28. next_chapter() {
  29. if (this.current_chapter < this.max_chapters) {
  30. this.current_chapter += 1;
  31. load_chapter(this.current_chapter)
  32. } else {
  33. console.log("last chapter!")
  34. }
  35. }
  36.  
  37. previous_chapter() {
  38. if (this.current_chapter > 1) {
  39. this.current_chapter -= 1;
  40. load_chapter(this.current_chapter)
  41. } else {
  42. console.log("chapter 1!")
  43. }
  44. }
  45. }
  46.  
  47. var story = new Story;
  48.  
  49.  
  50. function post_chapter() {
  51.  
  52. story.chapter_title.text(story.chapter["title"])
  53. story.chapter_text.text(story.chapter["text"])
  54. story.chapter_image.text(story.chapter["image"])
  55. console.log(story.chapter)
  56. console.log(story.book)
  57. }
  58.  
  59.  
  60. story.load_book(story.current_chapter)
  61. console.log(story.chapter)
  62. console.log(story.book)
  63.  
  64. //.then(post_chapter)
  65.  
  66. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement