Guest User

Untitled

a guest
May 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. @@ Book (#353)
  2.  
  3. @@ Basics
  4. @create Book
  5. @link Book = #340
  6. @set Book = LINK_OK
  7. @set Book = QUIET
  8. @set Book = !NO_COMMAND
  9.  
  10. @@ Description strings (you ought to override these)
  11. @DESCRIBE Book=A book entitled [name(me)]. It contains [v(PAGE_LAST)] pages of text.
  12. @set Book/DESCRIBE=no_command visual prefixmatch public nearby
  13. @SUCCESS Book=You picked up a book entitled [name(me)].
  14. @set Book/SUCCESS=no_command prefixmatch
  15. @OSUCCESS Book=picked up [name(me)].
  16. @set Book/OSUCCESS=no_command prefixmatch
  17. @FAILURE Book=You can't pick up this book.
  18. @set Book/FAILURE=no_command prefixmatch
  19.  
  20. @@ Book data
  21. &PAGE Book=
  22. @set Book/PAGE=no_command
  23. &PAGE_CURRENT Book=0
  24. @set Book/PAGE_CURRENT=no_command
  25. &PAGE_LAST Book=0
  26. @set Book/PAGE_LAST=no_command
  27.  
  28. @@ Verbs
  29. @@ Help
  30. &DO_HELP Book=$howto *:@include me/DO_CHECK_USE; @pemit/silent %#=Usage:%r [ansi(h, << [name(me)])] %t go to the first page%r [ansi(h, >> [name(me)])] %t go to the last page %r [ansi(h, < [name(me)])] %t go to the previous page %r [ansi(h, > [name(me)])] %t go to the next page %r [ansi(h, ># [name(me)]=pg#)] %t go to specific page %r [ansi(h, ># [name(me)])] %t show current page and total page count %r [ansi(h, _ [name(me)])] %t read current page %r [ansi(h, ! [name(me)])] %t read current page aloud %r [ansi(h, >_ [name(me)])] %t go to the next page and read it %r [ansi(h, >! [name(me)])] %t go to the next page and read it aloud %r [ansi(h, ? [name(me)]=text)] %t show page numbers where text is found (case-insensitive) %r [ansi(h, >>+ [name(me)]=text)] %t add new page with specified text to the end %r [ansi(h, ++ [name(me)]=text)] %t insert new page with specified text before current page %r [ansi(h, -- [name(me)]=pg#)] %t delete specified page %r [ansi(h, howto [name(me)])] %t show this help %r To use a book you must pass its [ansi(h, @lock/user:use)]. To change book's content you must pass its [ansi(h, @lock/user:edit)].;
  31.  
  32. @@ Go to the first page: << BookName
  33. &DO_FIRSTPAGE Book=$<< *:@include me/DO_CHECK_USE; &PAGE_CURRENT me=1; @pemit/silent %#=You open [name(me)] at the first page.
  34.  
  35. @@ Go to the previous page: < BookName
  36. &DO_PREVPAGE Book=$< *:@include me/DO_CHECK_USE; @assert gt(v(PAGE_CURRENT),1)={@pemit/silent %#=You're on the first page.}; &PAGE_CURRENT me=[SUB(v(PAGE_CURRENT),1)]; @pemit/silent %#=You flip to the previous page of [name(me)].
  37.  
  38. @@ Go to the next page: > BookName
  39. &DO_NEXTPAGE Book=$> *:@include me/DO_CHECK_USE; @assert lt(v(PAGE_CURRENT),v(PAGE_LAST))={@pemit/silent %#=You're on the last page.}; &PAGE_CURRENT me=[ADD(v(PAGE_CURRENT),1)]; @pemit/silent %#=You flip to the next page of [name(me)].
  40.  
  41. @@ Go to the last page: >> BookName
  42. &DO_LASTPAGE Book=$>> *:@include me/DO_CHECK_USE;&PAGE_CURRENT me=v(PAGE_LAST); @pemit/silent %#=You open [name(me)] at the last page.
  43.  
  44. @@ Go to the specified page: ># BookName=page#
  45. &DO_GOTOPAGE Book=$># *=*:@include me/DO_CHECK_USE; @assert CAND(isnum(%1), gte(%1,1), lte(%1, v(PAGE_LAST) ) ); &PAGE_CURRENT me=%1; @pemit/silent %#=You open [name(me)] at page [v(PAGE_CURRENT)].
  46.  
  47. @@ Get current page # and total pages count: ># BookName
  48. &DO_GETPAGE Book=$># *:@include me/DO_CHECK_USE; @pemit/silent %#=[v(PAGE_CURRENT)]/[v(PAGE_LAST)]
  49.  
  50. @@ Read current page: _ BookName
  51. &DO_READ Book=$_ *:@include me/DO_CHECK_USE; @assert hasattr(me,PAGE`[v(PAGE_CURRENT)])={@pemit/silent %#=This page is blank.}; @pemit/silent %#= "[v(PAGE`[v(PAGE_CURRENT)])]"
  52.  
  53. @@ Read current page aloud: ! BookName
  54. &DO_ALOUD Book=$! *:@include me/DO_CHECK_USE; @assert hasattr(me,PAGE`[v(PAGE_CURRENT)])={@pemit/silent %#=This page is blank.}; @oemit %#=%N reads, "[v(PAGE`[v(PAGE_CURRENT)])]"; @pemit/silent %#=You read, "[v(PAGE`[v(PAGE_CURRENT)])]"
  55.  
  56. @@ Read next page: >_ BookName
  57. &DO_READNEXT Book=$>_ *:@include me/DO_CHECK_USE; @assert lt(v(PAGE_CURRENT),v(PAGE_LAST))={@pemit/silent %#=You're on the last page.}; &PAGE_CURRENT me=[ADD(v(PAGE_CURRENT),1)]; {@pemit/silent %#=You flip to the next page of [name(me)].}; @pemit/silent %#="[v(PAGE`[v(PAGE_CURRENT)])]"
  58.  
  59. @@ Read next page aloud: >_ BookName
  60. &DO_ALOUDNEXT Book=$>! *:@include me/DO_CHECK_USE; @assert lt(v(PAGE_CURRENT),v(PAGE_LAST))={@pemit/silent %#=You're on the last page.}; &PAGE_CURRENT me=[ADD(v(PAGE_CURRENT),1)]; {@pemit/silent %#=You flip to the next page of [name(me)].}; @oemit %#=%N reads, "[v(PAGE`[v(PAGE_CURRENT)])]"; @pemit/silent %#=You read, "[v(PAGE`[v(PAGE_CURRENT)])]"
  61.  
  62. @@ Look for text: ? BookName=text
  63. &DO_SEARCH Book=$\? *=*: @break comp(num(%0),%!); @pemit/silent %#=Pages: [iter(grepi(Diary, {PAGE`*}, {%1}), after(##,`))]
  64.  
  65. @@ Append page to the end: >>+ BookName=Page text
  66. &DO_ADDPAGE Book=$>>+ *=*:@include me/DO_CHECK_USE; @include me/DO_CHECK_EDIT; @assert gt(strlen(%1),0); &PAGE_LAST me=add(get(me/PAGE_LAST),1); &PAGE_CURRENT me=get(me/PAGE_LAST); &PAGE`[get(me/PAGE_LAST)] me={%1}; @pemit/silent %#=You added new page into [name(me)].
  67.  
  68. @@ Add page before the current page: ++ BookName=Page text
  69. &DO_INSPAGE Book=$++ *=*:@include me/DO_CHECK_USE; @include me/DO_CHECK_EDIT; @assert gt(strlen(%1),0); @switch gte(v(PAGE_CURRENT),1)=0,{&PAGE_CURRENT me=1};@wait me={&PAGE_LAST me=add(v(PAGE_LAST),1); &PAGE`[v(PAGE_CURRENT)] me={%1}; @pemit/silent %#=You added new page into [name(me)].}; @tr me/DO_SHIFTPAGES=[v(PAGE_CURRENT)],[v(PAGE_LAST)],1;
  70.  
  71. @@ Delete specified page: -- BookName=page#
  72. &DO_DELPAGE Book=$-- *=*:@include me/DO_CHECK_USE; @include me/DO_CHECK_EDIT; @assert CAND(gt(%1,0),lte(%1,v(PAGE_LAST))); @wait me={&PAGE`[v(PAGE_LAST)] me; &PAGE_LAST me=sub(v(PAGE_LAST),1); @switch gt(v(PAGE_CURRENT),v(PAGE_LAST))=1,&PAGE_CURRENT me=[v(PAGE_LAST)]; @pemit/silent %#=You tore out page #[%1] from [name(me)].}; @break eq(%1,v(PAGE_LAST))=@notify me; @tr me/DO_SHIFTPAGES=add(%1,1),[v(PAGE_LAST)],-1;
  73.  
  74. @@ Helper functions
  75. @@ helper function that shifts pages. warning: pretty slow. Usage: @tr BookName/DO_SHIFTPAGES=startpage,endpage,offset
  76. &DO_SHIFTPAGES Book=@dolist/notify/delimit | [cond( gt(%2,0), lnum(%1,%0,|) , lnum(%0,%1,|) )]={&PAGE`[add(##,%2)] me=v(PAGE`[##])}
  77.  
  78. @@ Helper function that checks if user can do anything to the book
  79. &DO_CHECK_USE Book=@break comp(num(%0),%!); @assert elock(me/user:use, %#)={@pemit/silent %#=You can't do anything with this book.};
  80. &DO_CHECK_EDIT Book=@assert elock(me/user:edit, %#)={@pemit/silent %#=You can't change contents of this book.};
Add Comment
Please, Sign In to add comment