webgal-parser 4.6.1 → 4.6.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/es/index.js CHANGED
@@ -35,6 +35,7 @@ var commandType;
35
35
  commandType[commandType["applyStyle"] = 32] = "applyStyle";
36
36
  commandType[commandType["wait"] = 33] = "wait";
37
37
  commandType[commandType["callSteam"] = 34] = "callSteam";
38
+ commandType[commandType["return"] = 35] = "return";
38
39
  })(commandType || (commandType = {}));
39
40
 
40
41
  const SCRIPT_CONFIG = [
@@ -76,6 +77,7 @@ const SCRIPT_CONFIG = [
76
77
  { scriptString: 'applyStyle', scriptType: commandType.applyStyle },
77
78
  { scriptString: 'wait', scriptType: commandType.wait },
78
79
  { scriptString: 'callSteam', scriptType: commandType.callSteam },
80
+ { scriptString: 'return', scriptType: commandType.return },
79
81
  ];
80
82
  const ADD_NEXT_ARG_LIST = [
81
83
  commandType.bgm,
@@ -134,7 +136,7 @@ function argsParser(argsRaw, assetSetter) {
134
136
  argValue = undefined;
135
137
  }
136
138
  // 判断是不是语音参数
137
- if (argName.toLowerCase().match(/.ogg|.mp3|.wav/)) {
139
+ if (argName.toLowerCase().match(/.ogg|.mp3|.wav|.opus/)) {
138
140
  returnArrayList.push({
139
141
  key: 'vocal',
140
142
  value: assetSetter(e, fileType.vocal),
@@ -449,7 +451,7 @@ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG
449
451
  const commentSplit = sentenceRaw.split(/(?<!\\);/);
450
452
  let newSentenceRaw = commentSplit[0];
451
453
  newSentenceRaw = newSentenceRaw.replaceAll('\\;', ';');
452
- const sentenceComment = commentSplit[1] ?? '';
454
+ const sentenceComment = commentSplit.slice(1).join(';');
453
455
  if (newSentenceRaw.trim() === '') {
454
456
  // 注释提前返回
455
457
  return {
@@ -459,7 +461,10 @@ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG
459
461
  args: [{ key: 'next', value: true }],
460
462
  sentenceAssets: [],
461
463
  subScene: [],
462
- inlineComment: '', // 行内注释
464
+ inlineComment: '',
465
+ startLine: lineNumber,
466
+ endLine: lineNumber,
467
+ isLineBreakHolder: false,
463
468
  };
464
469
  }
465
470
  // 截取命令
@@ -510,1326 +515,14 @@ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG
510
515
  args: args,
511
516
  sentenceAssets: sentenceAssets,
512
517
  subScene: subScene,
513
- inlineComment: sentenceComment.trim(), // 行内注释
518
+ inlineComment: sentenceComment.trim(),
519
+ // 单行语句的行范围就是自己,多行语句的 endLine 由 sceneParser 回填
520
+ startLine: lineNumber,
521
+ endLine: lineNumber,
522
+ isLineBreakHolder: false,
514
523
  };
515
524
  };
516
525
 
517
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
518
-
519
- /** Detect free variable `global` from Node.js. */
520
-
521
- var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
522
-
523
- var _freeGlobal = freeGlobal$1;
524
-
525
- var freeGlobal = _freeGlobal;
526
-
527
- /** Detect free variable `self`. */
528
- var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
529
-
530
- /** Used as a reference to the global object. */
531
- var root$4 = freeGlobal || freeSelf || Function('return this')();
532
-
533
- var _root = root$4;
534
-
535
- var root$3 = _root;
536
-
537
- /** Built-in value references. */
538
- var Symbol$2 = root$3.Symbol;
539
-
540
- var _Symbol = Symbol$2;
541
-
542
- var Symbol$1 = _Symbol;
543
-
544
- /** Used for built-in method references. */
545
- var objectProto$4 = Object.prototype;
546
-
547
- /** Used to check objects for own properties. */
548
- var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
549
-
550
- /**
551
- * Used to resolve the
552
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
553
- * of values.
554
- */
555
- var nativeObjectToString$1 = objectProto$4.toString;
556
-
557
- /** Built-in value references. */
558
- var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
559
-
560
- /**
561
- * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
562
- *
563
- * @private
564
- * @param {*} value The value to query.
565
- * @returns {string} Returns the raw `toStringTag`.
566
- */
567
- function getRawTag$1(value) {
568
- var isOwn = hasOwnProperty$3.call(value, symToStringTag$1),
569
- tag = value[symToStringTag$1];
570
-
571
- try {
572
- value[symToStringTag$1] = undefined;
573
- var unmasked = true;
574
- } catch (e) {}
575
-
576
- var result = nativeObjectToString$1.call(value);
577
- if (unmasked) {
578
- if (isOwn) {
579
- value[symToStringTag$1] = tag;
580
- } else {
581
- delete value[symToStringTag$1];
582
- }
583
- }
584
- return result;
585
- }
586
-
587
- var _getRawTag = getRawTag$1;
588
-
589
- /** Used for built-in method references. */
590
-
591
- var objectProto$3 = Object.prototype;
592
-
593
- /**
594
- * Used to resolve the
595
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
596
- * of values.
597
- */
598
- var nativeObjectToString = objectProto$3.toString;
599
-
600
- /**
601
- * Converts `value` to a string using `Object.prototype.toString`.
602
- *
603
- * @private
604
- * @param {*} value The value to convert.
605
- * @returns {string} Returns the converted string.
606
- */
607
- function objectToString$1(value) {
608
- return nativeObjectToString.call(value);
609
- }
610
-
611
- var _objectToString = objectToString$1;
612
-
613
- var Symbol = _Symbol,
614
- getRawTag = _getRawTag,
615
- objectToString = _objectToString;
616
-
617
- /** `Object#toString` result references. */
618
- var nullTag = '[object Null]',
619
- undefinedTag = '[object Undefined]';
620
-
621
- /** Built-in value references. */
622
- var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
623
-
624
- /**
625
- * The base implementation of `getTag` without fallbacks for buggy environments.
626
- *
627
- * @private
628
- * @param {*} value The value to query.
629
- * @returns {string} Returns the `toStringTag`.
630
- */
631
- function baseGetTag$1(value) {
632
- if (value == null) {
633
- return value === undefined ? undefinedTag : nullTag;
634
- }
635
- return (symToStringTag && symToStringTag in Object(value))
636
- ? getRawTag(value)
637
- : objectToString(value);
638
- }
639
-
640
- var _baseGetTag = baseGetTag$1;
641
-
642
- /**
643
- * Checks if `value` is the
644
- * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
645
- * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
646
- *
647
- * @static
648
- * @memberOf _
649
- * @since 0.1.0
650
- * @category Lang
651
- * @param {*} value The value to check.
652
- * @returns {boolean} Returns `true` if `value` is an object, else `false`.
653
- * @example
654
- *
655
- * _.isObject({});
656
- * // => true
657
- *
658
- * _.isObject([1, 2, 3]);
659
- * // => true
660
- *
661
- * _.isObject(_.noop);
662
- * // => true
663
- *
664
- * _.isObject(null);
665
- * // => false
666
- */
667
-
668
- function isObject$2(value) {
669
- var type = typeof value;
670
- return value != null && (type == 'object' || type == 'function');
671
- }
672
-
673
- var isObject_1 = isObject$2;
674
-
675
- var baseGetTag = _baseGetTag,
676
- isObject$1 = isObject_1;
677
-
678
- /** `Object#toString` result references. */
679
- var asyncTag = '[object AsyncFunction]',
680
- funcTag = '[object Function]',
681
- genTag = '[object GeneratorFunction]',
682
- proxyTag = '[object Proxy]';
683
-
684
- /**
685
- * Checks if `value` is classified as a `Function` object.
686
- *
687
- * @static
688
- * @memberOf _
689
- * @since 0.1.0
690
- * @category Lang
691
- * @param {*} value The value to check.
692
- * @returns {boolean} Returns `true` if `value` is a function, else `false`.
693
- * @example
694
- *
695
- * _.isFunction(_);
696
- * // => true
697
- *
698
- * _.isFunction(/abc/);
699
- * // => false
700
- */
701
- function isFunction$1(value) {
702
- if (!isObject$1(value)) {
703
- return false;
704
- }
705
- // The use of `Object#toString` avoids issues with the `typeof` operator
706
- // in Safari 9 which returns 'object' for typed arrays and other constructors.
707
- var tag = baseGetTag(value);
708
- return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
709
- }
710
-
711
- var isFunction_1 = isFunction$1;
712
-
713
- var root$2 = _root;
714
-
715
- /** Used to detect overreaching core-js shims. */
716
- var coreJsData$1 = root$2['__core-js_shared__'];
717
-
718
- var _coreJsData = coreJsData$1;
719
-
720
- var coreJsData = _coreJsData;
721
-
722
- /** Used to detect methods masquerading as native. */
723
- var maskSrcKey = (function() {
724
- var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
725
- return uid ? ('Symbol(src)_1.' + uid) : '';
726
- }());
727
-
728
- /**
729
- * Checks if `func` has its source masked.
730
- *
731
- * @private
732
- * @param {Function} func The function to check.
733
- * @returns {boolean} Returns `true` if `func` is masked, else `false`.
734
- */
735
- function isMasked$1(func) {
736
- return !!maskSrcKey && (maskSrcKey in func);
737
- }
738
-
739
- var _isMasked = isMasked$1;
740
-
741
- /** Used for built-in method references. */
742
-
743
- var funcProto$1 = Function.prototype;
744
-
745
- /** Used to resolve the decompiled source of functions. */
746
- var funcToString$1 = funcProto$1.toString;
747
-
748
- /**
749
- * Converts `func` to its source code.
750
- *
751
- * @private
752
- * @param {Function} func The function to convert.
753
- * @returns {string} Returns the source code.
754
- */
755
- function toSource$1(func) {
756
- if (func != null) {
757
- try {
758
- return funcToString$1.call(func);
759
- } catch (e) {}
760
- try {
761
- return (func + '');
762
- } catch (e) {}
763
- }
764
- return '';
765
- }
766
-
767
- var _toSource = toSource$1;
768
-
769
- var isFunction = isFunction_1,
770
- isMasked = _isMasked,
771
- isObject = isObject_1,
772
- toSource = _toSource;
773
-
774
- /**
775
- * Used to match `RegExp`
776
- * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
777
- */
778
- var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
779
-
780
- /** Used to detect host constructors (Safari). */
781
- var reIsHostCtor = /^\[object .+?Constructor\]$/;
782
-
783
- /** Used for built-in method references. */
784
- var funcProto = Function.prototype,
785
- objectProto$2 = Object.prototype;
786
-
787
- /** Used to resolve the decompiled source of functions. */
788
- var funcToString = funcProto.toString;
789
-
790
- /** Used to check objects for own properties. */
791
- var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
792
-
793
- /** Used to detect if a method is native. */
794
- var reIsNative = RegExp('^' +
795
- funcToString.call(hasOwnProperty$2).replace(reRegExpChar, '\\$&')
796
- .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
797
- );
798
-
799
- /**
800
- * The base implementation of `_.isNative` without bad shim checks.
801
- *
802
- * @private
803
- * @param {*} value The value to check.
804
- * @returns {boolean} Returns `true` if `value` is a native function,
805
- * else `false`.
806
- */
807
- function baseIsNative$1(value) {
808
- if (!isObject(value) || isMasked(value)) {
809
- return false;
810
- }
811
- var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
812
- return pattern.test(toSource(value));
813
- }
814
-
815
- var _baseIsNative = baseIsNative$1;
816
-
817
- /**
818
- * Gets the value at `key` of `object`.
819
- *
820
- * @private
821
- * @param {Object} [object] The object to query.
822
- * @param {string} key The key of the property to get.
823
- * @returns {*} Returns the property value.
824
- */
825
-
826
- function getValue$1(object, key) {
827
- return object == null ? undefined : object[key];
828
- }
829
-
830
- var _getValue = getValue$1;
831
-
832
- var baseIsNative = _baseIsNative,
833
- getValue = _getValue;
834
-
835
- /**
836
- * Gets the native function at `key` of `object`.
837
- *
838
- * @private
839
- * @param {Object} object The object to query.
840
- * @param {string} key The key of the method to get.
841
- * @returns {*} Returns the function if it's native, else `undefined`.
842
- */
843
- function getNative$3(object, key) {
844
- var value = getValue(object, key);
845
- return baseIsNative(value) ? value : undefined;
846
- }
847
-
848
- var _getNative = getNative$3;
849
-
850
- var getNative$2 = _getNative;
851
-
852
- /* Built-in method references that are verified to be native. */
853
- var nativeCreate$4 = getNative$2(Object, 'create');
854
-
855
- var _nativeCreate = nativeCreate$4;
856
-
857
- var nativeCreate$3 = _nativeCreate;
858
-
859
- /**
860
- * Removes all key-value entries from the hash.
861
- *
862
- * @private
863
- * @name clear
864
- * @memberOf Hash
865
- */
866
- function hashClear$1() {
867
- this.__data__ = nativeCreate$3 ? nativeCreate$3(null) : {};
868
- this.size = 0;
869
- }
870
-
871
- var _hashClear = hashClear$1;
872
-
873
- /**
874
- * Removes `key` and its value from the hash.
875
- *
876
- * @private
877
- * @name delete
878
- * @memberOf Hash
879
- * @param {Object} hash The hash to modify.
880
- * @param {string} key The key of the value to remove.
881
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
882
- */
883
-
884
- function hashDelete$1(key) {
885
- var result = this.has(key) && delete this.__data__[key];
886
- this.size -= result ? 1 : 0;
887
- return result;
888
- }
889
-
890
- var _hashDelete = hashDelete$1;
891
-
892
- var nativeCreate$2 = _nativeCreate;
893
-
894
- /** Used to stand-in for `undefined` hash values. */
895
- var HASH_UNDEFINED$2 = '__lodash_hash_undefined__';
896
-
897
- /** Used for built-in method references. */
898
- var objectProto$1 = Object.prototype;
899
-
900
- /** Used to check objects for own properties. */
901
- var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
902
-
903
- /**
904
- * Gets the hash value for `key`.
905
- *
906
- * @private
907
- * @name get
908
- * @memberOf Hash
909
- * @param {string} key The key of the value to get.
910
- * @returns {*} Returns the entry value.
911
- */
912
- function hashGet$1(key) {
913
- var data = this.__data__;
914
- if (nativeCreate$2) {
915
- var result = data[key];
916
- return result === HASH_UNDEFINED$2 ? undefined : result;
917
- }
918
- return hasOwnProperty$1.call(data, key) ? data[key] : undefined;
919
- }
920
-
921
- var _hashGet = hashGet$1;
922
-
923
- var nativeCreate$1 = _nativeCreate;
924
-
925
- /** Used for built-in method references. */
926
- var objectProto = Object.prototype;
927
-
928
- /** Used to check objects for own properties. */
929
- var hasOwnProperty = objectProto.hasOwnProperty;
930
-
931
- /**
932
- * Checks if a hash value for `key` exists.
933
- *
934
- * @private
935
- * @name has
936
- * @memberOf Hash
937
- * @param {string} key The key of the entry to check.
938
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
939
- */
940
- function hashHas$1(key) {
941
- var data = this.__data__;
942
- return nativeCreate$1 ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
943
- }
944
-
945
- var _hashHas = hashHas$1;
946
-
947
- var nativeCreate = _nativeCreate;
948
-
949
- /** Used to stand-in for `undefined` hash values. */
950
- var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
951
-
952
- /**
953
- * Sets the hash `key` to `value`.
954
- *
955
- * @private
956
- * @name set
957
- * @memberOf Hash
958
- * @param {string} key The key of the value to set.
959
- * @param {*} value The value to set.
960
- * @returns {Object} Returns the hash instance.
961
- */
962
- function hashSet$1(key, value) {
963
- var data = this.__data__;
964
- this.size += this.has(key) ? 0 : 1;
965
- data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED$1 : value;
966
- return this;
967
- }
968
-
969
- var _hashSet = hashSet$1;
970
-
971
- var hashClear = _hashClear,
972
- hashDelete = _hashDelete,
973
- hashGet = _hashGet,
974
- hashHas = _hashHas,
975
- hashSet = _hashSet;
976
-
977
- /**
978
- * Creates a hash object.
979
- *
980
- * @private
981
- * @constructor
982
- * @param {Array} [entries] The key-value pairs to cache.
983
- */
984
- function Hash$1(entries) {
985
- var index = -1,
986
- length = entries == null ? 0 : entries.length;
987
-
988
- this.clear();
989
- while (++index < length) {
990
- var entry = entries[index];
991
- this.set(entry[0], entry[1]);
992
- }
993
- }
994
-
995
- // Add methods to `Hash`.
996
- Hash$1.prototype.clear = hashClear;
997
- Hash$1.prototype['delete'] = hashDelete;
998
- Hash$1.prototype.get = hashGet;
999
- Hash$1.prototype.has = hashHas;
1000
- Hash$1.prototype.set = hashSet;
1001
-
1002
- var _Hash = Hash$1;
1003
-
1004
- /**
1005
- * Removes all key-value entries from the list cache.
1006
- *
1007
- * @private
1008
- * @name clear
1009
- * @memberOf ListCache
1010
- */
1011
-
1012
- function listCacheClear$1() {
1013
- this.__data__ = [];
1014
- this.size = 0;
1015
- }
1016
-
1017
- var _listCacheClear = listCacheClear$1;
1018
-
1019
- /**
1020
- * Performs a
1021
- * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1022
- * comparison between two values to determine if they are equivalent.
1023
- *
1024
- * @static
1025
- * @memberOf _
1026
- * @since 4.0.0
1027
- * @category Lang
1028
- * @param {*} value The value to compare.
1029
- * @param {*} other The other value to compare.
1030
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1031
- * @example
1032
- *
1033
- * var object = { 'a': 1 };
1034
- * var other = { 'a': 1 };
1035
- *
1036
- * _.eq(object, object);
1037
- * // => true
1038
- *
1039
- * _.eq(object, other);
1040
- * // => false
1041
- *
1042
- * _.eq('a', 'a');
1043
- * // => true
1044
- *
1045
- * _.eq('a', Object('a'));
1046
- * // => false
1047
- *
1048
- * _.eq(NaN, NaN);
1049
- * // => true
1050
- */
1051
-
1052
- function eq$1(value, other) {
1053
- return value === other || (value !== value && other !== other);
1054
- }
1055
-
1056
- var eq_1 = eq$1;
1057
-
1058
- var eq = eq_1;
1059
-
1060
- /**
1061
- * Gets the index at which the `key` is found in `array` of key-value pairs.
1062
- *
1063
- * @private
1064
- * @param {Array} array The array to inspect.
1065
- * @param {*} key The key to search for.
1066
- * @returns {number} Returns the index of the matched value, else `-1`.
1067
- */
1068
- function assocIndexOf$4(array, key) {
1069
- var length = array.length;
1070
- while (length--) {
1071
- if (eq(array[length][0], key)) {
1072
- return length;
1073
- }
1074
- }
1075
- return -1;
1076
- }
1077
-
1078
- var _assocIndexOf = assocIndexOf$4;
1079
-
1080
- var assocIndexOf$3 = _assocIndexOf;
1081
-
1082
- /** Used for built-in method references. */
1083
- var arrayProto = Array.prototype;
1084
-
1085
- /** Built-in value references. */
1086
- var splice = arrayProto.splice;
1087
-
1088
- /**
1089
- * Removes `key` and its value from the list cache.
1090
- *
1091
- * @private
1092
- * @name delete
1093
- * @memberOf ListCache
1094
- * @param {string} key The key of the value to remove.
1095
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1096
- */
1097
- function listCacheDelete$1(key) {
1098
- var data = this.__data__,
1099
- index = assocIndexOf$3(data, key);
1100
-
1101
- if (index < 0) {
1102
- return false;
1103
- }
1104
- var lastIndex = data.length - 1;
1105
- if (index == lastIndex) {
1106
- data.pop();
1107
- } else {
1108
- splice.call(data, index, 1);
1109
- }
1110
- --this.size;
1111
- return true;
1112
- }
1113
-
1114
- var _listCacheDelete = listCacheDelete$1;
1115
-
1116
- var assocIndexOf$2 = _assocIndexOf;
1117
-
1118
- /**
1119
- * Gets the list cache value for `key`.
1120
- *
1121
- * @private
1122
- * @name get
1123
- * @memberOf ListCache
1124
- * @param {string} key The key of the value to get.
1125
- * @returns {*} Returns the entry value.
1126
- */
1127
- function listCacheGet$1(key) {
1128
- var data = this.__data__,
1129
- index = assocIndexOf$2(data, key);
1130
-
1131
- return index < 0 ? undefined : data[index][1];
1132
- }
1133
-
1134
- var _listCacheGet = listCacheGet$1;
1135
-
1136
- var assocIndexOf$1 = _assocIndexOf;
1137
-
1138
- /**
1139
- * Checks if a list cache value for `key` exists.
1140
- *
1141
- * @private
1142
- * @name has
1143
- * @memberOf ListCache
1144
- * @param {string} key The key of the entry to check.
1145
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1146
- */
1147
- function listCacheHas$1(key) {
1148
- return assocIndexOf$1(this.__data__, key) > -1;
1149
- }
1150
-
1151
- var _listCacheHas = listCacheHas$1;
1152
-
1153
- var assocIndexOf = _assocIndexOf;
1154
-
1155
- /**
1156
- * Sets the list cache `key` to `value`.
1157
- *
1158
- * @private
1159
- * @name set
1160
- * @memberOf ListCache
1161
- * @param {string} key The key of the value to set.
1162
- * @param {*} value The value to set.
1163
- * @returns {Object} Returns the list cache instance.
1164
- */
1165
- function listCacheSet$1(key, value) {
1166
- var data = this.__data__,
1167
- index = assocIndexOf(data, key);
1168
-
1169
- if (index < 0) {
1170
- ++this.size;
1171
- data.push([key, value]);
1172
- } else {
1173
- data[index][1] = value;
1174
- }
1175
- return this;
1176
- }
1177
-
1178
- var _listCacheSet = listCacheSet$1;
1179
-
1180
- var listCacheClear = _listCacheClear,
1181
- listCacheDelete = _listCacheDelete,
1182
- listCacheGet = _listCacheGet,
1183
- listCacheHas = _listCacheHas,
1184
- listCacheSet = _listCacheSet;
1185
-
1186
- /**
1187
- * Creates an list cache object.
1188
- *
1189
- * @private
1190
- * @constructor
1191
- * @param {Array} [entries] The key-value pairs to cache.
1192
- */
1193
- function ListCache$1(entries) {
1194
- var index = -1,
1195
- length = entries == null ? 0 : entries.length;
1196
-
1197
- this.clear();
1198
- while (++index < length) {
1199
- var entry = entries[index];
1200
- this.set(entry[0], entry[1]);
1201
- }
1202
- }
1203
-
1204
- // Add methods to `ListCache`.
1205
- ListCache$1.prototype.clear = listCacheClear;
1206
- ListCache$1.prototype['delete'] = listCacheDelete;
1207
- ListCache$1.prototype.get = listCacheGet;
1208
- ListCache$1.prototype.has = listCacheHas;
1209
- ListCache$1.prototype.set = listCacheSet;
1210
-
1211
- var _ListCache = ListCache$1;
1212
-
1213
- var getNative$1 = _getNative,
1214
- root$1 = _root;
1215
-
1216
- /* Built-in method references that are verified to be native. */
1217
- var Map$2 = getNative$1(root$1, 'Map');
1218
-
1219
- var _Map = Map$2;
1220
-
1221
- var Hash = _Hash,
1222
- ListCache = _ListCache,
1223
- Map$1 = _Map;
1224
-
1225
- /**
1226
- * Removes all key-value entries from the map.
1227
- *
1228
- * @private
1229
- * @name clear
1230
- * @memberOf MapCache
1231
- */
1232
- function mapCacheClear$1() {
1233
- this.size = 0;
1234
- this.__data__ = {
1235
- 'hash': new Hash,
1236
- 'map': new (Map$1 || ListCache),
1237
- 'string': new Hash
1238
- };
1239
- }
1240
-
1241
- var _mapCacheClear = mapCacheClear$1;
1242
-
1243
- /**
1244
- * Checks if `value` is suitable for use as unique object key.
1245
- *
1246
- * @private
1247
- * @param {*} value The value to check.
1248
- * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
1249
- */
1250
-
1251
- function isKeyable$1(value) {
1252
- var type = typeof value;
1253
- return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
1254
- ? (value !== '__proto__')
1255
- : (value === null);
1256
- }
1257
-
1258
- var _isKeyable = isKeyable$1;
1259
-
1260
- var isKeyable = _isKeyable;
1261
-
1262
- /**
1263
- * Gets the data for `map`.
1264
- *
1265
- * @private
1266
- * @param {Object} map The map to query.
1267
- * @param {string} key The reference key.
1268
- * @returns {*} Returns the map data.
1269
- */
1270
- function getMapData$4(map, key) {
1271
- var data = map.__data__;
1272
- return isKeyable(key)
1273
- ? data[typeof key == 'string' ? 'string' : 'hash']
1274
- : data.map;
1275
- }
1276
-
1277
- var _getMapData = getMapData$4;
1278
-
1279
- var getMapData$3 = _getMapData;
1280
-
1281
- /**
1282
- * Removes `key` and its value from the map.
1283
- *
1284
- * @private
1285
- * @name delete
1286
- * @memberOf MapCache
1287
- * @param {string} key The key of the value to remove.
1288
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1289
- */
1290
- function mapCacheDelete$1(key) {
1291
- var result = getMapData$3(this, key)['delete'](key);
1292
- this.size -= result ? 1 : 0;
1293
- return result;
1294
- }
1295
-
1296
- var _mapCacheDelete = mapCacheDelete$1;
1297
-
1298
- var getMapData$2 = _getMapData;
1299
-
1300
- /**
1301
- * Gets the map value for `key`.
1302
- *
1303
- * @private
1304
- * @name get
1305
- * @memberOf MapCache
1306
- * @param {string} key The key of the value to get.
1307
- * @returns {*} Returns the entry value.
1308
- */
1309
- function mapCacheGet$1(key) {
1310
- return getMapData$2(this, key).get(key);
1311
- }
1312
-
1313
- var _mapCacheGet = mapCacheGet$1;
1314
-
1315
- var getMapData$1 = _getMapData;
1316
-
1317
- /**
1318
- * Checks if a map value for `key` exists.
1319
- *
1320
- * @private
1321
- * @name has
1322
- * @memberOf MapCache
1323
- * @param {string} key The key of the entry to check.
1324
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1325
- */
1326
- function mapCacheHas$1(key) {
1327
- return getMapData$1(this, key).has(key);
1328
- }
1329
-
1330
- var _mapCacheHas = mapCacheHas$1;
1331
-
1332
- var getMapData = _getMapData;
1333
-
1334
- /**
1335
- * Sets the map `key` to `value`.
1336
- *
1337
- * @private
1338
- * @name set
1339
- * @memberOf MapCache
1340
- * @param {string} key The key of the value to set.
1341
- * @param {*} value The value to set.
1342
- * @returns {Object} Returns the map cache instance.
1343
- */
1344
- function mapCacheSet$1(key, value) {
1345
- var data = getMapData(this, key),
1346
- size = data.size;
1347
-
1348
- data.set(key, value);
1349
- this.size += data.size == size ? 0 : 1;
1350
- return this;
1351
- }
1352
-
1353
- var _mapCacheSet = mapCacheSet$1;
1354
-
1355
- var mapCacheClear = _mapCacheClear,
1356
- mapCacheDelete = _mapCacheDelete,
1357
- mapCacheGet = _mapCacheGet,
1358
- mapCacheHas = _mapCacheHas,
1359
- mapCacheSet = _mapCacheSet;
1360
-
1361
- /**
1362
- * Creates a map cache object to store key-value pairs.
1363
- *
1364
- * @private
1365
- * @constructor
1366
- * @param {Array} [entries] The key-value pairs to cache.
1367
- */
1368
- function MapCache$1(entries) {
1369
- var index = -1,
1370
- length = entries == null ? 0 : entries.length;
1371
-
1372
- this.clear();
1373
- while (++index < length) {
1374
- var entry = entries[index];
1375
- this.set(entry[0], entry[1]);
1376
- }
1377
- }
1378
-
1379
- // Add methods to `MapCache`.
1380
- MapCache$1.prototype.clear = mapCacheClear;
1381
- MapCache$1.prototype['delete'] = mapCacheDelete;
1382
- MapCache$1.prototype.get = mapCacheGet;
1383
- MapCache$1.prototype.has = mapCacheHas;
1384
- MapCache$1.prototype.set = mapCacheSet;
1385
-
1386
- var _MapCache = MapCache$1;
1387
-
1388
- /** Used to stand-in for `undefined` hash values. */
1389
-
1390
- var HASH_UNDEFINED = '__lodash_hash_undefined__';
1391
-
1392
- /**
1393
- * Adds `value` to the array cache.
1394
- *
1395
- * @private
1396
- * @name add
1397
- * @memberOf SetCache
1398
- * @alias push
1399
- * @param {*} value The value to cache.
1400
- * @returns {Object} Returns the cache instance.
1401
- */
1402
- function setCacheAdd$1(value) {
1403
- this.__data__.set(value, HASH_UNDEFINED);
1404
- return this;
1405
- }
1406
-
1407
- var _setCacheAdd = setCacheAdd$1;
1408
-
1409
- /**
1410
- * Checks if `value` is in the array cache.
1411
- *
1412
- * @private
1413
- * @name has
1414
- * @memberOf SetCache
1415
- * @param {*} value The value to search for.
1416
- * @returns {number} Returns `true` if `value` is found, else `false`.
1417
- */
1418
-
1419
- function setCacheHas$1(value) {
1420
- return this.__data__.has(value);
1421
- }
1422
-
1423
- var _setCacheHas = setCacheHas$1;
1424
-
1425
- var MapCache = _MapCache,
1426
- setCacheAdd = _setCacheAdd,
1427
- setCacheHas = _setCacheHas;
1428
-
1429
- /**
1430
- *
1431
- * Creates an array cache object to store unique values.
1432
- *
1433
- * @private
1434
- * @constructor
1435
- * @param {Array} [values] The values to cache.
1436
- */
1437
- function SetCache$1(values) {
1438
- var index = -1,
1439
- length = values == null ? 0 : values.length;
1440
-
1441
- this.__data__ = new MapCache;
1442
- while (++index < length) {
1443
- this.add(values[index]);
1444
- }
1445
- }
1446
-
1447
- // Add methods to `SetCache`.
1448
- SetCache$1.prototype.add = SetCache$1.prototype.push = setCacheAdd;
1449
- SetCache$1.prototype.has = setCacheHas;
1450
-
1451
- var _SetCache = SetCache$1;
1452
-
1453
- /**
1454
- * The base implementation of `_.findIndex` and `_.findLastIndex` without
1455
- * support for iteratee shorthands.
1456
- *
1457
- * @private
1458
- * @param {Array} array The array to inspect.
1459
- * @param {Function} predicate The function invoked per iteration.
1460
- * @param {number} fromIndex The index to search from.
1461
- * @param {boolean} [fromRight] Specify iterating from right to left.
1462
- * @returns {number} Returns the index of the matched value, else `-1`.
1463
- */
1464
-
1465
- function baseFindIndex$1(array, predicate, fromIndex, fromRight) {
1466
- var length = array.length,
1467
- index = fromIndex + (fromRight ? 1 : -1);
1468
-
1469
- while ((fromRight ? index-- : ++index < length)) {
1470
- if (predicate(array[index], index, array)) {
1471
- return index;
1472
- }
1473
- }
1474
- return -1;
1475
- }
1476
-
1477
- var _baseFindIndex = baseFindIndex$1;
1478
-
1479
- /**
1480
- * The base implementation of `_.isNaN` without support for number objects.
1481
- *
1482
- * @private
1483
- * @param {*} value The value to check.
1484
- * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
1485
- */
1486
-
1487
- function baseIsNaN$1(value) {
1488
- return value !== value;
1489
- }
1490
-
1491
- var _baseIsNaN = baseIsNaN$1;
1492
-
1493
- /**
1494
- * A specialized version of `_.indexOf` which performs strict equality
1495
- * comparisons of values, i.e. `===`.
1496
- *
1497
- * @private
1498
- * @param {Array} array The array to inspect.
1499
- * @param {*} value The value to search for.
1500
- * @param {number} fromIndex The index to search from.
1501
- * @returns {number} Returns the index of the matched value, else `-1`.
1502
- */
1503
-
1504
- function strictIndexOf$1(array, value, fromIndex) {
1505
- var index = fromIndex - 1,
1506
- length = array.length;
1507
-
1508
- while (++index < length) {
1509
- if (array[index] === value) {
1510
- return index;
1511
- }
1512
- }
1513
- return -1;
1514
- }
1515
-
1516
- var _strictIndexOf = strictIndexOf$1;
1517
-
1518
- var baseFindIndex = _baseFindIndex,
1519
- baseIsNaN = _baseIsNaN,
1520
- strictIndexOf = _strictIndexOf;
1521
-
1522
- /**
1523
- * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
1524
- *
1525
- * @private
1526
- * @param {Array} array The array to inspect.
1527
- * @param {*} value The value to search for.
1528
- * @param {number} fromIndex The index to search from.
1529
- * @returns {number} Returns the index of the matched value, else `-1`.
1530
- */
1531
- function baseIndexOf$1(array, value, fromIndex) {
1532
- return value === value
1533
- ? strictIndexOf(array, value, fromIndex)
1534
- : baseFindIndex(array, baseIsNaN, fromIndex);
1535
- }
1536
-
1537
- var _baseIndexOf = baseIndexOf$1;
1538
-
1539
- var baseIndexOf = _baseIndexOf;
1540
-
1541
- /**
1542
- * A specialized version of `_.includes` for arrays without support for
1543
- * specifying an index to search from.
1544
- *
1545
- * @private
1546
- * @param {Array} [array] The array to inspect.
1547
- * @param {*} target The value to search for.
1548
- * @returns {boolean} Returns `true` if `target` is found, else `false`.
1549
- */
1550
- function arrayIncludes$1(array, value) {
1551
- var length = array == null ? 0 : array.length;
1552
- return !!length && baseIndexOf(array, value, 0) > -1;
1553
- }
1554
-
1555
- var _arrayIncludes = arrayIncludes$1;
1556
-
1557
- /**
1558
- * This function is like `arrayIncludes` except that it accepts a comparator.
1559
- *
1560
- * @private
1561
- * @param {Array} [array] The array to inspect.
1562
- * @param {*} target The value to search for.
1563
- * @param {Function} comparator The comparator invoked per element.
1564
- * @returns {boolean} Returns `true` if `target` is found, else `false`.
1565
- */
1566
-
1567
- function arrayIncludesWith$1(array, value, comparator) {
1568
- var index = -1,
1569
- length = array == null ? 0 : array.length;
1570
-
1571
- while (++index < length) {
1572
- if (comparator(value, array[index])) {
1573
- return true;
1574
- }
1575
- }
1576
- return false;
1577
- }
1578
-
1579
- var _arrayIncludesWith = arrayIncludesWith$1;
1580
-
1581
- /**
1582
- * Checks if a `cache` value for `key` exists.
1583
- *
1584
- * @private
1585
- * @param {Object} cache The cache to query.
1586
- * @param {string} key The key of the entry to check.
1587
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1588
- */
1589
-
1590
- function cacheHas$1(cache, key) {
1591
- return cache.has(key);
1592
- }
1593
-
1594
- var _cacheHas = cacheHas$1;
1595
-
1596
- var getNative = _getNative,
1597
- root = _root;
1598
-
1599
- /* Built-in method references that are verified to be native. */
1600
- var Set$1 = getNative(root, 'Set');
1601
-
1602
- var _Set = Set$1;
1603
-
1604
- /**
1605
- * This method returns `undefined`.
1606
- *
1607
- * @static
1608
- * @memberOf _
1609
- * @since 2.3.0
1610
- * @category Util
1611
- * @example
1612
- *
1613
- * _.times(2, _.noop);
1614
- * // => [undefined, undefined]
1615
- */
1616
-
1617
- function noop$1() {
1618
- // No operation performed.
1619
- }
1620
-
1621
- var noop_1 = noop$1;
1622
-
1623
- /**
1624
- * Converts `set` to an array of its values.
1625
- *
1626
- * @private
1627
- * @param {Object} set The set to convert.
1628
- * @returns {Array} Returns the values.
1629
- */
1630
-
1631
- function setToArray$2(set) {
1632
- var index = -1,
1633
- result = Array(set.size);
1634
-
1635
- set.forEach(function(value) {
1636
- result[++index] = value;
1637
- });
1638
- return result;
1639
- }
1640
-
1641
- var _setToArray = setToArray$2;
1642
-
1643
- var Set = _Set,
1644
- noop = noop_1,
1645
- setToArray$1 = _setToArray;
1646
-
1647
- /** Used as references for various `Number` constants. */
1648
- var INFINITY = 1 / 0;
1649
-
1650
- /**
1651
- * Creates a set object of `values`.
1652
- *
1653
- * @private
1654
- * @param {Array} values The values to add to the set.
1655
- * @returns {Object} Returns the new set.
1656
- */
1657
- var createSet$1 = !(Set && (1 / setToArray$1(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
1658
- return new Set(values);
1659
- };
1660
-
1661
- var _createSet = createSet$1;
1662
-
1663
- var SetCache = _SetCache,
1664
- arrayIncludes = _arrayIncludes,
1665
- arrayIncludesWith = _arrayIncludesWith,
1666
- cacheHas = _cacheHas,
1667
- createSet = _createSet,
1668
- setToArray = _setToArray;
1669
-
1670
- /** Used as the size to enable large array optimizations. */
1671
- var LARGE_ARRAY_SIZE = 200;
1672
-
1673
- /**
1674
- * The base implementation of `_.uniqBy` without support for iteratee shorthands.
1675
- *
1676
- * @private
1677
- * @param {Array} array The array to inspect.
1678
- * @param {Function} [iteratee] The iteratee invoked per element.
1679
- * @param {Function} [comparator] The comparator invoked per element.
1680
- * @returns {Array} Returns the new duplicate free array.
1681
- */
1682
- function baseUniq$1(array, iteratee, comparator) {
1683
- var index = -1,
1684
- includes = arrayIncludes,
1685
- length = array.length,
1686
- isCommon = true,
1687
- result = [],
1688
- seen = result;
1689
-
1690
- if (comparator) {
1691
- isCommon = false;
1692
- includes = arrayIncludesWith;
1693
- }
1694
- else if (length >= LARGE_ARRAY_SIZE) {
1695
- var set = iteratee ? null : createSet(array);
1696
- if (set) {
1697
- return setToArray(set);
1698
- }
1699
- isCommon = false;
1700
- includes = cacheHas;
1701
- seen = new SetCache;
1702
- }
1703
- else {
1704
- seen = iteratee ? [] : result;
1705
- }
1706
- outer:
1707
- while (++index < length) {
1708
- var value = array[index],
1709
- computed = iteratee ? iteratee(value) : value;
1710
-
1711
- value = (comparator || value !== 0) ? value : 0;
1712
- if (isCommon && computed === computed) {
1713
- var seenIndex = seen.length;
1714
- while (seenIndex--) {
1715
- if (seen[seenIndex] === computed) {
1716
- continue outer;
1717
- }
1718
- }
1719
- if (iteratee) {
1720
- seen.push(computed);
1721
- }
1722
- result.push(value);
1723
- }
1724
- else if (!includes(seen, computed, comparator)) {
1725
- if (seen !== result) {
1726
- seen.push(computed);
1727
- }
1728
- result.push(value);
1729
- }
1730
- }
1731
- return result;
1732
- }
1733
-
1734
- var _baseUniq = baseUniq$1;
1735
-
1736
- var baseUniq = _baseUniq;
1737
-
1738
- /**
1739
- * This method is like `_.uniq` except that it accepts `comparator` which
1740
- * is invoked to compare elements of `array`. The order of result values is
1741
- * determined by the order they occur in the array.The comparator is invoked
1742
- * with two arguments: (arrVal, othVal).
1743
- *
1744
- * @static
1745
- * @memberOf _
1746
- * @since 4.0.0
1747
- * @category Array
1748
- * @param {Array} array The array to inspect.
1749
- * @param {Function} [comparator] The comparator invoked per element.
1750
- * @returns {Array} Returns the new duplicate free array.
1751
- * @example
1752
- *
1753
- * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
1754
- *
1755
- * _.uniqWith(objects, _.isEqual);
1756
- * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
1757
- */
1758
- function uniqWith(array, comparator) {
1759
- comparator = typeof comparator == 'function' ? comparator : undefined;
1760
- return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
1761
- }
1762
-
1763
- var uniqWith_1 = uniqWith;
1764
-
1765
- /**
1766
- * 场景解析器
1767
- * @param rawScene 原始场景
1768
- * @param sceneName 场景名称
1769
- * @param sceneUrl 场景url
1770
- * @param assetsPrefetcher
1771
- * @param assetSetter
1772
- * @param ADD_NEXT_ARG_LIST
1773
- * @param SCRIPT_CONFIG_MAP
1774
- * @return {IScene} 解析后的场景
1775
- */
1776
- const sceneParser = (rawScene, sceneName, sceneUrl, assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP) => {
1777
- const rawSentenceList = rawScene.replaceAll('\r', '').split('\n'); // 原始句子列表
1778
- // 去分号留到后面去做了,现在注释要单独处理
1779
- const rawSentenceListWithoutEmpty = rawSentenceList;
1780
- // .map((sentence) => sentence.split(";")[0])
1781
- // .filter((sentence) => sentence.trim() !== "");
1782
- let assetsList = []; // 场景资源列表
1783
- let subSceneList = []; // 子场景列表
1784
- const sentenceList = rawSentenceListWithoutEmpty.map((sentence, index) => {
1785
- const returnSentence = scriptParser(sentence, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP, index);
1786
- // 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
1787
- assetsList = [...assetsList, ...returnSentence.sentenceAssets];
1788
- subSceneList = [...subSceneList, ...returnSentence.subScene];
1789
- return returnSentence;
1790
- });
1791
- // 开始资源的预加载
1792
- assetsList = uniqWith_1(assetsList); // 去重
1793
- assetsPrefetcher(assetsList);
1794
- return {
1795
- sceneName: sceneName,
1796
- sceneUrl: sceneUrl,
1797
- sentenceList: sentenceList,
1798
- assetsList: assetsList,
1799
- subSceneList: subSceneList, // 子场景列表
1800
- };
1801
- };
1802
-
1803
- function scss2cssinjsParser(scssString) {
1804
- const [classNameStyles, others] = parseCSS(scssString);
1805
- return {
1806
- classNameStyles,
1807
- others,
1808
- };
1809
- }
1810
- /**
1811
- * GPT 4 写的,临时用,以后要重构!!!
1812
- * TODO:用人类智能重构,要是用着一直没问题,也不是不可以 trust AI
1813
- * @param css
1814
- */
1815
- function parseCSS(css) {
1816
- const result = {};
1817
- let specialRules = '';
1818
- let matches;
1819
- // 使用非贪婪匹配,尝试正确处理任意层次的嵌套
1820
- const classRegex = /\.([^{\s]+)\s*{((?:[^{}]*|{[^}]*})*)}/g;
1821
- const specialRegex = /(@[^{]+{\s*(?:[^{}]*{[^}]*}[^{}]*)+\s*})/g;
1822
- while ((matches = classRegex.exec(css)) !== null) {
1823
- const key = matches[1];
1824
- const value = matches[2].trim().replace(/\s*;\s*/g, ';\n');
1825
- result[key] = value;
1826
- }
1827
- while ((matches = specialRegex.exec(css)) !== null) {
1828
- specialRules += matches[1].trim() + '\n';
1829
- }
1830
- return [result, specialRules.trim()];
1831
- }
1832
-
1833
526
  /**
1834
527
  * Preprocessor for scene text.
1835
528
  *
@@ -1859,13 +552,11 @@ function sceneTextPreProcessPassOne(lines) {
1859
552
  let lastLineIsMultiline = false;
1860
553
  let thisLineIsMultiline = false;
1861
554
  for (const line of lines) {
1862
- thisLineIsMultiline = false;
1863
- if (canBeMultiline(line)) {
1864
- thisLineIsMultiline = true;
1865
- }
1866
- if (shouldNotBeMultiline(line, lastLineIsMultiline)) {
1867
- thisLineIsMultiline = false;
1868
- }
555
+ // 续行需要接到上一行,所以场景的第一行永远不会是续行。
556
+ thisLineIsMultiline =
557
+ processedLines.length > 0 &&
558
+ canBeMultiline(line) &&
559
+ !shouldNotBeMultiline(line, lastLineIsMultiline);
1869
560
  if (thisLineIsMultiline) {
1870
561
  processedLines[processedLines.length - 1] += '\\';
1871
562
  }
@@ -1923,7 +614,6 @@ function sceneTextPreProcessPassTwo(lines) {
1923
614
  placeHolderLines.push(placeholderLine(line));
1924
615
  }
1925
616
  for (const line of lines) {
1926
- console.log(line);
1927
617
  if (line.endsWith('\\')) {
1928
618
  const trueLine = line.slice(0, -1);
1929
619
  if (currentMultilineContent === "") {
@@ -1947,8 +637,24 @@ function sceneTextPreProcessPassTwo(lines) {
1947
637
  }
1948
638
  processedLines.push(line);
1949
639
  }
640
+ // 场景末行仍以 \ 结尾时循环里没有机会收尾,在这里把累积的内容补出去。
641
+ if (currentMultilineContent !== "") {
642
+ processedLines.push(currentMultilineContent, ...placeHolderLines);
643
+ }
1950
644
  return processedLines;
1951
645
  }
646
+ /**
647
+ * 占位行的前缀。占位行本身是一条注释,引擎会空跑掉;
648
+ * 它的作用是让预处理后的行数与原始场景一致,从而保持
649
+ * 「解析后语句 index == 文件行号」这一不变量。
650
+ */
651
+ const WEBGAL_LINE_BREAK_MARK = ';_WEBGAL_LINE_BREAK_';
652
+ /**
653
+ * 判断预处理后的某一行是否是占位行,即它是上一条多行语句折叠掉的续行。
654
+ */
655
+ function isLineBreakPlaceholder(processedLine) {
656
+ return processedLine.startsWith(WEBGAL_LINE_BREAK_MARK);
657
+ }
1952
658
  /**
1953
659
  * Placeholder Line. Adding this line preserves the original number of lines
1954
660
  * in the scene text, so that it can be compatible with the graphical editor.
@@ -1957,70 +663,116 @@ function sceneTextPreProcessPassTwo(lines) {
1957
663
  * @returns The placeholder line
1958
664
  */
1959
665
  function placeholderLine(content = "") {
1960
- return ";_WEBGAL_LINE_BREAK_" + content;
666
+ return WEBGAL_LINE_BREAK_MARK + content;
667
+ }
668
+
669
+ /**
670
+ * 场景解析器
671
+ * @param rawScene 原始场景
672
+ * @param sceneName 场景名称
673
+ * @param sceneUrl 场景url
674
+ * @param assetsPrefetcher
675
+ * @param assetSetter
676
+ * @param ADD_NEXT_ARG_LIST
677
+ * @param SCRIPT_CONFIG_MAP
678
+ * @return {IScene} 解析后的场景
679
+ */
680
+ const sceneParser = (rawScene, sceneName, sceneUrl, assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP) => {
681
+ // 预处理把多行语句折叠进它的首行,并用占位行补齐被折叠掉的行,
682
+ // 因此这里的行数与原始场景严格一致,「语句 index == 文件行号」始终成立。
683
+ const rawSentenceList = sceneTextPreProcess(rawScene).split('\n'); // 原始句子列表
684
+ // 去分号留到后面去做了,现在注释要单独处理
685
+ const rawSentenceListWithoutEmpty = rawSentenceList;
686
+ // .map((sentence) => sentence.split(";")[0])
687
+ // .filter((sentence) => sentence.trim() !== "");
688
+ let assetsList = []; // 场景资源列表
689
+ let subSceneList = []; // 子场景列表
690
+ const sentenceList = rawSentenceListWithoutEmpty.map((sentence, index) => {
691
+ const returnSentence = scriptParser(sentence, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP, index);
692
+ // 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
693
+ assetsList = [...assetsList, ...returnSentence.sentenceAssets];
694
+ subSceneList = [...subSceneList, ...returnSentence.subScene];
695
+ return returnSentence;
696
+ });
697
+ markMultilineRanges(sentenceList, rawSentenceList);
698
+ // 开始资源的预加载
699
+ assetsList = deduplicateAssets(assetsList);
700
+ assetsPrefetcher(assetsList);
701
+ return {
702
+ sceneName: sceneName,
703
+ sceneUrl: sceneUrl,
704
+ sentenceList: sentenceList,
705
+ assetsList: assetsList,
706
+ subSceneList: subSceneList, // 子场景列表
707
+ };
708
+ };
709
+ /**
710
+ * 回填多行语句的行范围。
711
+ *
712
+ * 预处理后,一条多行语句的完整内容都落在它的首行,紧跟其后的若干占位行
713
+ * 就是被折叠掉的续行。这里把占位行标记出来,并把首行语句的 endLine
714
+ * 推到最后一条续行,图形编辑器据此按整个行范围替换语句。
715
+ *
716
+ * @param sentenceList 解析后的语句列表
717
+ * @param processedLines 预处理后的行,与 sentenceList 一一对应
718
+ */
719
+ const markMultilineRanges = (sentenceList, processedLines) => {
720
+ let headIndex = -1; // 最近一条非占位语句的下标,即当前多行语句的首行
721
+ for (let index = 0; index < sentenceList.length; index++) {
722
+ if (!isLineBreakPlaceholder(processedLines[index])) {
723
+ headIndex = index;
724
+ continue;
725
+ }
726
+ sentenceList[index].isLineBreakHolder = true;
727
+ if (headIndex >= 0) {
728
+ sentenceList[headIndex].endLine = index;
729
+ }
730
+ }
731
+ };
732
+ const deduplicateAssets = (assetsList) => {
733
+ const seenAssets = new Set();
734
+ return assetsList.filter((asset) => {
735
+ if (!asset || typeof asset.url !== 'string' || asset.url === '') {
736
+ return false;
737
+ }
738
+ const assetKey = `${asset.type}:${asset.url}`;
739
+ if (seenAssets.has(assetKey)) {
740
+ return false;
741
+ }
742
+ seenAssets.add(assetKey);
743
+ return true;
744
+ });
745
+ };
746
+
747
+ function scss2cssinjsParser(scssString) {
748
+ const [classNameStyles, others] = parseCSS(scssString);
749
+ return {
750
+ classNameStyles,
751
+ others,
752
+ };
1961
753
  }
1962
- // export function sceneTextPreProcess(sceneText: string): string {
1963
- // const lines = sceneText.replaceAll('\r', '').split('\n');
1964
- // const processedLines: string[] = [];
1965
- // let lastNonMultilineIndex = -1;
1966
- // let isInMultilineSequence = false;
1967
- // function isMultiline(line: string): boolean {
1968
- // if (!line.startsWith(' ')) return false;
1969
- // const trimmedLine = line.trimStart();
1970
- // return trimmedLine.startsWith('|') || trimmedLine.startsWith('-');
1971
- // }
1972
- // for (let i = 0; i < lines.length; i++) {
1973
- // const line = lines[i];
1974
- // if (line.trim() === '') {
1975
- // // Empty line handling
1976
- // if (isInMultilineSequence) {
1977
- // // Check if the next line is a multiline line
1978
- // let isStillInMulti = false;
1979
- // for (let j = i + 1; j < lines.length; j++) {
1980
- // const lookForwardLine = lines[j] || '';
1981
- // // 遇到正常语句了,直接中断
1982
- // if (lookForwardLine.trim() !== '' && !isMultiline(lookForwardLine)) {
1983
- // isStillInMulti = false;
1984
- // break;
1985
- // }
1986
- // // 必须找到后面接的是参数,并且中间没有遇到任何正常语句才行
1987
- // if (lookForwardLine.trim() !== '' && isMultiline(lookForwardLine)) {
1988
- // isStillInMulti = true;
1989
- // break;
1990
- // }
1991
- // }
1992
- // if (isStillInMulti) {
1993
- // // Still within a multiline sequence
1994
- // processedLines.push(';_WEBGAL_LINE_BREAK_');
1995
- // } else {
1996
- // // End of multiline sequence
1997
- // isInMultilineSequence = false;
1998
- // processedLines.push(line);
1999
- // }
2000
- // } else {
2001
- // // Preserve empty lines outside of multiline sequences
2002
- // processedLines.push(line);
2003
- // }
2004
- // } else if (isMultiline(line)) {
2005
- // // Multiline statement handling
2006
- // if (lastNonMultilineIndex >= 0) {
2007
- // // Concatenate to the previous non-multiline statement
2008
- // const trimedLine = line.trimStart();
2009
- // const addBlank = trimedLine.startsWith('-') ? ' ' : '';
2010
- // processedLines[lastNonMultilineIndex] += addBlank + trimedLine;
2011
- // }
2012
- // // Add the special comment line
2013
- // processedLines.push(';_WEBGAL_LINE_BREAK_' + line);
2014
- // isInMultilineSequence = true;
2015
- // } else {
2016
- // // Non-multiline statement handling
2017
- // processedLines.push(line);
2018
- // lastNonMultilineIndex = processedLines.length - 1;
2019
- // isInMultilineSequence = false;
2020
- // }
2021
- // }
2022
- // return processedLines.join('\n');
2023
- // }
754
+ /**
755
+ * GPT 4 写的,临时用,以后要重构!!!
756
+ * TODO:用人类智能重构,要是用着一直没问题,也不是不可以 trust AI
757
+ * @param css
758
+ */
759
+ function parseCSS(css) {
760
+ const result = {};
761
+ let specialRules = '';
762
+ let matches;
763
+ // 使用非贪婪匹配,尝试正确处理任意层次的嵌套
764
+ const classRegex = /\.([^{\s]+)\s*{((?:[^{}]*|{[^}]*})*)}/g;
765
+ const specialRegex = /(@[^{]+{\s*(?:[^{}]*{[^}]*}[^{}]*)+\s*})/g;
766
+ while ((matches = classRegex.exec(css)) !== null) {
767
+ const key = matches[1];
768
+ const value = matches[2].trim().replace(/\s*;\s*/g, ';\n');
769
+ result[key] = value;
770
+ }
771
+ while ((matches = specialRegex.exec(css)) !== null) {
772
+ specialRules += matches[1].trim() + '\n';
773
+ }
774
+ return [result, specialRules.trim()];
775
+ }
2024
776
 
2025
777
  class SceneParser {
2026
778
  assetsPrefetcher;
@@ -2065,4 +817,4 @@ class SceneParser {
2065
817
  }
2066
818
  }
2067
819
 
2068
- export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG, SceneParser as default, sceneTextPreProcess };
820
+ export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG, WEBGAL_LINE_BREAK_MARK, SceneParser as default, isLineBreakPlaceholder, sceneTextPreProcess };