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