Browse Source

[added] added array_func files to separate array manipulation functions

Pepegass 1 year ago
parent
commit
d1ba61a799
3 changed files with 127 additions and 34 deletions
  1. 2 1
      glife.qproj
  2. 78 0
      locations/array_func.qsrc
  3. 47 33
      locations/journal_quests_build.qsrc

+ 2 - 1
glife.qproj

@@ -16,7 +16,7 @@
 	<Location name="journal_portfolio"/>
 	<Location name="Cheatmenu_din"/>
 	<Location name="themes"/>
-	<Location name="journal_quests_build"/>
+	<Location name="journal_quests_build"/>	
 	<Folder name="System">
 		<Location name="counter"/>
 		<Location name="loadg"/>
@@ -73,6 +73,7 @@
 		<Location name="npc_finder"/>
 		<Location name="grades"/>
 		<Location name="internet_mobile"/>
+		<Location name="array_func"/>
 	</Folder>
 	<Folder name="Body">
 		<Location name="ApperanceSystem"/>

+ 78 - 0
locations/array_func.qsrc

@@ -0,0 +1,78 @@
+#arr_func
+
+!!Changes positons of 2 values in array
+!!$args[1] array name
+!!args[2] first element index
+!!args[3] second element index
+if $args[0] = 'reorderByIndex':
+    if instr($args[1], '$'):
+        dynamic '$tempValue = <<$args[1]>>[<<args[2]>>]'
+        dynamic '<<$args[1]>>[<<args[2]>>] = <<$args[1]>>[<<args[3]>>]'
+        dynamic '<<$args[1]>>[<<args[3]>>] = $tempValue'
+        killvar '$tempValue'
+    else
+        dynamic 'tempValue = <<$args[1]>>[<<args[2]>>]'
+        dynamic '<<$args[1]>>[<<args[2]>>] = <<$args[1]>>[<<args[3]>>]'
+        dynamic '<<$args[1]>>[<<args[3]>>] = tempValue'
+        killvar 'tempValue'
+    end
+end
+
+!!Removes value from array
+!!$args[1] array name
+!!$args[2] value that should removed
+if $args[0] = 'removeByValue':
+    if arrsize('<<$args[1]>>') > 0:
+        if instr($args[1], '$'):
+            dynamic 'i = arrpos("<<$args[1]>>", "<<$args[2]>>")'
+            if i <> -1: killvar '<<$args[1]>>', i
+        else
+            dynamic 'i = arrpos("<<$args[1]>>", <<args[2]>>)'
+            if i <> -1: killvar '<<$args[1]>>', i
+        end
+    end
+    killvar 'i'
+end
+
+!!Adding value to the end of array with check
+!!$args[1] array name
+!!$args[2] value
+if $args[0] = 'addUniqueByValue':
+    if instr($args[1], '$'):
+        if dyneval('result = arrpos("<<$args[1]>>", "<<$args[2]>>")') : dynamic '<<$args[1]>>[] = <<$args[2]>>' 
+    else
+        !!This is overcomplicated because arrpos doesnt return -1 if you look for '0' numeric value
+        !!conditions here are checking for 3 cases, array is empty, 0 not in the array, 0 in the array
+		temp = dyneval('result = arrpos("<<$args[1]>>", <<args[2]>>)')
+		size = dyneval('result = arrsize("<<$args[1]>>")')
+		*pl dyneval('result = arrpos("<<$args[1]>>", <<args[2]>>)')
+		if args[2] = 0:
+			!!checking for 0 edgecases
+			if size = 0 or temp = size:	dynamic '<<$args[1]>>[] = <<args[2]>>'
+		else	
+			if dyneval('result = arrpos("<<$args[1]>>", <<args[2]>>)'):
+				dynamic '<<$args[1]>>[] = <<args[2]>>'
+			end
+		end
+		killvar 'temp'
+		killvar 'size'
+    end    
+end
+
+
+!!Prints array in column
+if $args[0] = 'printArrayByName':
+    i = 0
+    size = arrsize('<<$args[1]>>')
+    :loopArray_l7dqGGraKI
+	if i < size : 		
+		*pl $dyneval('result = <<$args[1]>>[<<i>>]')
+		i += 1		
+		jump 'loopArray_l7dqGGraKI'
+	end 
+    killvar 'i'
+    killvar 'size'
+end
+
+--- arr_func ---------------------
+

+ 47 - 33
locations/journal_quests_build.qsrc

@@ -43,7 +43,7 @@ $questsDisplay
 !! Pavlovsk - pavlovsk quests filter
 !! Gadukino - gadukino quests filter
 
-journalBuilder['trackedQuests'] = 0
+!!journalBuilder['trackedQuests'] = 0
 !!journalBuilder['hideHeader'] toggle header on/off
 !!journalBuilder['questsMenu'] shows what menu item is currently active
 
@@ -53,7 +53,7 @@ $journalQuestsMenuOptions[2] = "St.Petersburg"
 $journalQuestsMenuOptions[3] = "Pavlovsk"
 $journalQuestsMenuOptions[4] = "Gadukino"
 
-pinnedQuests[0] = 0
+!!pinnedQuests[0] = 0
 
 
 if $args[0] = "pinned":
@@ -70,8 +70,8 @@ if $args[0] = "pinned":
         end       
     end
     if $args[1] = "unpin":
-        gs $this, 'pinned', 'remove', args[2]
-        gs $this, 'active', 'add', args[2]
+        gs 'journal_quests_build', 'pinned', 'remove', args[2]
+        gs 'journal_quests_build', 'active', 'add', args[2]
     end
     if $args[1] = "sort":
         tempCheckArray = arrpos('pinnedQuests', args[2])     
@@ -86,6 +86,9 @@ if $args[0] = "pinned":
         tempValue = pinnedQuests[tempFirstIndex]
         pinnedQuests[tempSecondIndex] = pinnedQuests[tempFirstIndex]
         pinnedQuests[tempFirstIndex] = tempValue
+        killvar 'tempValue' 
+        killvar 'tempCheckArray'
+        killvar 'tempFirstIndex'
     end
 end
 if $args[0] = "active":
@@ -101,34 +104,38 @@ if $args[0] = "active":
        
     end
     if $args[1] = "pin":        
-        gs $this, 'active', 'remove', args[2]
-        gs $this, 'pinned', 'add', args[2]
+        gs 'journal_quests_build', 'active', 'remove', args[2]
+        gs 'journal_quests_build', 'pinned', 'add', args[2]
     end
     if $args[1] = "sort":
-        tempCheckArray = arrpos('activeQuests', args[2])     
+        tempCheckArray = arrpos('activeQuests', args[2]) 
+        *pl "Moving index <<args[2]>> " + iif(args[3], "Down", "Up")     
         tempFirstIndex = tempCheckArray                
         size = arrsize('activeQuests')
-        !!depending on if we move quest up or down the list
+        !!depending on argument 0 or 1 we move quest up or down the list
         if args[3] = 0:            
             tempSecondIndex = tempCheckArray - 1
         else
             tempSecondIndex = tempCheckArray + 1
         end
         tempValue = activeQuests[tempFirstIndex]
-        activeQuests[tempSecondIndex] = activeQuests[tempFirstIndex]
-        activeQuests[tempFirstIndex] = tempValue
+        activeQuests[tempFirstIndex] = activeQuests[tempSecondIndex]
+        activeQuests[tempSecondIndex] = tempValue
+        killvar 'tempValue' 
+        killvar 'tempCheckArray'
+        killvar 'tempFirstIndex'
     end
 end
 
 if $args[0] = "track":
     if (arrpos('pinnedQuests', args[1]) = -1) and (arrpos('activeQuests', args[1]) = -1):
-        gs $this, 'active', 'add', args[1]
+        gs 'journal_quests_build', 'active', 'add', args[1]
     end
 end
 
 if $args[0] = "untrack":
-    gs $this, 'pinned', 'remove', args[1]
-    gs $this, 'active', 'remove', args[1]
+    gs 'journal_quests_build', 'pinned', 'remove', args[1]
+    gs 'journal_quests_build', 'active', 'remove', args[1]
 end
 
 if $args[0] = "locationFiltered":
@@ -155,12 +162,11 @@ if journalBuilder['hideHeader'] = 0:
 end
 
 "Args"
-"0: <<args[0]>>"
-"1: <<args[1]>>"
-"2: <<args[2]>>"
-"3: <<args[3]>>"
+"0: <<$args[0]>>"
+if isnum(args[1]): "1: <<args[1]>>" else "1: <<$args[1]>>"
+if isnum(args[2]): "2: <<args[2]>>" else "2: <<$args[2]>>"
+if isnum(args[3]): "3: <<args[3]>>" else "3: <<$args[3]>>"
 
-$this = 'journal_quests_build'
 
 !!*p '<table width="90%" align="center" width="90%" cellspacing="0" cellpadding="0" valign="top"><tr>' 
 *p '<table width="90%" align="center" cellspacing="10" cellpadding="0" valign="top"><tr>' 
@@ -184,10 +190,10 @@ if journalBuilder['questsMenu'] = 0:
         :loopPinnedArr
         if i < size:
             *p $questsArr[pinnedQuests[i]]
-            if i > 0 and (i + 1) < size : *p '<a href="exec:gs $this, ''pinned'', ''sort'', <<i>>, 0">Up</a> | '
-            if i < (size - 2): *p '<a href="exec:gs $this, ''pinned'', ''sort'', <<i>>, 1">Down</a> | '
-            *p '<a href="exec:gs $this, ''pinned'', ''unpin'', <<i>>">Unpin</a> | '
-            *p '<a href="exec:gs $this, ''untrack'', <<i>>">Untrack</a>'
+            if i > 0 and (i + 1) < size : *p '<a href="exec:gs ''journal_quests_build'', ''pinned'', ''sort'', <<i>>, 0">Up</a> | '
+            if i < (size - 2): *p '<a href="exec:gs ''journal_quests_build'', ''pinned'', ''sort'', <<i>>, 1">Down</a> | '
+            *p '<a href="exec:gs ''journal_quests_build'', ''pinned'', ''unpin'', <<i>>">Unpin</a> | '
+            *p '<a href="exec:gs ''journal_quests_build'', ''untrack'', <<i>>">Untrack</a>'
             *nl
             i += 1 & jump 'loopPinnedArr'
         end        
@@ -201,11 +207,11 @@ if journalBuilder['questsMenu'] = 0:
         i = 0
         :loopActiveArr
         if i < size:
-            *p $questsArr[activeQuests[i]]  
-            if i > 0 and (i + 1) < size : *p '<a href="exec:gs $this, ''active'', ''sort'', <<i>>, 0">Up</a> | '
-            if i < (size - 2): *p '<a href="exec:gs $this, ''active'', ''sort'', <<i>>, 1">Down</a> | '
-            *p '<a href="exec:gs $this, ''active'', ''unpin'', <<i>>">Unpin</a> | '
-            *p '<a href="exec:gs $this, ''untrack'', <<i>>">Untrack</a>'
+            *p $questsArr[activeQuests[i]] + "" 
+            if i > 0 : *p '<a href="exec:gs ''journal_quests_build'', ''active'', ''sort'', <<i>>, 0">Up</a> | '
+            if i < (size - 1): *p '<a href="exec:gs ''journal_quests_build'', ''active'', ''sort'', <<i>>, 1">Down</a> | '
+            *p ' <a href="exec:gs ''journal_quests_build'', ''active'', ''pin'', <<i>>">Pin</a> | '
+            *p '<a href="exec:gs ''journal_quests_build'', ''untrack'', <<i>>">Untrack</a>'
             *nl
             i += 1 & jump 'loopActiveArr'            
         end         
@@ -216,18 +222,26 @@ if journalBuilder['questsMenu'] = 1:
     *pl "All available quests"
     i = 0
     size = arrsize('$questsArr')  
-    :loopAllQuests
-    if arrsize('activeQuests', i) = 0 and arrsize('pinnedQuests', i) 
+    :loopAllQuests    
+    tempIsNonActive = (arrsize('activeQuests') > 0) and (arrpos('activeQuests', i) <> -1) and (arrpos('activeQuests', i) <> arrsize('activeQuests'))
+    tempIsNonPinned = (arrsize('pinnedQuests') > 0) and (arrpos('pinnedQuests', i) <> -1) and (arrpos('pinnedQuests', i) <> arrsize('pinnedQuests'))
     if i < size:
         *p $questsArr[i]
-        *p "; isActive = " + tempIsActive + "; is Pinned ="+ tempIsPinned +";   "
-        if tempIsActive = -1 and tempIsPinned = -1:
-            *p '<a href="exec:gs $this, ''pinned'', ''add'', <<i>>">Pin</a> | '
-            *p '<a href="exec:gs $this, ''track'', <<i>>">Track</a>'
+        *p "   activeQuests: " + (arrsize('activeQuests') > 0) + " and " + (arrpos('activeQuests', i) <> -1)
+        *p "  |    pinnedQuests: " + (arrsize('pinnedQuests') > 0) + " and " + (arrpos('pinnedQuests', i) <> -1) + "     "
+        if (no tempIsNonPinned) and (no tempIsNonActive):
+            *p '<a href="exec:gs ''journal_quests_build'', ''pinned'', ''add'', <<i>>">Pin</a> | '
+            *p '<a href="exec:gs ''journal_quests_build'', ''track'', <<i>>">Track</a>'
+        else 
+            *p '<a href="exec:gs ''journal_quests_build'', ''untrack'', <<i>>">Untrack</a>'
         end
         *nl
         i += 1 & jump 'loopAllQuests'
     end        
+    killvar 'tempIsNonActive'
+    killvar 'tempIsNonPinned'
+    killvar 'size'
+    killvar 'i'
 end
 if journalBuilder['questsMenu'] = 2:
     *pl "Display City quests"