Utility.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) - Violent Tulip
  4. //-----------------------------------------------------------------------------
  5. //-----------------------------------------------------------------------------
  6. //
  7. // Class
  8. //
  9. //-----------------------------------------------------------------------------
  10. function SimObject::isMemberOfClassList( %this, %typeList )
  11. {
  12. %typeCount = getWordCount( %typeList );
  13. for ( %i = 0; %i < %typeCount; %i++ )
  14. {
  15. if ( %this.isMemberOfClass( getWord( %typeList, %i ) ) )
  16. {
  17. return true;
  18. }
  19. }
  20. return false;
  21. }
  22. //-----------------------------------------------------------------------------
  23. //
  24. // GUI
  25. //
  26. //-----------------------------------------------------------------------------
  27. function GuiControl::getParentOfType( %this, %className )
  28. {
  29. %parent = %this.getParent();
  30. while ( isObject( %parent ) )
  31. {
  32. if ( %parent.isMemberOfClass( %className ) )
  33. {
  34. return %parent;
  35. }
  36. %parent = %parent.getParent();
  37. }
  38. return 0;
  39. }
  40. //-----------------------------------------------------------------------------
  41. //
  42. // STRING
  43. //
  44. //-----------------------------------------------------------------------------
  45. function isWordInList( %word, %list )
  46. {
  47. %wordCount = getWordCount( %list );
  48. for ( %i = 0; %i < %wordCount; %i++ )
  49. {
  50. if ( getWord( %list, %i ) $= %word )
  51. {
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57. function sortWordList( %list )
  58. {
  59. %wordCount = getWordCount( %list );
  60. for ( %j = 0; %j < %wordCount; %j++ )
  61. {
  62. for ( %i = %wordCount - 1; %i > %j; %i-- )
  63. {
  64. %wordA = getWord( %list, %i - 0 );
  65. %wordB = getWord( %list, %i - 1 );
  66. // Compare and swap if needed
  67. if ( strcmp( strlwr( %wordA ), strlwr( %wordB ) ) < 0 )
  68. {
  69. %list = setWord( %list, %i - 1, %wordA );
  70. %list = setWord( %list, %i - 0, %wordB );
  71. }
  72. }
  73. }
  74. return %list;
  75. }