gdcore-tools 2.0.0-gd-v5.4.220-autobuild → 2.0.0-gd-v5.5.221-autobuild

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.
@@ -0,0 +1,39 @@
1
+ declare namespace bondage {
2
+ export class Runner {
3
+ yarnNodes: any;
4
+ variables: any;
5
+ functions: any;
6
+ visited: any;
7
+ load(data: any[]): void;
8
+ setVariableStorage(storage: any): void;
9
+ registerFunction(name: string, func): void;
10
+ run(startNode: string): any;
11
+ evalNodes(nodes: any[], yarnNodeData: any): any;
12
+ handleSelections(selections: any[]): any;
13
+ evaluateAssignment(node: any): any;
14
+ evaluateConditional(node: any): any;
15
+ evaluateExpressionOrLiteral(node): any;
16
+ }
17
+
18
+ export class Result {}
19
+
20
+ export class TextResult extends Result {
21
+ text: string;
22
+ data: any;
23
+ lineNum: number;
24
+ }
25
+
26
+ export class CommandResult extends Result {
27
+ text: string;
28
+ data: any;
29
+ lineNum: number;
30
+ }
31
+
32
+ export class OptionsResult extends Result {
33
+ options: string[];
34
+ lineNum: number[];
35
+ selected: number;
36
+
37
+ select(index: number): void;
38
+ }
39
+ }
@@ -1,3 +1,3 @@
1
- var gdjs;(function(e){const n=new e.Logger("Dialogue tree");e.dialogueTree={},e.dialogueTree.runner=new bondage.Runner,e.dialogueTree.loadFromSceneVariable=function(i,t){this.runner=e.dialogueTree.runner;try{this.yarnData=JSON.parse(i.getAsString()),this.runner.load(this.yarnData),t&&t.length>0&&e.dialogueTree.startFrom(t)}catch(a){n.error("Error while loading from scene variable: ",a)}},e.dialogueTree.loadFromJsonFile=function(i,t,a){i.getGame().getJsonManager().loadJson(t,function(s,r){if(s)n.error("An error happened while loading JSON resource:",s);else{if(!r)return;e.dialogueTree.yarnData=r;try{e.dialogueTree.runner.load(e.dialogueTree.yarnData)}catch(o){n.error("An error happened while loading parsing the dialogue tree data:",o)}a&&a.length>0&&e.dialogueTree.startFrom(a)}})},e.dialogueTree.stopRunningDialogue=function(){this.dialogueIsRunning&&(this.dialogueIsRunning=!1),this.dialogueData&&(this.dialogueData=null),this.dialogueText="",this.clipTextEnd=0},e.dialogueTree.isRunning=function(){return this.dialogueIsRunning&&!this.dialogueData&&this.dialogueText&&this.clipTextEnd>=this.dialogueText.length&&(this.dialogueIsRunning=!1),this.dialogueIsRunning},e.dialogueTree.scrollClippedText=function(){if(!(this.pauseScrolling||!this.dialogueIsRunning)){if(e.dialogueTree._isLineTypeCommand()&&this.dialogueDataType==="text"&&this.dialogueBranchTitle===this.dialogueData.data.title&&this.lineNum===this.dialogueData.lineNum&&e.dialogueTree.hasClippedScrollingCompleted()){e.dialogueTree.goToNextDialogueLine();return}this.dialogueText&&this.dialogueDataType==="text"&&this.clipTextEnd<this.dialogueText.length&&(this.clipTextEnd+=1)}},e.dialogueTree.completeClippedTextScrolling=function(){this.pauseScrolling||!this.dialogueIsRunning||!this.dialogueText||this.dialogueDataType!=="text"||(this.clipTextEnd=this.dialogueText.length)},e.dialogueTree.hasClippedScrollingCompleted=function(){return!this.dialogueIsRunning||this.dialogueDataType===""?!1:this.dialogueData&&this.dialogueText.length>0&&this.clipTextEnd>=this.dialogueText.length?(e.dialogueTree.getVariable("debug")&&n.warn("Scroll completed:",this.clipTextEnd,"/",this.dialogueText.length),!0):!1},e.dialogueTree.getClippedLineText=function(){return this.dialogueIsRunning&&this.dialogueText.length?this.dialogueText.substring(0,this.clipTextEnd+1):""},e.dialogueTree.getLineText=function(){return this.dialogueIsRunning&&this.dialogueText.length?this.dialogueText:""},e.dialogueTree.commandParametersCount=function(){return this.commandParameters&&this.commandParameters.length>1?this.commandParameters.length-1:0},e.dialogueTree.getCommandParameter=function(i){if(i===-1&&this.commandParameters.length>0)return this.commandParameters[0];if(this.commandParameters&&this.commandParameters.length>=i+1){const t=this.commandParameters[i+1];return t||""}return""},e.dialogueTree.isCommandCalled=function(i){if(!this.dialogueIsRunning)return!1;const t=e.dialogueTree.commandCalls,a=e.dialogueTree.clipTextEnd,s=e.dialogueTree.dialogueText;return this.pauseScrolling||!t?!1:this.commandCalls.some(function(r,o){if(a!==0&&a<r.time)return!1;if(r.cmd==="wait"&&(a===0||a!==s.length)&&(e.dialogueTree.pauseScrolling=!0,setTimeout(function(){e.dialogueTree.pauseScrolling=!1,t.splice(o,1),e.dialogueTree.getVariable("debug")&&n.info("CMD:",r)},parseInt(r.params[1],10))),r.cmd===i)return e.dialogueTree.commandParameters=r.params,t.splice(o,1),e.dialogueTree.getVariable("debug")&&n.info("CMD:",r),!0})},e.dialogueTree._normalizedOptionIndex=function(i){return i>=this.options.length&&(i=this.options.length-1),i<0&&(i=0),i},e.dialogueTree._cycledOptionIndex=function(i){return i>=this.options.length&&(i=0),i<0&&(i=this.options.length-1),i},e.dialogueTree.getLineOption=function(i){return!this.dialogueIsRunning||!this.options.length?[]:(i=e.dialogueTree._normalizedOptionIndex(i),this.options[i])},e.dialogueTree.getLineOptionsText=function(i,t){if(!this.dialogueIsRunning||!this.options.length)return"";let a="";return this.options.forEach(function(s,r){r===e.dialogueTree.selectedOption?a+=i:a+=i.replace(/.*/g," "),a+=s,t&&(a+=`
2
- `)}),a},e.dialogueTree.getLineOptionsTextHorizontal=function(i){return this.getLineOptionsText(i,!1)},e.dialogueTree.getLineOptionsTextVertical=function(i){return this.getLineOptionsText(i,!0)},e.dialogueTree.getLineOptionsCount=function(){return this.dialogueIsRunning&&this.options.length?this.optionsCount:0},e.dialogueTree.confirmSelectOption=function(){if(!!this.dialogueIsRunning&&this.dialogueData.select&&!this.selectedOptionUpdated&&this.selectedOption!==-1){this.commandCalls=[];try{this.dialogueData.select(this.selectedOption);try{this.dialogueData=this.dialogue.next().value}catch(i){n.error("Error while confirming in the dialogue tree. Verify if there is a syntax error? Full error is: ",i);return}e.dialogueTree.goToNextDialogueLine()}catch(i){n.error("An error happened when trying to access the dialogue branch!",i)}}},e.dialogueTree.selectNextOption=function(){!this.dialogueIsRunning||this.dialogueData.select&&(this.selectedOption+=1,this.selectedOption=e.dialogueTree._cycledOptionIndex(this.selectedOption),this.selectedOptionUpdated=!0)},e.dialogueTree.selectPreviousOption=function(){!this.dialogueIsRunning||this.dialogueData.select&&(this.selectedOption-=1,this.selectedOption=e.dialogueTree._cycledOptionIndex(this.selectedOption),this.selectedOptionUpdated=!0)},e.dialogueTree.selectOption=function(i){!this.dialogueIsRunning||this.dialogueData.select&&(this.selectedOption=e.dialogueTree._normalizedOptionIndex(i),this.selectedOptionUpdated=!0)},e.dialogueTree.getSelectedOption=function(){if(!!this.dialogueIsRunning)return this.dialogueData.select?this.selectedOption:0},e.dialogueTree.hasSelectedOptionChanged=function(){return this.selectedOptionUpdated?(this.selectedOptionUpdated=!1,this.selectedOption===-1&&(this.selectedOption=0),!0):!1},e.dialogueTree.isDialogueLineType=function(i){if(!this.dialogueIsRunning)return!1;if(this.commandCalls&&i==="command"){if(this.commandCalls.some(function(t){return e.dialogueTree.clipTextEnd>t.time&&t.cmd==="wait"}))return!this.pauseScrolling;if(this.commandCalls.length>0&&this.commandParameters.length>0)return!0}return this.dialogueDataType===i},e.dialogueTree.hasDialogueBranch=function(i){return this.runner&&this.runner.yarnNodes&&Object.keys(this.runner.yarnNodes).some(function(t){return t===i})},e.dialogueTree.startFrom=function(i){if(this.runner=e.dialogueTree.runner,!!this.hasDialogueBranch(i)){this.optionsCount=0,this.options=[],this.tagParameters=[];try{this.dialogue=this.runner.run(i)}catch(t){n.error("Error while setting up the dialogue tree. Verify if there is a syntax error? Full error is: ",t);return}this.dialogueText="",this.clipTextEnd=0,this.commandCalls=[],this.commandParameters=[],this.pauseScrolling=!1;try{this.dialogueData=this.dialogue.next().value}catch(t){n.error("Error while starting the dialogue tree. Verify if there is a syntax error? Full error is: ",t);return}this.dialogueBranchTags=this.dialogueData.data.tags,this.dialogueBranchTitle=this.dialogueData.data.title,this.dialogueBranchBody=this.dialogueData.data.body,this.lineNum=this.dialogueData.lineNum,e.dialogueTree._isLineTypeText()?this.dialogueDataType="text":e.dialogueTree._isLineTypeOptions()?this.dialogueDataType="options":this.dialogueDataType="command",this.dialogueIsRunning=!0,e.dialogueTree.goToNextDialogueLine()}},e.dialogueTree._isLineTypeText=function(){return this.dialogueData instanceof bondage.TextResult},e.dialogueTree._isLineTypeOptions=function(){return this.dialogueData instanceof bondage.OptionsResult},e.dialogueTree._isLineTypeCommand=function(){return this.dialogueData instanceof bondage.CommandResult},e.dialogueTree.goToNextDialogueLine=function(){if(!(this.pauseScrolling||!this.dialogueIsRunning))if(this.optionsCount=0,this.selectedOption=-1,this.selectedOptionUpdated=!1,e.dialogueTree.getVariable("debug")&&n.info("Parsing:",this.dialogueData),!this.dialogueData)e.dialogueTree.stopRunningDialogue();else if(e.dialogueTree._isLineTypeText()){this.lineNum===this.dialogueData.lineNum&&this.dialogueBranchTitle===this.dialogueData.data.title?(this.clipTextEnd=this.dialogueText.length-1,this.dialogueText+=(this.dialogueText===""?"":" ")+this.dialogueData.text):(this.clipTextEnd=0,this.dialogueText=this.dialogueData.text),this.dialogueBranchTags=this.dialogueData.data.tags,this.dialogueBranchTitle=this.dialogueData.data.title,this.dialogueBranchBody=this.dialogueData.data.body,this.lineNum=this.dialogueData.lineNum,this.dialogueDataType="text";try{this.dialogueData=this.dialogue.next().value}catch(i){n.error("Error while progressing the dialogue tree. Verify if there is a syntax error? Full error is: ",i);return}}else if(e.dialogueTree._isLineTypeOptions())this.commandCalls=[],this.dialogueDataType="options",this.dialogueText="",this.clipTextEnd=0,this.optionsCount=this.dialogueData.options.length,this.options=this.dialogueData.options,this.selectedOptionUpdated=!0;else if(e.dialogueTree._isLineTypeCommand()){this.dialogueDataType="command";const i=this.dialogueData.text.split(" "),t=this.commandCalls.length&&this.commandCalls[this.commandCalls.length-1].cmd==="wait"?1:0;this.commandCalls.push({cmd:i[0],params:i,time:this.dialogueText.length+t});try{this.dialogueData=this.dialogue.next().value}catch(a){n.error("Error while progressing the dialogue tree. Verify if there is a syntax error? Full error is: ",a);return}e.dialogueTree.goToNextDialogueLine()}else this.dialogueDataType="unknown"},e.dialogueTree.getBranchTitle=function(){return this.dialogueIsRunning?this.dialogueBranchTitle:""},e.dialogueTree.branchTitleIs=function(i){return this.dialogueIsRunning?this.dialogueBranchTitle===i:!1},e.dialogueTree.getBranchTags=function(){return this.dialogueIsRunning?this.dialogueBranchTags.join(","):""},e.dialogueTree.getBranchTag=function(i){return this.dialogueIsRunning&&this.dialogueBranchTags.length?(i>this.dialogueBranchTags.length-1&&(i=this.dialogueBranchTags.length-1),this.dialogueBranchTags[i]):""},e.dialogueTree.branchContainsTag=function(i){return this.tagParameters=[],this.dialogueIsRunning&&this.dialogueBranchTags.length?this.dialogueBranchTags.some(function(t){const a=t.match(/([^\(]+)\(([^\)]+)\)/i);return e.dialogueTree.tagParameters=a?a[2].split(","):[],a?a[1]===i:t===i}):!1},e.dialogueTree.getTagParameter=function(i){if(this.dialogueIsRunning&&this.tagParameters.length>=i){const t=this.tagParameters[i];return t||""}return""},e.dialogueTree.getVisitedBranchTitles=function(){return this.dialogueIsRunning?Object.keys(this.runner.visited).join(","):""},e.dialogueTree.branchTitleHasBeenVisited=function(i){return i||(i=this.dialogueBranchTitle),Object.keys(this.runner.visited).includes(i)&&this.runner.visited[i]},e.dialogueTree.getBranchText=function(){return this.dialogueIsRunning?this.dialogueBranchBody:""},e.dialogueTree.getVariable=function(i){return this.runner.variables&&i in this.runner.variables.data?this.runner.variables.get(i):""},e.dialogueTree.getVariableAsNumber=function(i){if(this.runner.variables&&i in this.runner.variables.data){const t=this.runner.variables.get(i);return typeof t!="number"?parseFloat(t)||0:isFinite(t)?t:0}return 0},e.dialogueTree.getVariableAsString=function(i){return this.runner.variables&&i in this.runner.variables.data?""+this.runner.variables.get(i):""},e.dialogueTree.compareVariable=function(i,t){return this.runner.variables&&i in this.runner.variables.data?this.runner.variables.get(i)===t:!1},e.dialogueTree.setVariable=function(i,t){this.runner.variables&&this.runner.variables.set(i,t)},e.dialogueTree.saveState=function(i){const t={variables:e.dialogueTree.runner.variables.data,visited:e.dialogueTree.runner.visited};i.fromJSObject(t)},e.dialogueTree.loadState=function(i){const t=i.toJSObject();if(!t){n.error("Load state variable is empty:",i);return}try{e.dialogueTree.runner.visited=t.visited,e.dialogueTree.runner.variables.data={},Object.keys(t.variables).forEach(function(a){const s=t.variables[a];e.dialogueTree.runner.variables.set(a,s)})}catch(a){n.error("Failed to load state from variable:",i,a)}},e.dialogueTree.clearState=function(){e.dialogueTree.runner.visited={},e.dialogueTree.runner.variables.data={}}})(gdjs||(gdjs={}));
1
+ var gdjs;(function(l){let F;(function(Le){const s=new l.Logger("Dialogue tree"),n=new bondage.Runner;let g,u=0,o="",m=!1,p=[],f=0,b=!1,v=[],r=null,i=!1,c=null,x="",C=0,L=0,d=[],y,h=[],S="";function j(e,t){try{const a=JSON.parse(e.getAsString());n.load(a),t&&t.length>0&&l.dialogueTree.startFrom(t)}catch(a){s.error("Error while loading from scene variable: ",a)}}Le.loadFromSceneVariable=j;function E(e,t,a){e.getGame().getJsonManager().loadJson(t,function(T,R){if(T)s.error("An error happened while loading JSON resource:",T);else{if(!R)return;const A=R;try{n.load(A)}catch(N){s.error("An error happened while loading parsing the dialogue tree data:",N)}a&&a.length>0&&l.dialogueTree.startFrom(a)}})}Le.loadFromJsonFile=E;function P(){i=!1,r=null,o="",u=0}Le.stopRunningDialogue=P;function J(){return i&&!r&&o&&u>=o.length&&(i=!1),i}Le.isRunning=J;function _(){if(!(m||!i)){if(r instanceof bondage.CommandResult&&c==="text"&&x===r.data.title&&C===r.lineNum&&l.dialogueTree.hasClippedScrollingCompleted()){l.dialogueTree.goToNextDialogueLine();return}o&&c==="text"&&u<o.length&&(u+=1)}}Le.scrollClippedText=_;function M(){m||!i||!o||c!=="text"||(u=o.length)}Le.completeClippedTextScrolling=M;function z(){return!i||c===""?!1:r&&o.length>0&&u>=o.length?(l.dialogueTree.getVariable("debug")&&s.warn("Scroll completed:",u,"/",o.length),!0):!1}Le.hasClippedScrollingCompleted=z;function H(){return i&&o.length?o.substring(0,u+1):""}Le.getClippedLineText=H;function G(){return i&&o.length?o:""}Le.getLineText=G;function U(){return p.length>1?p.length-1:0}Le.commandParametersCount=U;function k(e){if(e===-1&&p.length>0)return p[0];if(p.length>=e+1){const t=p[e+1];return t||""}return""}Le.getCommandParameter=k;function K(e){return!i||m||!g?!1:g.some(function(t,a){return u!==0&&u<t.time?!1:(t.cmd==="wait"&&(u===0||u!==o.length)&&(m=!0,setTimeout(function(){m=!1,g.splice(a,1),l.dialogueTree.getVariable("debug")&&s.info("CMD:",t)},parseInt(t.params[1],10))),t.cmd===e?(p=t.params,g.splice(a,1),l.dialogueTree.getVariable("debug")&&s.info("CMD:",t),!0):!1)})}Le.isCommandCalled=K;function V(e){return e>=d.length&&(e=d.length-1),e<0&&(e=0),e}function w(e){return e>=d.length&&(e=0),e<0&&(e=d.length-1),e}function Q(e){return!i||!d.length?[]:(e=V(e),d[e])}Le.getLineOption=Q;function W(e,t){if(!i||!d.length)return"";let a="";return d.forEach(function(T,R){R===f?a+=e:a+=e.replace(/.*/g," "),a+=T,t&&(a+=`
2
+ `)}),a}Le.getLineOptionsText=W;function X(e){return l.dialogueTree.getLineOptionsText(e,!1)}Le.getLineOptionsTextHorizontal=X;function Y(e){return l.dialogueTree.getLineOptionsText(e,!0)}Le.getLineOptionsTextVertical=Y;function Z(){return i&&d.length?L:0}Le.getLineOptionsCount=Z;function $(){if(!!i&&r instanceof bondage.OptionsResult&&!b&&f!==-1){g=[];try{r.select(f);try{r=y.next().value}catch(e){s.error("Error while confirming in the dialogue tree. Verify if there is a syntax error? Full error is: ",e);return}l.dialogueTree.goToNextDialogueLine()}catch(e){s.error("An error happened when trying to access the dialogue branch!",e)}}}Le.confirmSelectOption=$;function q(){!i||O()&&(f+=1,f=w(f),b=!0)}Le.selectNextOption=q;function I(){!i||O()&&(f-=1,f=w(f),b=!0)}Le.selectPreviousOption=I;function ee(e){!i||O()&&(f=V(e),b=!0)}Le.selectOption=ee;function te(){return i&&O()?f:0}Le.getSelectedOption=te;function re(){return b?(b=!1,f===-1&&(f=0),!0):!1}Le.hasSelectedOptionChanged=re;function ne(e){if(!i)return!1;if(g&&e==="command"){if(g.some(function(t){return u>t.time&&t.cmd==="wait"}))return!m;if(g.length>0&&p.length>0)return!0}return c===e}Le.isDialogueLineType=ne;function ie(e){return n&&n.yarnNodes&&Object.keys(n.yarnNodes).some(function(t){return t===e})}Le.hasDialogueBranch=ie;function ae(e){if(!!l.dialogueTree.hasDialogueBranch(e)){L=0,d=[],v=[];try{y=n.run(e)}catch(t){s.error("Error while setting up the dialogue tree. Verify if there is a syntax error? Full error is: ",t);return}o="",u=0,g=[],p=[],m=!1;try{r=y.next().value}catch(t){s.error("Error while starting the dialogue tree. Verify if there is a syntax error? Full error is: ",t);return}!r||((r instanceof bondage.TextResult||r instanceof bondage.CommandResult)&&(h=r.data.tags,x=r.data.title,S=r.data.body),C=r.lineNum,B()?c="text":O()?c="options":c="command",i=!0,l.dialogueTree.goToNextDialogueLine())}}Le.startFrom=ae;function B(){return r instanceof bondage.TextResult}function O(){return r instanceof bondage.OptionsResult}function D(){return r instanceof bondage.CommandResult}function oe(){if(!(m||!i))if(L=0,f=-1,b=!1,l.dialogueTree.getVariable("debug")&&s.info("Parsing:",r),!r)l.dialogueTree.stopRunningDialogue();else if(r instanceof bondage.TextResult){C===r.lineNum&&x===r.data.title?(u=o.length-1,o+=(o===""?"":" ")+r.text):(u=0,o=r.text),h=r.data.tags,x=r.data.title,S=r.data.body,C=r.lineNum,c="text";try{r=y.next().value}catch(e){s.error("Error while progressing the dialogue tree. Verify if there is a syntax error? Full error is: ",e);return}}else if(r instanceof bondage.OptionsResult)g=[],c="options",o="",u=0,L=r.options.length,d=r.options,b=!0;else if(D()){c="command";const e=r.text.split(" "),t=g.length&&g[g.length-1].cmd==="wait"?1:0;g.push({cmd:e[0],params:e,time:o.length+t});try{r=y.next().value}catch(a){s.error("Error while progressing the dialogue tree. Verify if there is a syntax error? Full error is: ",a);return}l.dialogueTree.goToNextDialogueLine()}else c="unknown"}Le.goToNextDialogueLine=oe;function le(){return i?x:""}Le.getBranchTitle=le;function ue(e){return i?x===e:!1}Le.branchTitleIs=ue;function se(){return i?h.join(","):""}Le.getBranchTags=se;function ge(e){return i&&h.length?(e>h.length-1&&(e=h.length-1),h[e]):""}Le.getBranchTag=ge;function fe(e){return v=[],i&&h.length?h.some(function(t){const a=t.match(/([^\(]+)\(([^\)]+)\)/i);return v=a?a[2].split(","):[],a?a[1]===e:t===e}):!1}Le.branchContainsTag=fe;function ce(e){if(i&&v.length>=e){const t=v[e];return t||""}return""}Le.getTagParameter=ce;function de(){return i?Object.keys(n.visited).join(","):""}Le.getVisitedBranchTitles=de;function pe(e){return e||(e=x),Object.keys(n.visited).includes(e)&&n.visited[e]}Le.branchTitleHasBeenVisited=pe;function he(){return i?S:""}Le.getBranchText=he;function me(e){return n.variables&&e in n.variables.data?n.variables.get(e):""}Le.getVariable=me;function be(e){if(n.variables&&e in n.variables.data){const t=n.variables.get(e);return typeof t!="number"?parseFloat(t)||0:isFinite(t)?t:0}return 0}Le.getVariableAsNumber=be;function xe(e){return n.variables&&e in n.variables.data?""+n.variables.get(e):""}Le.getVariableAsString=xe;function Te(e,t){return n.variables&&e in n.variables.data?n.variables.get(e)===t:!1}Le.compareVariable=Te;function ve(e,t){n.variables&&n.variables.set(e,t)}Le.setVariable=ve;function ye(e){const t={variables:n.variables.data,visited:n.visited};e.fromJSObject(t)}Le.saveState=ye;function Oe(e){const t=e.toJSObject();if(!t){s.error("Load state variable is empty:",e);return}try{n.visited=t.visited,n.variables.data={},Object.keys(t.variables).forEach(function(a){const T=t.variables[a];n.variables.set(a,T)})}catch(a){s.error("Failed to load state from variable:",e,a)}}Le.loadState=Oe;function Ce(){n.visited={},n.variables.data={}}Le.clearState=Ce})(F=l.dialogueTree||(l.dialogueTree={}))})(gdjs||(gdjs={}));
3
3
  //# sourceMappingURL=dialoguetools.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../GDevelop/Extensions/DialogueTree/dialoguetools.ts"],
4
- "sourcesContent": ["// @ts-nocheck - Weird usage of `this` in this file. Should be refactored.\n\nnamespace gdjs {\n const logger = new gdjs.Logger('Dialogue tree');\n\n gdjs.dialogueTree = {};\n gdjs.dialogueTree.runner = new bondage.Runner();\n\n /**\n * Load the Dialogue Tree data of the game. Initialize The Dialogue Tree, so as it can be used in the game.\n * @param sceneVar The variable to load the Dialogue tree data from. The data is a JSON string, created by Yarn.\n * @param startDialogueNode The Dialogue Branch to start the Dialogue Tree from. If left empty, the data will only be loaded, but can later be initialized via another action\n */\n gdjs.dialogueTree.loadFromSceneVariable = function (\n sceneVar: gdjs.Variable,\n startDialogueNode: string\n ) {\n this.runner = gdjs.dialogueTree.runner;\n try {\n this.yarnData = JSON.parse(sceneVar.getAsString());\n this.runner.load(this.yarnData);\n if (startDialogueNode && startDialogueNode.length > 0) {\n gdjs.dialogueTree.startFrom(startDialogueNode);\n }\n } catch (e) {\n logger.error('Error while loading from scene variable: ', e);\n }\n };\n\n /**\n * Load the Dialogue Tree data from a JSON resource.\n *\n * @param instanceContainer The scene where the dialogue is running.\n * @param jsonResourceName The JSON resource where to load the Dialogue Tree data from. The data is a JSON string usually created with [Yarn Dialogue Editor](https://github.com/InfiniteAmmoInc/Yarn).\n * @param startDialogueNode The Dialogue Branch to start the Dialogue Tree from. If left empty, the data will only be loaded, but can later be initialized via another action\n */\n gdjs.dialogueTree.loadFromJsonFile = function (\n instanceContainer: gdjs.RuntimeInstanceContainer,\n jsonResourceName: string,\n startDialogueNode: string\n ) {\n instanceContainer\n .getGame()\n .getJsonManager()\n .loadJson(jsonResourceName, function (error, content) {\n if (error) {\n logger.error('An error happened while loading JSON resource:', error);\n } else {\n if (!content) {\n return;\n }\n gdjs.dialogueTree.yarnData = content;\n try {\n gdjs.dialogueTree.runner.load(gdjs.dialogueTree.yarnData);\n } catch (error) {\n logger.error(\n 'An error happened while loading parsing the dialogue tree data:',\n error\n );\n }\n if (startDialogueNode && startDialogueNode.length > 0) {\n gdjs.dialogueTree.startFrom(startDialogueNode);\n }\n }\n });\n };\n\n /**\n * Stop the currently running dialogue\n */\n gdjs.dialogueTree.stopRunningDialogue = function () {\n if (this.dialogueIsRunning) {\n this.dialogueIsRunning = false;\n }\n if (this.dialogueData) {\n this.dialogueData = null;\n }\n this.dialogueText = '';\n this.clipTextEnd = 0;\n };\n\n /**\n * Check if the Dialogue Tree is currently parsing data.\n * For example, you can do things like disabling player movement while talking to a NPC.\n */\n gdjs.dialogueTree.isRunning = function () {\n if (\n this.dialogueIsRunning &&\n !this.dialogueData &&\n this.dialogueText &&\n this.clipTextEnd >= this.dialogueText.length\n ) {\n this.dialogueIsRunning = false;\n }\n return this.dialogueIsRunning;\n };\n\n /**\n * Scroll the clipped text. This can be combined with a timer and user input to control how fast the dialogue line text is scrolling.\n */\n gdjs.dialogueTree.scrollClippedText = function () {\n if (this.pauseScrolling || !this.dialogueIsRunning) {\n return;\n }\n\n // Autoscroll commands so the user doesn't have to press again.\n if (\n gdjs.dialogueTree._isLineTypeCommand() &&\n this.dialogueDataType === 'text' &&\n this.dialogueBranchTitle === this.dialogueData.data.title &&\n this.lineNum === this.dialogueData.lineNum &&\n gdjs.dialogueTree.hasClippedScrollingCompleted()\n ) {\n gdjs.dialogueTree.goToNextDialogueLine();\n return;\n }\n\n // Increment scrolling of clipped text\n if (\n this.dialogueText &&\n this.dialogueDataType === 'text' &&\n this.clipTextEnd < this.dialogueText.length\n ) {\n this.clipTextEnd += 1;\n }\n };\n\n /**\n * Scroll the clipped text to its end, so the entire text is printed. This can be useful in keeping the event sheet logic simpler, while supporting more variation.\n */\n gdjs.dialogueTree.completeClippedTextScrolling = function () {\n if (\n this.pauseScrolling ||\n !this.dialogueIsRunning ||\n !this.dialogueText ||\n this.dialogueDataType !== 'text'\n ) {\n return;\n }\n this.clipTextEnd = this.dialogueText.length;\n };\n\n /**\n * Check if text scrolling has completed.\n * Useful to prevent the user from skipping to next line before the current one has been printed fully.\n */\n gdjs.dialogueTree.hasClippedScrollingCompleted = function () {\n if (!this.dialogueIsRunning || this.dialogueDataType === '') {\n return false;\n }\n if (\n this.dialogueData &&\n this.dialogueText.length > 0 &&\n this.clipTextEnd >= this.dialogueText.length\n ) {\n if (gdjs.dialogueTree.getVariable('debug')) {\n logger.warn(\n 'Scroll completed:',\n this.clipTextEnd,\n '/',\n this.dialogueText.length\n );\n }\n return true;\n }\n return false;\n };\n\n /**\n * Get the current dialogue line with a scrolling effect (recommended).\n * Used with the scrollClippedText to achieve a classic scrolling text, as well as any <<wait>> effects to pause scrolling.\n */\n gdjs.dialogueTree.getClippedLineText = function () {\n return this.dialogueIsRunning && this.dialogueText.length\n ? this.dialogueText.substring(0, this.clipTextEnd + 1)\n : '';\n };\n\n /**\n * Get the current complete dialogue line without using any scrolling effects.\n * Note that using this instead getClippedLineText will skip any <<wait>> commands entirely.\n */\n gdjs.dialogueTree.getLineText = function () {\n return this.dialogueIsRunning && this.dialogueText.length\n ? this.dialogueText\n : '';\n };\n\n /**\n * Get the number of command parameters in a command with parameters that has been caught by a isCommandCalled condition\n */\n gdjs.dialogueTree.commandParametersCount = function () {\n if (this.commandParameters && this.commandParameters.length > 1) {\n return this.commandParameters.length - 1;\n }\n return 0;\n };\n\n /**\n * Get a command parameter in any command with parameters that has been caught by a isCommandCalled condition\n * @param paramIndex The index of the parameter to get.\n */\n gdjs.dialogueTree.getCommandParameter = function (paramIndex: float) {\n if (paramIndex === -1 && this.commandParameters.length > 0) {\n return this.commandParameters[0];\n }\n if (\n this.commandParameters &&\n this.commandParameters.length >= paramIndex + 1\n ) {\n const returnedParam = this.commandParameters[paramIndex + 1];\n return returnedParam ? returnedParam : '';\n }\n return '';\n };\n\n /**\n * Catch <<commands>> and <<commands with parameters>> from the current Dialogue Line.\n * You can trigger custom logic that relate to the story you are telling during the dialogue.\n *\n * @param command The command you want to check for being called. Write it without the `<<>>`.\n */\n gdjs.dialogueTree.isCommandCalled = function (command: string) {\n if (!this.dialogueIsRunning) {\n return false;\n }\n const commandCalls = gdjs.dialogueTree.commandCalls;\n const clipTextEnd = gdjs.dialogueTree.clipTextEnd;\n const dialogueText = gdjs.dialogueTree.dialogueText;\n if (this.pauseScrolling || !commandCalls) {\n return false;\n }\n return this.commandCalls.some(function (call, index) {\n if (clipTextEnd !== 0 && clipTextEnd < call.time) {\n return false;\n }\n if (\n call.cmd === 'wait' &&\n (clipTextEnd === 0 || clipTextEnd !== dialogueText.length)\n ) {\n gdjs.dialogueTree.pauseScrolling = true;\n setTimeout(function () {\n gdjs.dialogueTree.pauseScrolling = false;\n commandCalls.splice(index, 1);\n if (gdjs.dialogueTree.getVariable('debug')) {\n logger.info('CMD:', call);\n }\n }, parseInt(call.params[1], 10));\n }\n if (call.cmd === command) {\n gdjs.dialogueTree.commandParameters = call.params;\n commandCalls.splice(index, 1);\n if (gdjs.dialogueTree.getVariable('debug')) {\n logger.info('CMD:', call);\n }\n return true;\n }\n });\n };\n\n /**\n * Internal method to allow for capping option selection.\n */\n gdjs.dialogueTree._normalizedOptionIndex = function (optionIndex) {\n if (optionIndex >= this.options.length) {\n optionIndex = this.options.length - 1;\n }\n if (optionIndex < 0) {\n optionIndex = 0;\n }\n return optionIndex;\n };\n\n /**\n * Internal method to allow for cycling option selection.\n */\n gdjs.dialogueTree._cycledOptionIndex = function (optionIndex) {\n if (optionIndex >= this.options.length) {\n optionIndex = 0;\n }\n if (optionIndex < 0) {\n optionIndex = this.options.length - 1;\n }\n return optionIndex;\n };\n\n /**\n * Get the text of an option the player can select.\n * Used with getLineOptionsCount to render options for the player when a line of the Options type is parsed\n * @param optionIndex The index of the option you want to get\n */\n gdjs.dialogueTree.getLineOption = function (optionIndex: float) {\n if (!this.dialogueIsRunning || !this.options.length) {\n return [];\n }\n optionIndex = gdjs.dialogueTree._normalizedOptionIndex(optionIndex);\n return this.options[optionIndex];\n };\n\n /**\n * Get the text of the options the player can select, along with the selection cursor.\n * @param optionSelectionCursor The string used to draw the currently selected option's cursor\n * @param addNewLine when true each option is rendered on a new line.\n */\n gdjs.dialogueTree.getLineOptionsText = function (\n optionSelectionCursor: string,\n addNewLine: boolean\n ) {\n if (!this.dialogueIsRunning || !this.options.length) {\n return '';\n }\n let textResult = '';\n this.options.forEach(function (optionText, index) {\n if (index === gdjs.dialogueTree.selectedOption) {\n textResult += optionSelectionCursor;\n } else {\n textResult += optionSelectionCursor.replace(/.*/g, ' ');\n }\n textResult += optionText;\n if (addNewLine) {\n textResult += '\\n';\n }\n });\n return textResult;\n };\n gdjs.dialogueTree.getLineOptionsTextHorizontal = function (\n optionSelectionCursor\n ) {\n return this.getLineOptionsText(optionSelectionCursor, false);\n };\n gdjs.dialogueTree.getLineOptionsTextVertical = function (\n optionSelectionCursor\n ) {\n return this.getLineOptionsText(optionSelectionCursor, true);\n };\n\n /**\n * Get the number of options that are presented to the player, during the parsing of an Options type line.\n * @returns The number of options\n */\n gdjs.dialogueTree.getLineOptionsCount = function (): number {\n if (this.dialogueIsRunning && this.options.length) {\n return this.optionsCount;\n }\n return 0;\n };\n\n /**\n * Confirm the currently selected option, during the parsing of an Options type line.\n *\n * This will advance the dialogue tree to the dialogue branch was selected by the player.\n */\n gdjs.dialogueTree.confirmSelectOption = function () {\n if (!this.dialogueIsRunning) {\n return;\n }\n if (\n this.dialogueData.select &&\n !this.selectedOptionUpdated &&\n this.selectedOption !== -1\n ) {\n this.commandCalls = [];\n try {\n this.dialogueData.select(this.selectedOption);\n try {\n this.dialogueData = this.dialogue.next().value;\n } catch (error) {\n logger.error(\n 'Error while confirming in the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n gdjs.dialogueTree.goToNextDialogueLine();\n } catch (error) {\n logger.error(\n `An error happened when trying to access the dialogue branch!`,\n error\n );\n }\n }\n };\n\n /**\n * Select next option during Options type line parsing. Hook this to your game input.\n */\n gdjs.dialogueTree.selectNextOption = function () {\n if (!this.dialogueIsRunning) {\n return;\n }\n if (this.dialogueData.select) {\n this.selectedOption += 1;\n this.selectedOption = gdjs.dialogueTree._cycledOptionIndex(\n this.selectedOption\n );\n this.selectedOptionUpdated = true;\n }\n };\n\n /**\n * Select previous option during Options type line parsing. Hook this to your game input.\n */\n gdjs.dialogueTree.selectPreviousOption = function () {\n if (!this.dialogueIsRunning) {\n return;\n }\n if (this.dialogueData.select) {\n this.selectedOption -= 1;\n this.selectedOption = gdjs.dialogueTree._cycledOptionIndex(\n this.selectedOption\n );\n this.selectedOptionUpdated = true;\n }\n };\n\n /**\n * Select option by index during Options type line parsing.\n * @param optionIndex The index of the option to select\n */\n gdjs.dialogueTree.selectOption = function (optionIndex: float) {\n if (!this.dialogueIsRunning) {\n return;\n }\n if (this.dialogueData.select) {\n this.selectedOption = gdjs.dialogueTree._normalizedOptionIndex(\n optionIndex\n );\n this.selectedOptionUpdated = true;\n }\n };\n\n /**\n * Get the currently selected option\n * @returns The index of the currently selected option\n */\n gdjs.dialogueTree.getSelectedOption = function (): number {\n if (!this.dialogueIsRunning) {\n return;\n }\n if (this.dialogueData.select) {\n return this.selectedOption;\n }\n return 0;\n };\n\n /**\n * Check when the player has changed option selection since the last call to this function.\n *\n * Can be used to re-render your displayed dialogue options when needed.\n *\n * @returns true if the selected option was updated since the last call to this function\n */\n gdjs.dialogueTree.hasSelectedOptionChanged = function (): boolean {\n if (this.selectedOptionUpdated) {\n this.selectedOptionUpdated = false;\n if (this.selectedOption === -1) {\n this.selectedOption = 0;\n }\n return true;\n }\n return false;\n };\n\n /**\n * Check the type of the Dialogue Line that is being displayed to the player at the moment.\n *\n * There are three types:\n * - text - regular dialogue text is being parsed at the moment\n * - options - the player has reached a branching choice moment where they must select one of multiple options\n * - command - a <<command>> was called in the background, that can be used to trigger game events, but will not be displayed in the dialogue box.\n *\n * @param type The type you want to check for ( one of the three above )\n */\n gdjs.dialogueTree.isDialogueLineType = function (type: string) {\n if (!this.dialogueIsRunning) {\n return false;\n }\n if (this.commandCalls && type === 'command') {\n if (\n this.commandCalls.some(function (call) {\n return (\n gdjs.dialogueTree.clipTextEnd > call.time && call.cmd === 'wait'\n );\n })\n ) {\n return !this.pauseScrolling;\n }\n if (this.commandCalls.length > 0 && this.commandParameters.length > 0) {\n return true;\n }\n }\n return this.dialogueDataType === type;\n };\n\n /**\n * Check if a branch exists. It is also used internally whenever you use the start from action.\n * @param branchName The Dialogue Branch name you want to check.\n */\n gdjs.dialogueTree.hasDialogueBranch = function (branchName: string) {\n return (\n this.runner &&\n this.runner.yarnNodes &&\n Object.keys(this.runner.yarnNodes).some(function (node) {\n return node === branchName;\n })\n );\n };\n\n /**\n * Start parsing dialogue from a specified Dialogue tree branch.\n * Can be used if you want to store multiple dialogues inside a single Dialogue tree data set.\n * @param startDialogueNode The Dialogue Branch name you want to start parsing from.\n */\n gdjs.dialogueTree.startFrom = function (startDialogueNode: string) {\n this.runner = gdjs.dialogueTree.runner;\n if (!this.hasDialogueBranch(startDialogueNode)) {\n return;\n }\n this.optionsCount = 0;\n this.options = [];\n this.tagParameters = [];\n try {\n this.dialogue = this.runner.run(startDialogueNode);\n } catch (error) {\n logger.error(\n 'Error while setting up the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n this.dialogueText = '';\n this.clipTextEnd = 0;\n this.commandCalls = [];\n this.commandParameters = [];\n this.pauseScrolling = false;\n try {\n this.dialogueData = this.dialogue.next().value;\n } catch (error) {\n logger.error(\n 'Error while starting the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n this.dialogueBranchTags = this.dialogueData.data.tags;\n this.dialogueBranchTitle = this.dialogueData.data.title;\n this.dialogueBranchBody = this.dialogueData.data.body;\n this.lineNum = this.dialogueData.lineNum;\n if (gdjs.dialogueTree._isLineTypeText()) {\n this.dialogueDataType = 'text';\n } else {\n if (gdjs.dialogueTree._isLineTypeOptions()) {\n this.dialogueDataType = 'options';\n } else {\n this.dialogueDataType = 'command';\n }\n }\n this.dialogueIsRunning = true;\n gdjs.dialogueTree.goToNextDialogueLine();\n };\n\n /**\n * Internal methods to check the type of a Dialogue Line\n */\n gdjs.dialogueTree._isLineTypeText = function () {\n return this.dialogueData instanceof bondage.TextResult;\n };\n gdjs.dialogueTree._isLineTypeOptions = function () {\n return this.dialogueData instanceof bondage.OptionsResult;\n };\n gdjs.dialogueTree._isLineTypeCommand = function () {\n return this.dialogueData instanceof bondage.CommandResult;\n };\n\n /**\n * This is the main lifecycle function.It runs once only when the user is advancing the dialogue to the next line.\n * Progress Dialogue to the next line. Hook it to your game input.\n * Note that this action can be influenced by any <<wait>> commands, but they work only if you have at least one isCommandCalled condition.\n */\n gdjs.dialogueTree.goToNextDialogueLine = function () {\n if (this.pauseScrolling || !this.dialogueIsRunning) {\n return;\n }\n this.optionsCount = 0;\n this.selectedOption = -1;\n this.selectedOptionUpdated = false;\n if (gdjs.dialogueTree.getVariable('debug')) {\n logger.info('Parsing:', this.dialogueData);\n }\n if (!this.dialogueData) {\n gdjs.dialogueTree.stopRunningDialogue();\n } else {\n if (gdjs.dialogueTree._isLineTypeText()) {\n if (\n this.lineNum === this.dialogueData.lineNum &&\n this.dialogueBranchTitle === this.dialogueData.data.title\n ) {\n this.clipTextEnd = this.dialogueText.length - 1;\n this.dialogueText +=\n (this.dialogueText === '' ? '' : ' ') + this.dialogueData.text;\n } else {\n this.clipTextEnd = 0;\n this.dialogueText = this.dialogueData.text;\n }\n this.dialogueBranchTags = this.dialogueData.data.tags;\n this.dialogueBranchTitle = this.dialogueData.data.title;\n this.dialogueBranchBody = this.dialogueData.data.body;\n this.lineNum = this.dialogueData.lineNum;\n this.dialogueDataType = 'text';\n try {\n this.dialogueData = this.dialogue.next().value;\n } catch (error) {\n logger.error(\n 'Error while progressing the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n } else {\n if (gdjs.dialogueTree._isLineTypeOptions()) {\n this.commandCalls = [];\n this.dialogueDataType = 'options';\n this.dialogueText = '';\n this.clipTextEnd = 0;\n this.optionsCount = this.dialogueData.options.length;\n this.options = this.dialogueData.options;\n this.selectedOptionUpdated = true;\n } else {\n if (gdjs.dialogueTree._isLineTypeCommand()) {\n this.dialogueDataType = 'command';\n const command = this.dialogueData.text.split(' ');\n\n // If last command was to wait, increase time by one\n const offsetTime =\n this.commandCalls.length &&\n this.commandCalls[this.commandCalls.length - 1].cmd === 'wait'\n ? 1\n : 0;\n this.commandCalls.push({\n cmd: command[0],\n params: command,\n time: this.dialogueText.length + offsetTime,\n });\n try {\n this.dialogueData = this.dialogue.next().value;\n } catch (error) {\n logger.error(\n 'Error while progressing the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n gdjs.dialogueTree.goToNextDialogueLine();\n } else {\n this.dialogueDataType = 'unknown';\n }\n }\n }\n }\n };\n\n /**\n * Get the current Dialogue Tree branch title.\n * @returns The current branch title.\n */\n gdjs.dialogueTree.getBranchTitle = function (): string {\n if (this.dialogueIsRunning) {\n return this.dialogueBranchTitle;\n }\n return '';\n };\n\n /**\n * Check if the currently parsed Dialogue branch title is a query.\n * @param title The Dialogue Branch name you want to check for.\n */\n gdjs.dialogueTree.branchTitleIs = function (title: string) {\n if (this.dialogueIsRunning) {\n return this.dialogueBranchTitle === title;\n }\n return false;\n };\n\n /**\n * Get all the branch tags from the current Dialogue branch as a string. Useful for debugging.\n * @returns The current branch tags, separated by a comma.\n */\n gdjs.dialogueTree.getBranchTags = function (): string {\n if (this.dialogueIsRunning) {\n return this.dialogueBranchTags.join(',');\n }\n return '';\n };\n\n /**\n * Get one of the current Dialogue branch tags via index.\n * @param index The index of the Dialogue Branch tag you want to get.\n * @returns The branch tag at the specified index, or an empty string if not found.\n */\n gdjs.dialogueTree.getBranchTag = function (index: float): string {\n if (this.dialogueIsRunning && this.dialogueBranchTags.length) {\n if (index > this.dialogueBranchTags.length - 1) {\n index = this.dialogueBranchTags.length - 1;\n }\n return this.dialogueBranchTags[index];\n }\n return '';\n };\n\n /**\n * Check if the current Dialogue branch contains a specific tag.\n * @param query The name of the Dialogue Branch tag you want to check.\n */\n gdjs.dialogueTree.branchContainsTag = function (query: string) {\n this.tagParameters = [];\n if (this.dialogueIsRunning && this.dialogueBranchTags.length) {\n return this.dialogueBranchTags.some(function (tag) {\n const splitTag = tag.match(/([^\\(]+)\\(([^\\)]+)\\)/i);\n gdjs.dialogueTree.tagParameters = splitTag\n ? splitTag[2].split(',')\n : [];\n return splitTag ? splitTag[1] === query : tag === query;\n });\n }\n return false;\n };\n\n /**\n * Get any tag(parameter,anotherParameter) from a tag captured by the branchContainsTag Condition\n * @param paramIndex The index of the tag parameter you want to get.\n * Leaving this empty will result in retrieving the first parameter.\n */\n gdjs.dialogueTree.getTagParameter = function (paramIndex: float) {\n if (this.dialogueIsRunning && this.tagParameters.length >= paramIndex) {\n const returnedParam = this.tagParameters[paramIndex];\n return returnedParam ? returnedParam : '';\n }\n return '';\n };\n\n /**\n * Get a list of all the titles of visited by the player Branches. Useful for debugging.\n */\n gdjs.dialogueTree.getVisitedBranchTitles = function () {\n if (this.dialogueIsRunning) {\n return Object.keys(this.runner.visited).join(',');\n }\n return '';\n };\n\n /**\n * Check if a player has visited a Dialogue Branch in the past.\n * @param title The title of the branch to check for.\n * Leaving this empty will check if the current branch title has been visited in the past.\n */\n gdjs.dialogueTree.branchTitleHasBeenVisited = function (title: string) {\n if (!title) {\n title = this.dialogueBranchTitle;\n }\n return (\n Object.keys(this.runner.visited).includes(title) &&\n this.runner.visited[title]\n );\n };\n\n /**\n * Get the entire unparsed text of the current Dialogue Branch\n */\n gdjs.dialogueTree.getBranchText = function () {\n if (this.dialogueIsRunning) {\n return this.dialogueBranchBody;\n }\n return '';\n };\n\n /**\n * Get the value of a variable stored in the dialogue state.\n * @param key The variable name\n */\n gdjs.dialogueTree.getVariable = function (\n key: string\n ): string | float | boolean {\n if (this.runner.variables && key in this.runner.variables.data) {\n return this.runner.variables.get(key);\n }\n return '';\n };\n\n /**\n * Get the value of a variable stored in the dialogue state.\n * @param key The variable name\n */\n gdjs.dialogueTree.getVariableAsNumber = function (key: string): float {\n if (this.runner.variables && key in this.runner.variables.data) {\n const value = this.runner.variables.get(key);\n if (typeof value !== 'number') {\n return parseFloat(value) || 0;\n }\n\n return isFinite(value) ? value : 0;\n }\n return 0;\n };\n\n /**\n * Get the value of a variable stored in the dialogue state.\n * @param key The variable name\n */\n gdjs.dialogueTree.getVariableAsString = function (key: string): string {\n if (this.runner.variables && key in this.runner.variables.data) {\n return '' + this.runner.variables.get(key);\n }\n return '';\n };\n\n /**\n * Check if a specific variable created by the Dialogue parses exists and is equal to a specific value.\n * @param key The name of the variable you want to check the value of\n * @param value The value you want to check against\n */\n gdjs.dialogueTree.compareVariable = function (\n key: string,\n value: string | boolean | number\n ) {\n if (this.runner.variables && key in this.runner.variables.data) {\n return this.runner.variables.get(key) === value;\n }\n return false;\n };\n\n /**\n * Set a specific variable created by the Dialogue parser to a specific value.\n * @param key The name of the variable you want to set the value of\n * @param value The value you want to set\n */\n gdjs.dialogueTree.setVariable = function (\n key: string,\n value: string | boolean | number\n ) {\n if (this.runner.variables) {\n this.runner.variables.set(key, value);\n }\n };\n\n /**\n * Store the current State of the Dialogue Parser in a specified variable.\n * Can be used to implement persistence in dialogue through your game's Load/Save function.\n * That way you can later load all the dialogue choices the player has made.\n * @param outputVariable The variable where to store the State\n */\n gdjs.dialogueTree.saveState = function (outputVariable: gdjs.Variable) {\n const dialogueState = {\n variables: gdjs.dialogueTree.runner.variables.data,\n visited: gdjs.dialogueTree.runner.visited,\n };\n outputVariable.fromJSObject(dialogueState);\n };\n\n /**\n * Load the current State of the Dialogue Parser from a specified variable.\n * Can be used to implement persistence in dialogue through your game's Load/Save function.\n * That way you can later load all the dialogue choices the player has made.\n * @param inputVariable The structured variable where to load the State from.\n */\n gdjs.dialogueTree.loadState = function (inputVariable: gdjs.Variable) {\n const loadedState = inputVariable.toJSObject();\n if (!loadedState) {\n logger.error('Load state variable is empty:', inputVariable);\n return;\n }\n try {\n gdjs.dialogueTree.runner.visited = loadedState.visited;\n gdjs.dialogueTree.runner.variables.data = {};\n Object.keys(loadedState.variables).forEach(function (key) {\n const value = loadedState.variables[key];\n gdjs.dialogueTree.runner.variables.set(key, value);\n });\n } catch (e) {\n logger.error('Failed to load state from variable:', inputVariable, e);\n }\n };\n\n /**\n * Clear the current State of the Dialogue Parser.\n */\n gdjs.dialogueTree.clearState = function () {\n gdjs.dialogueTree.runner.visited = {};\n gdjs.dialogueTree.runner.variables.data = {};\n };\n}\n"],
5
- "mappings": "AAEA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,iBAE/B,EAAK,aAAe,GACpB,EAAK,aAAa,OAAS,GAAI,SAAQ,OAOvC,EAAK,aAAa,sBAAwB,SACxC,EACA,EACA,CACA,KAAK,OAAS,EAAK,aAAa,OAChC,GAAI,CACF,KAAK,SAAW,KAAK,MAAM,EAAS,eACpC,KAAK,OAAO,KAAK,KAAK,UAClB,GAAqB,EAAkB,OAAS,GAClD,EAAK,aAAa,UAAU,SAEvB,EAAP,CACA,EAAO,MAAM,4CAA6C,KAW9D,EAAK,aAAa,iBAAmB,SACnC,EACA,EACA,EACA,CACA,EACG,UACA,iBACA,SAAS,EAAkB,SAAU,EAAO,EAAS,CACpD,GAAI,EACF,EAAO,MAAM,iDAAkD,OAC1D,CACL,GAAI,CAAC,EACH,OAEF,EAAK,aAAa,SAAW,EAC7B,GAAI,CACF,EAAK,aAAa,OAAO,KAAK,EAAK,aAAa,gBACzC,EAAP,CACA,EAAO,MACL,kEACA,GAGJ,AAAI,GAAqB,EAAkB,OAAS,GAClD,EAAK,aAAa,UAAU,OAStC,EAAK,aAAa,oBAAsB,UAAY,CAClD,AAAI,KAAK,mBACP,MAAK,kBAAoB,IAEvB,KAAK,cACP,MAAK,aAAe,MAEtB,KAAK,aAAe,GACpB,KAAK,YAAc,GAOrB,EAAK,aAAa,UAAY,UAAY,CACxC,MACE,MAAK,mBACL,CAAC,KAAK,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AAK,aAAa,OAAO,SAEpC,EAAe,aAAa,IAS9B,EAAK,aAAa,UAAY,SAAU,EAA8B,CACpE,KAAM,GAAc,EAAc,aAClC,GAAI,CAAC,EAAa,CAChB,EAAO,MAAM,gCAAiC,GAC9C,OAEF,GAAI,CACF,EAAK,aAAa,OAAO,QAAU,EAAY,QAC/C,EAAK,aAAa,OAAO,UAAU,KAAO,GAC1C,OAAO,KAAK,EAAY,WAAW,QAAQ,SAAU,EAAK,CACxD,KAAM,GAAQ,EAAY,UAAU,GACpC,EAAK,aAAa,OAAO,UAAU,IAAI,EAAK,WAEvC,EAAP,CACA,EAAO,MAAM,sCAAuC,EAAe,KAOvE,EAAK,aAAa,WAAa,UAAY,CACzC,EAAK,aAAa,OAAO,QAAU,GACnC,EAAK,aAAa,OAAO,UAAU,KAAO,MAr3BpC",
4
+ "sourcesContent": ["namespace gdjs {\n export namespace dialogueTree {\n const logger = new gdjs.Logger('Dialogue tree');\n\n const runner = new bondage.Runner();\n let commandCalls: Array<any>;\n let clipTextEnd: integer = 0;\n let dialogueText = '';\n let pauseScrolling = false;\n let commandParameters: Array<string> = [];\n let selectedOption: integer = 0;\n let selectedOptionUpdated = false;\n let tagParameters: Array<string> = [];\n let dialogueData:\n | bondage.TextResult\n | bondage.CommandResult\n | bondage.OptionsResult\n | null = null;\n let dialogueIsRunning = false;\n let dialogueDataType: string | null = null;\n let dialogueBranchTitle = '';\n let lineNum: number | number[] = 0;\n let optionsCount = 0;\n let options: Array<string> = [];\n let dialogue: any;\n let dialogueBranchTags: Array<string> = [];\n let dialogueBranchBody = '';\n\n /**\n * Load the Dialogue Tree data of the game. Initialize The Dialogue Tree, so as it can be used in the game.\n * @param sceneVar The variable to load the Dialogue tree data from. The data is a JSON string, created by Yarn.\n * @param startDialogueNode The Dialogue Branch to start the Dialogue Tree from. If left empty, the data will only be loaded, but can later be initialized via another action\n */\n export function loadFromSceneVariable(\n sceneVar: gdjs.Variable,\n startDialogueNode: string\n ) {\n try {\n const yarnData = JSON.parse(sceneVar.getAsString());\n runner.load(yarnData);\n if (startDialogueNode && startDialogueNode.length > 0) {\n gdjs.dialogueTree.startFrom(startDialogueNode);\n }\n } catch (e) {\n logger.error('Error while loading from scene variable: ', e);\n }\n }\n\n /**\n * Load the Dialogue Tree data from a JSON resource.\n *\n * @param instanceContainer The scene where the dialogue is running.\n * @param jsonResourceName The JSON resource where to load the Dialogue Tree data from. The data is a JSON string usually created with [Yarn Dialogue Editor](https://github.com/InfiniteAmmoInc/Yarn).\n * @param startDialogueNode The Dialogue Branch to start the Dialogue Tree from. If left empty, the data will only be loaded, but can later be initialized via another action\n */\n export function loadFromJsonFile(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n jsonResourceName: string,\n startDialogueNode: string\n ) {\n instanceContainer\n .getGame()\n .getJsonManager()\n .loadJson(jsonResourceName, function (error, content) {\n if (error) {\n logger.error(\n 'An error happened while loading JSON resource:',\n error\n );\n } else {\n if (!content) {\n return;\n }\n const yarnData = content as any[];\n try {\n runner.load(yarnData);\n } catch (error) {\n logger.error(\n 'An error happened while loading parsing the dialogue tree data:',\n error\n );\n }\n if (startDialogueNode && startDialogueNode.length > 0) {\n gdjs.dialogueTree.startFrom(startDialogueNode);\n }\n }\n });\n }\n\n /**\n * Stop the currently running dialogue\n */\n export function stopRunningDialogue() {\n dialogueIsRunning = false;\n dialogueData = null;\n dialogueText = '';\n clipTextEnd = 0;\n }\n\n /**\n * Check if the Dialogue Tree is currently parsing data.\n * For example, you can do things like disabling player movement while talking to a NPC.\n */\n export function isRunning() {\n if (\n dialogueIsRunning &&\n !dialogueData &&\n dialogueText &&\n clipTextEnd >= dialogueText.length\n ) {\n dialogueIsRunning = false;\n }\n return dialogueIsRunning;\n }\n\n /**\n * Scroll the clipped text. This can be combined with a timer and user input to control how fast the dialogue line text is scrolling.\n */\n export function scrollClippedText() {\n if (pauseScrolling || !dialogueIsRunning) {\n return;\n }\n\n // Autoscroll commands so the user doesn't have to press again.\n if (\n dialogueData instanceof bondage.CommandResult &&\n dialogueDataType === 'text' &&\n dialogueBranchTitle === dialogueData.data.title &&\n lineNum === dialogueData.lineNum &&\n gdjs.dialogueTree.hasClippedScrollingCompleted()\n ) {\n gdjs.dialogueTree.goToNextDialogueLine();\n return;\n }\n\n // Increment scrolling of clipped text\n if (\n dialogueText &&\n dialogueDataType === 'text' &&\n clipTextEnd < dialogueText.length\n ) {\n clipTextEnd += 1;\n }\n }\n\n /**\n * Scroll the clipped text to its end, so the entire text is printed. This can be useful in keeping the event sheet logic simpler, while supporting more variation.\n */\n export function completeClippedTextScrolling() {\n if (\n pauseScrolling ||\n !dialogueIsRunning ||\n !dialogueText ||\n dialogueDataType !== 'text'\n ) {\n return;\n }\n clipTextEnd = dialogueText.length;\n }\n\n /**\n * Check if text scrolling has completed.\n * Useful to prevent the user from skipping to next line before the current one has been printed fully.\n */\n export function hasClippedScrollingCompleted() {\n if (!dialogueIsRunning || dialogueDataType === '') {\n return false;\n }\n if (\n dialogueData &&\n dialogueText.length > 0 &&\n clipTextEnd >= dialogueText.length\n ) {\n if (gdjs.dialogueTree.getVariable('debug')) {\n logger.warn(\n 'Scroll completed:',\n clipTextEnd,\n '/',\n dialogueText.length\n );\n }\n return true;\n }\n return false;\n }\n\n /**\n * Get the current dialogue line with a scrolling effect (recommended).\n * Used with the scrollClippedText to achieve a classic scrolling text, as well as any <<wait>> effects to pause scrolling.\n */\n export function getClippedLineText() {\n return dialogueIsRunning && dialogueText.length\n ? dialogueText.substring(0, clipTextEnd + 1)\n : '';\n }\n\n /**\n * Get the current complete dialogue line without using any scrolling effects.\n * Note that using this instead getClippedLineText will skip any <<wait>> commands entirely.\n */\n export function getLineText() {\n return dialogueIsRunning && dialogueText.length ? dialogueText : '';\n }\n\n /**\n * Get the number of command parameters in a command with parameters that has been caught by a isCommandCalled condition\n */\n export function commandParametersCount() {\n if (commandParameters.length > 1) {\n return commandParameters.length - 1;\n }\n return 0;\n }\n\n /**\n * Get a command parameter in any command with parameters that has been caught by a isCommandCalled condition\n * @param paramIndex The index of the parameter to get.\n */\n export function getCommandParameter(paramIndex: float) {\n if (paramIndex === -1 && commandParameters.length > 0) {\n return commandParameters[0];\n }\n if (commandParameters.length >= paramIndex + 1) {\n const returnedParam = commandParameters[paramIndex + 1];\n return returnedParam ? returnedParam : '';\n }\n return '';\n }\n\n /**\n * Catch <<commands>> and <<commands with parameters>> from the current Dialogue Line.\n * You can trigger custom logic that relate to the story you are telling during the dialogue.\n *\n * @param command The command you want to check for being called. Write it without the `<<>>`.\n */\n export function isCommandCalled(command: string) {\n if (!dialogueIsRunning) {\n return false;\n }\n if (pauseScrolling || !commandCalls) {\n return false;\n }\n return commandCalls.some(function (call, index) {\n if (clipTextEnd !== 0 && clipTextEnd < call.time) {\n return false;\n }\n if (\n call.cmd === 'wait' &&\n (clipTextEnd === 0 || clipTextEnd !== dialogueText.length)\n ) {\n pauseScrolling = true;\n setTimeout(function () {\n pauseScrolling = false;\n commandCalls.splice(index, 1);\n if (gdjs.dialogueTree.getVariable('debug')) {\n logger.info('CMD:', call);\n }\n }, parseInt(call.params[1], 10));\n }\n if (call.cmd === command) {\n commandParameters = call.params;\n commandCalls.splice(index, 1);\n if (gdjs.dialogueTree.getVariable('debug')) {\n logger.info('CMD:', call);\n }\n return true;\n }\n return false;\n });\n }\n\n /**\n * Internal method to allow for capping option selection.\n */\n function _normalizedOptionIndex(optionIndex: integer) {\n if (optionIndex >= options.length) {\n optionIndex = options.length - 1;\n }\n if (optionIndex < 0) {\n optionIndex = 0;\n }\n return optionIndex;\n }\n\n /**\n * Internal method to allow for cycling option selection.\n */\n function _cycledOptionIndex(optionIndex: integer) {\n if (optionIndex >= options.length) {\n optionIndex = 0;\n }\n if (optionIndex < 0) {\n optionIndex = options.length - 1;\n }\n return optionIndex;\n }\n\n /**\n * Get the text of an option the player can select.\n * Used with getLineOptionsCount to render options for the player when a line of the Options type is parsed\n * @param optionIndex The index of the option you want to get\n */\n export function getLineOption(optionIndex: float) {\n if (!dialogueIsRunning || !options.length) {\n return [];\n }\n optionIndex = _normalizedOptionIndex(optionIndex);\n return options[optionIndex];\n }\n\n /**\n * Get the text of the options the player can select, along with the selection cursor.\n * @param optionSelectionCursor The string used to draw the currently selected option's cursor\n * @param addNewLine when true each option is rendered on a new line.\n */\n export function getLineOptionsText(\n optionSelectionCursor: string,\n addNewLine: boolean\n ) {\n if (!dialogueIsRunning || !options.length) {\n return '';\n }\n let textResult = '';\n options.forEach(function (optionText, index) {\n if (index === selectedOption) {\n textResult += optionSelectionCursor;\n } else {\n textResult += optionSelectionCursor.replace(/.*/g, ' ');\n }\n textResult += optionText;\n if (addNewLine) {\n textResult += '\\n';\n }\n });\n return textResult;\n }\n export function getLineOptionsTextHorizontal(optionSelectionCursor) {\n return gdjs.dialogueTree.getLineOptionsText(optionSelectionCursor, false);\n }\n export function getLineOptionsTextVertical(optionSelectionCursor) {\n return gdjs.dialogueTree.getLineOptionsText(optionSelectionCursor, true);\n }\n\n /**\n * Get the number of options that are presented to the player, during the parsing of an Options type line.\n * @returns The number of options\n */\n export function getLineOptionsCount(): number {\n if (dialogueIsRunning && options.length) {\n return optionsCount;\n }\n return 0;\n }\n\n /**\n * Confirm the currently selected option, during the parsing of an Options type line.\n *\n * This will advance the dialogue tree to the dialogue branch was selected by the player.\n */\n export function confirmSelectOption() {\n if (!dialogueIsRunning) {\n return;\n }\n if (\n dialogueData instanceof bondage.OptionsResult &&\n !selectedOptionUpdated &&\n selectedOption !== -1\n ) {\n commandCalls = [];\n try {\n dialogueData.select(selectedOption);\n try {\n dialogueData = dialogue.next().value;\n } catch (error) {\n logger.error(\n 'Error while confirming in the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n gdjs.dialogueTree.goToNextDialogueLine();\n } catch (error) {\n logger.error(\n `An error happened when trying to access the dialogue branch!`,\n error\n );\n }\n }\n }\n\n /**\n * Select next option during Options type line parsing. Hook this to your game input.\n */\n export function selectNextOption() {\n if (!dialogueIsRunning) {\n return;\n }\n if (_isLineTypeOptions()) {\n selectedOption += 1;\n selectedOption = _cycledOptionIndex(selectedOption);\n selectedOptionUpdated = true;\n }\n }\n\n /**\n * Select previous option during Options type line parsing. Hook this to your game input.\n */\n export function selectPreviousOption() {\n if (!dialogueIsRunning) {\n return;\n }\n if (_isLineTypeOptions()) {\n selectedOption -= 1;\n selectedOption = _cycledOptionIndex(selectedOption);\n selectedOptionUpdated = true;\n }\n }\n\n /**\n * Select option by index during Options type line parsing.\n * @param optionIndex The index of the option to select\n */\n export function selectOption(optionIndex: float) {\n if (!dialogueIsRunning) {\n return;\n }\n if (_isLineTypeOptions()) {\n selectedOption = _normalizedOptionIndex(optionIndex);\n selectedOptionUpdated = true;\n }\n }\n\n /**\n * Get the currently selected option\n * @returns The index of the currently selected option\n */\n export function getSelectedOption(): number {\n if (!dialogueIsRunning) {\n return 0;\n }\n if (_isLineTypeOptions()) {\n return selectedOption;\n }\n return 0;\n }\n\n /**\n * Check when the player has changed option selection since the last call to this function.\n *\n * Can be used to re-render your displayed dialogue options when needed.\n *\n * @returns true if the selected option was updated since the last call to this function\n */\n export function hasSelectedOptionChanged(): boolean {\n if (selectedOptionUpdated) {\n selectedOptionUpdated = false;\n if (selectedOption === -1) {\n selectedOption = 0;\n }\n return true;\n }\n return false;\n }\n\n /**\n * Check the type of the Dialogue Line that is being displayed to the player at the moment.\n *\n * There are three types:\n * - text - regular dialogue text is being parsed at the moment\n * - options - the player has reached a branching choice moment where they must select one of multiple options\n * - command - a <<command>> was called in the background, that can be used to trigger game events, but will not be displayed in the dialogue box.\n *\n * @param type The type you want to check for ( one of the three above )\n */\n export function isDialogueLineType(type: string) {\n if (!dialogueIsRunning) {\n return false;\n }\n if (commandCalls && type === 'command') {\n if (\n commandCalls.some(function (call) {\n return clipTextEnd > call.time && call.cmd === 'wait';\n })\n ) {\n return !pauseScrolling;\n }\n if (commandCalls.length > 0 && commandParameters.length > 0) {\n return true;\n }\n }\n return dialogueDataType === type;\n }\n\n /**\n * Check if a branch exists. It is also used internally whenever you use the start from action.\n * @param branchName The Dialogue Branch name you want to check.\n */\n export function hasDialogueBranch(branchName: string) {\n return (\n runner &&\n runner.yarnNodes &&\n Object.keys(runner.yarnNodes).some(function (node) {\n return node === branchName;\n })\n );\n }\n\n /**\n * Start parsing dialogue from a specified Dialogue tree branch.\n * Can be used if you want to store multiple dialogues inside a single Dialogue tree data set.\n * @param startDialogueNode The Dialogue Branch name you want to start parsing from.\n */\n export function startFrom(startDialogueNode: string) {\n if (!gdjs.dialogueTree.hasDialogueBranch(startDialogueNode)) {\n return;\n }\n optionsCount = 0;\n options = [];\n tagParameters = [];\n try {\n dialogue = runner.run(startDialogueNode);\n } catch (error) {\n logger.error(\n 'Error while setting up the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n dialogueText = '';\n clipTextEnd = 0;\n commandCalls = [];\n commandParameters = [];\n pauseScrolling = false;\n try {\n dialogueData = dialogue.next().value;\n } catch (error) {\n logger.error(\n 'Error while starting the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n if (!dialogueData) {\n return;\n }\n if (\n dialogueData instanceof bondage.TextResult ||\n dialogueData instanceof bondage.CommandResult\n ) {\n dialogueBranchTags = dialogueData.data.tags;\n dialogueBranchTitle = dialogueData.data.title;\n dialogueBranchBody = dialogueData.data.body;\n }\n lineNum = dialogueData.lineNum;\n if (_isLineTypeText()) {\n dialogueDataType = 'text';\n } else {\n if (_isLineTypeOptions()) {\n dialogueDataType = 'options';\n } else {\n dialogueDataType = 'command';\n }\n }\n dialogueIsRunning = true;\n gdjs.dialogueTree.goToNextDialogueLine();\n }\n\n /**\n * Internal methods to check the type of a Dialogue Line\n */\n function _isLineTypeText() {\n return dialogueData instanceof bondage.TextResult;\n }\n function _isLineTypeOptions() {\n return dialogueData instanceof bondage.OptionsResult;\n }\n function _isLineTypeCommand() {\n return dialogueData instanceof bondage.CommandResult;\n }\n\n /**\n * This is the main lifecycle function.It runs once only when the user is advancing the dialogue to the next line.\n * Progress Dialogue to the next line. Hook it to your game input.\n * Note that this action can be influenced by any <<wait>> commands, but they work only if you have at least one isCommandCalled condition.\n */\n export function goToNextDialogueLine() {\n if (pauseScrolling || !dialogueIsRunning) {\n return;\n }\n optionsCount = 0;\n selectedOption = -1;\n selectedOptionUpdated = false;\n if (gdjs.dialogueTree.getVariable('debug')) {\n logger.info('Parsing:', dialogueData);\n }\n if (!dialogueData) {\n gdjs.dialogueTree.stopRunningDialogue();\n } else {\n if (dialogueData instanceof bondage.TextResult) {\n if (\n lineNum === dialogueData.lineNum &&\n dialogueBranchTitle === dialogueData.data.title\n ) {\n clipTextEnd = dialogueText.length - 1;\n dialogueText +=\n (dialogueText === '' ? '' : ' ') + dialogueData.text;\n } else {\n clipTextEnd = 0;\n dialogueText = dialogueData.text;\n }\n dialogueBranchTags = dialogueData.data.tags;\n dialogueBranchTitle = dialogueData.data.title;\n dialogueBranchBody = dialogueData.data.body;\n lineNum = dialogueData.lineNum;\n dialogueDataType = 'text';\n try {\n dialogueData = dialogue.next().value;\n } catch (error) {\n logger.error(\n 'Error while progressing the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n } else {\n if (dialogueData instanceof bondage.OptionsResult) {\n commandCalls = [];\n dialogueDataType = 'options';\n dialogueText = '';\n clipTextEnd = 0;\n optionsCount = dialogueData.options.length;\n options = dialogueData.options;\n selectedOptionUpdated = true;\n } else {\n if (_isLineTypeCommand()) {\n dialogueDataType = 'command';\n const command = dialogueData.text.split(' ');\n\n // If last command was to wait, increase time by one\n const offsetTime =\n commandCalls.length &&\n commandCalls[commandCalls.length - 1].cmd === 'wait'\n ? 1\n : 0;\n commandCalls.push({\n cmd: command[0],\n params: command,\n time: dialogueText.length + offsetTime,\n });\n try {\n dialogueData = dialogue.next().value;\n } catch (error) {\n logger.error(\n 'Error while progressing the dialogue tree. Verify if there is a syntax error? Full error is: ',\n error\n );\n return;\n }\n gdjs.dialogueTree.goToNextDialogueLine();\n } else {\n dialogueDataType = 'unknown';\n }\n }\n }\n }\n }\n\n /**\n * Get the current Dialogue Tree branch title.\n * @returns The current branch title.\n */\n export function getBranchTitle(): string {\n if (dialogueIsRunning) {\n return dialogueBranchTitle;\n }\n return '';\n }\n\n /**\n * Check if the currently parsed Dialogue branch title is a query.\n * @param title The Dialogue Branch name you want to check for.\n */\n export function branchTitleIs(title: string) {\n if (dialogueIsRunning) {\n return dialogueBranchTitle === title;\n }\n return false;\n }\n\n /**\n * Get all the branch tags from the current Dialogue branch as a string. Useful for debugging.\n * @returns The current branch tags, separated by a comma.\n */\n export function getBranchTags(): string {\n if (dialogueIsRunning) {\n return dialogueBranchTags.join(',');\n }\n return '';\n }\n\n /**\n * Get one of the current Dialogue branch tags via index.\n * @param index The index of the Dialogue Branch tag you want to get.\n * @returns The branch tag at the specified index, or an empty string if not found.\n */\n export function getBranchTag(index: float): string {\n if (dialogueIsRunning && dialogueBranchTags.length) {\n if (index > dialogueBranchTags.length - 1) {\n index = dialogueBranchTags.length - 1;\n }\n return dialogueBranchTags[index];\n }\n return '';\n }\n\n /**\n * Check if the current Dialogue branch contains a specific tag.\n * @param query The name of the Dialogue Branch tag you want to check.\n */\n export function branchContainsTag(query: string) {\n tagParameters = [];\n if (dialogueIsRunning && dialogueBranchTags.length) {\n return dialogueBranchTags.some(function (tag) {\n const splitTag = tag.match(/([^\\(]+)\\(([^\\)]+)\\)/i);\n tagParameters = splitTag ? splitTag[2].split(',') : [];\n return splitTag ? splitTag[1] === query : tag === query;\n });\n }\n return false;\n }\n\n /**\n * Get any tag(parameter,anotherParameter) from a tag captured by the branchContainsTag Condition\n * @param paramIndex The index of the tag parameter you want to get.\n * Leaving this empty will result in retrieving the first parameter.\n */\n export function getTagParameter(paramIndex: float) {\n if (dialogueIsRunning && tagParameters.length >= paramIndex) {\n const returnedParam = tagParameters[paramIndex];\n return returnedParam ? returnedParam : '';\n }\n return '';\n }\n\n /**\n * Get a list of all the titles of visited by the player Branches. Useful for debugging.\n */\n export function getVisitedBranchTitles() {\n if (dialogueIsRunning) {\n return Object.keys(runner.visited).join(',');\n }\n return '';\n }\n\n /**\n * Check if a player has visited a Dialogue Branch in the past.\n * @param title The title of the branch to check for.\n * Leaving this empty will check if the current branch title has been visited in the past.\n */\n export function branchTitleHasBeenVisited(title: string) {\n if (!title) {\n title = dialogueBranchTitle;\n }\n return (\n Object.keys(runner.visited).includes(title) && runner.visited[title]\n );\n }\n\n /**\n * Get the entire unparsed text of the current Dialogue Branch\n */\n export function getBranchText() {\n if (dialogueIsRunning) {\n return dialogueBranchBody;\n }\n return '';\n }\n\n /**\n * Get the value of a variable stored in the dialogue state.\n * @param key The variable name\n */\n export function getVariable(key: string): string | float | boolean {\n if (runner.variables && key in runner.variables.data) {\n return runner.variables.get(key);\n }\n return '';\n }\n\n /**\n * Get the value of a variable stored in the dialogue state.\n * @param key The variable name\n */\n export function getVariableAsNumber(key: string): float {\n if (runner.variables && key in runner.variables.data) {\n const value = runner.variables.get(key);\n if (typeof value !== 'number') {\n return parseFloat(value) || 0;\n }\n\n return isFinite(value) ? value : 0;\n }\n return 0;\n }\n\n /**\n * Get the value of a variable stored in the dialogue state.\n * @param key The variable name\n */\n export function getVariableAsString(key: string): string {\n if (runner.variables && key in runner.variables.data) {\n return '' + runner.variables.get(key);\n }\n return '';\n }\n\n /**\n * Check if a specific variable created by the Dialogue parses exists and is equal to a specific value.\n * @param key The name of the variable you want to check the value of\n * @param value The value you want to check against\n */\n export function compareVariable(\n key: string,\n value: string | boolean | number\n ) {\n if (runner.variables && key in runner.variables.data) {\n return runner.variables.get(key) === value;\n }\n return false;\n }\n\n /**\n * Set a specific variable created by the Dialogue parser to a specific value.\n * @param key The name of the variable you want to set the value of\n * @param value The value you want to set\n */\n export function setVariable(key: string, value: string | boolean | number) {\n if (runner.variables) {\n runner.variables.set(key, value);\n }\n }\n\n /**\n * Store the current State of the Dialogue Parser in a specified variable.\n * Can be used to implement persistence in dialogue through your game's Load/Save function.\n * That way you can later load all the dialogue choices the player has made.\n * @param outputVariable The variable where to store the State\n */\n export function saveState(outputVariable: gdjs.Variable) {\n const dialogueState = {\n variables: runner.variables.data,\n visited: runner.visited,\n };\n outputVariable.fromJSObject(dialogueState);\n }\n\n /**\n * Load the current State of the Dialogue Parser from a specified variable.\n * Can be used to implement persistence in dialogue through your game's Load/Save function.\n * That way you can later load all the dialogue choices the player has made.\n * @param inputVariable The structured variable where to load the State from.\n */\n export function loadState(inputVariable: gdjs.Variable) {\n const loadedState = inputVariable.toJSObject();\n if (!loadedState) {\n logger.error('Load state variable is empty:', inputVariable);\n return;\n }\n try {\n runner.visited = loadedState.visited;\n runner.variables.data = {};\n Object.keys(loadedState.variables).forEach(function (key) {\n const value = loadedState.variables[key];\n runner.variables.set(key, value);\n });\n } catch (e) {\n logger.error('Failed to load state from variable:', inputVariable, e);\n }\n }\n\n /**\n * Clear the current State of the Dialogue Parser.\n */\n export function clearState() {\n runner.visited = {};\n runner.variables.data = {};\n }\n }\n}\n"],
5
+ "mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CACS,GAAU,GAAV,UAAU,GAAV,CACL,KAAM,GAAS,GAAI,GAAK,OAAO,iBAEzB,EAAS,GAAI,SAAQ,OAC3B,GAAI,GACA,EAAuB,EACvB,EAAe,GACf,EAAiB,GACjB,EAAmC,GACnC,EAA0B,EAC1B,EAAwB,GACxB,EAA+B,GAC/B,EAIO,KACP,EAAoB,GACpB,EAAkC,KAClC,EAAsB,GACtB,EAA6B,EAC7B,EAAe,EACf,EAAyB,GACzB,EACA,EAAoC,GACpC,EAAqB,GAOlB,WACL,EACA,EACA,CACA,GAAI,CACF,KAAM,GAAW,KAAK,MAAM,EAAS,eACrC,EAAO,KAAK,GACR,GAAqB,EAAkB,OAAS,GAClD,EAAK,aAAa,UAAU,SAEvB,EAAP,CACA,EAAO,MAAM,4CAA6C,IAXvD,GAAS,wBAsBT,WACL,EACA,EACA,EACA,CACA,EACG,UACA,iBACA,SAAS,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nB,GAAS,gBAl3BD,yCADT",
6
6
  "names": []
7
7
  }
@@ -340,7 +340,8 @@ module.exports = {
340
340
  _(
341
341
  'The friction applied when touching other objects. The higher the value, the more friction.'
342
342
  )
343
- );
343
+ )
344
+ .setGroup(_('Movement'));
344
345
  behaviorProperties
345
346
  .getOrCreate('restitution')
346
347
  .setValue(
@@ -352,7 +353,8 @@ module.exports = {
352
353
  _(
353
354
  'The "bounciness" of the object. The higher the value, the more other objects will bounce against it.'
354
355
  )
355
- );
356
+ )
357
+ .setGroup(_('Movement'));
356
358
  behaviorProperties
357
359
  .getOrCreate('linearDamping')
358
360
  .setValue(
@@ -300,7 +300,8 @@ module.exports = {
300
300
  _(
301
301
  'The friction applied when touching other objects. The higher the value, the more friction.'
302
302
  )
303
- );
303
+ )
304
+ .setGroup(_('Movement'));
304
305
  behaviorProperties
305
306
  .getOrCreate('restitution')
306
307
  .setValue(
@@ -315,7 +316,8 @@ module.exports = {
315
316
  _(
316
317
  'The "bounciness" of the object. The higher the value, the more other objects will bounce against it.'
317
318
  )
318
- );
319
+ )
320
+ .setGroup(_('Movement'));
319
321
  behaviorProperties
320
322
  .getOrCreate('linearDamping')
321
323
  .setValue(
@@ -1533,6 +1535,15 @@ module.exports = {
1533
1535
  return true;
1534
1536
  }
1535
1537
 
1538
+ if (propertyName === 'stairHeightMax') {
1539
+ const newValueAsNumber = parseFloat(newValue);
1540
+ if (newValueAsNumber !== newValueAsNumber) return false;
1541
+ behaviorContent
1542
+ .getChild('stairHeightMax')
1543
+ .setDoubleValue(newValueAsNumber);
1544
+ return true;
1545
+ }
1546
+
1536
1547
  if (propertyName === 'shouldBindObjectAndForwardAngle') {
1537
1548
  behaviorContent
1538
1549
  .getChild('shouldBindObjectAndForwardAngle')
@@ -1701,6 +1712,24 @@ module.exports = {
1701
1712
  .setAdvanced(true)
1702
1713
  .setQuickCustomizationVisibility(gd.QuickCustomization.Hidden);
1703
1714
 
1715
+ if (!behaviorContent.hasChild('stairHeightMax')) {
1716
+ behaviorContent.addChild('stairHeightMax').setDoubleValue(20);
1717
+ }
1718
+ behaviorProperties
1719
+ .getOrCreate('stairHeightMax')
1720
+ .setLabel('Max. stair height')
1721
+ .setGroup(_('Walk'))
1722
+ .setType('Number')
1723
+ .setMeasurementUnit(gd.MeasurementUnit.getPixel())
1724
+ .setValue(
1725
+ behaviorContent
1726
+ .getChild('stairHeightMax')
1727
+ .getDoubleValue()
1728
+ .toString(10)
1729
+ )
1730
+ .setAdvanced(true)
1731
+ .setQuickCustomizationVisibility(gd.QuickCustomization.Hidden);
1732
+
1704
1733
  behaviorProperties
1705
1734
  .getOrCreate('shouldBindObjectAndForwardAngle')
1706
1735
  .setLabel('Keep object angle and forward direction the same')
@@ -1732,6 +1761,7 @@ module.exports = {
1732
1761
  behaviorContent.addChild('sidewaysDeceleration').setDoubleValue(800);
1733
1762
  behaviorContent.addChild('sidewaysSpeedMax').setDoubleValue(400);
1734
1763
  behaviorContent.addChild('slopeMaxAngle').setDoubleValue(50);
1764
+ behaviorContent.addChild('stairHeightMax').setDoubleValue(20);
1735
1765
  behaviorContent
1736
1766
  .addChild('shouldBindObjectAndForwardAngle')
1737
1767
  .setBoolValue(true);
@@ -1,2 +1,2 @@
1
- var gdjs;(function(n){const g=async()=>{try{const t=(await import("./jolt-physics.wasm.js")).default;if(!t)throw new Error("No default export found in Jolt.");const e=await t();window.Jolt=e}catch(u){throw console.error("Unable to load Jolt physics library.",u),u}};n.registerAsynchronouslyLoadingLibraryPromise(g());class b{constructor(t,e){this._tempVec3=new Jolt.Vec3;this._tempRVec3=new Jolt.RVec3;this._tempQuat=new Jolt.Quat;this.stepped=!1;this._physics3DHooks=[];this._registeredBehaviors=new Set,this.gravityX=e.gravityX,this.gravityY=e.gravityY,this.gravityZ=e.gravityZ,this.worldScale=e.worldScale,this.worldInvScale=1/this.worldScale;const i=new Jolt.JoltSettings;n.Physics3DSharedData.setupCollisionFiltering(i),this.jolt=new Jolt.JoltInterface(i),Jolt.destroy(i),this.physicsSystem=this.jolt.GetPhysicsSystem(),this.physicsSystem.SetGravity(this.getVec3(this.gravityX,this.gravityY,this.gravityZ)),this.bodyInterface=this.physicsSystem.GetBodyInterface(),this.contactListener=new Jolt.ContactListenerJS,this.physicsSystem.SetContactListener(this.contactListener),this.contactListener.OnContactAdded=(s,o,a,h)=>{const d=Jolt.wrapPointer(s,Jolt.Body),l=Jolt.wrapPointer(o,Jolt.Body),r=d.gdjsAssociatedBehavior,f=l.gdjsAssociatedBehavior;!r||!f||(r.onContactBegin(f),f.onContactBegin(r))},this.contactListener.OnContactRemoved=s=>{const o=Jolt.wrapPointer(s,Jolt.SubShapeIDPair),a=this.physicsSystem.GetBodyLockInterface(),h=a.TryGetBody(o.GetBody1ID()),d=a.TryGetBody(o.GetBody2ID()),l=h.gdjsAssociatedBehavior,r=d.gdjsAssociatedBehavior;!l||!r||(l.onContactEnd(r),r.onContactEnd(l))},this.contactListener.OnContactPersisted=(s,o,a,h)=>{},this.contactListener.OnContactValidate=(s,o,a,h)=>Jolt.ValidateResult_AcceptAllContactsForThisBodyPair}getVec3(t,e,i){const s=this._tempVec3;return s.Set(t,e,i),s}getRVec3(t,e,i){const s=this._tempRVec3;return s.Set(t,e,i),s}getQuat(t,e,i,s){const o=this._tempQuat;return o.Set(t,e,i,s),o}static getSharedData(t,e){if(!t.physics3DSharedData){const i=t.getInitialSharedDataForBehavior(e);t.physics3DSharedData=new n.Physics3DSharedData(t,i)}return t.physics3DSharedData}static setupCollisionFiltering(t){const e=new Jolt.ObjectLayerPairFilterMask,i=new Jolt.BroadPhaseLayer(n.Physics3DSharedData.staticBroadPhaseLayerIndex),s=new Jolt.BroadPhaseLayer(n.Physics3DSharedData.dynamicBroadPhaseLayerIndex),o=new Jolt.BroadPhaseLayerInterfaceMask(2);o.ConfigureLayer(i,n.Physics3DSharedData.staticLayersMask,0),o.ConfigureLayer(s,n.Physics3DSharedData.dynamicLayersMask,0),Jolt.destroy(i),Jolt.destroy(s),t.mObjectLayerPairFilter=e,t.mBroadPhaseLayerInterface=o,t.mObjectVsBroadPhaseLayerFilter=new Jolt.ObjectVsBroadPhaseLayerFilterMask(o)}addToBehaviorsList(t){this._registeredBehaviors.add(t)}removeFromBehaviorsList(t){this._registeredBehaviors.delete(t)}step(t){for(const i of this._registeredBehaviors)i._contactsStartedThisFrame.length=0,i._contactsEndedThisFrame.length=0;for(const i of this._registeredBehaviors)i.updateBodyFromObject();for(const i of this._physics3DHooks)i.doBeforePhysicsStep(t);const e=t>1/55?2:1;this.jolt.Step(t,e),this.stepped=!0;for(const i of this._registeredBehaviors)i.updateObjectFromBody()}registerHook(t){this._physics3DHooks.push(t)}}b.staticLayersMask=15,b.dynamicLayersMask=240,b.allLayersMask=255,b.staticBroadPhaseLayerIndex=1,b.dynamicBroadPhaseLayerIndex=1,n.Physics3DSharedData=b,n.registerRuntimeSceneUnloadedCallback(function(u){const t=u.physics3DSharedData;t&&(Jolt.destroy(t.jolt),Jolt.destroy(t.contactListener),Jolt.destroy(t._tempVec3),Jolt.destroy(t._tempRVec3),Jolt.destroy(t._tempQuat),u.physics3DSharedData=null)});class p extends n.RuntimeBehavior{constructor(t,e,i){super(t,e,i);this.shapeScale=1;this._contactsStartedThisFrame=[];this._contactsEndedThisFrame=[];this._currentContacts=[];this._body=null;this._needToRecreateBody=!1;this._needToRecreateShape=!1;this._shapeHalfDepth=0;this._objectOldX=0;this._objectOldY=0;this._objectOldZ=0;this._objectOldRotationX=0;this._objectOldRotationY=0;this._objectOldRotationZ=0;this._objectOldWidth=0;this._objectOldHeight=0;this._objectOldDepth=0;this.bodyUpdater=new n.Physics3DRuntimeBehavior.DefaultBodyUpdater(this),this.owner3D=i,this.bodyType=e.bodyType,this.bullet=e.bullet,this.fixedRotation=e.fixedRotation,this.shape=e.shape,this.shapeOrientation=e.shapeOrientation,this.shapeDimensionA=e.shapeDimensionA,this.shapeDimensionB=e.shapeDimensionB,this.shapeDimensionC=e.shapeDimensionC,this.density=e.density,this.friction=e.friction,this.restitution=e.restitution,this.linearDamping=Math.max(0,e.linearDamping),this.angularDamping=Math.max(0,e.angularDamping),this.gravityScale=e.gravityScale,this.layers=e.layers,this.masks=e.masks,this._destroyedDuringFrameLogic=!1,this._sharedData=b.getSharedData(t.getScene(),e.name),this._sharedData.addToBehaviorsList(this)}getVec3(t,e,i){const s=this._sharedData._tempVec3;return s.Set(t,e,i),s}getRVec3(t,e,i){const s=this._sharedData._tempRVec3;return s.Set(t,e,i),s}getQuat(t,e,i,s){const o=this._sharedData._tempQuat;return o.Set(t,e,i,s),o}updateFromBehaviorData(t,e){return t.bullet!==e.bullet&&this.setBullet(e.bullet),t.fixedRotation!==e.fixedRotation&&this.setFixedRotation(e.fixedRotation),t.shapeDimensionA!==e.shapeDimensionA&&(this.shapeDimensionA=e.shapeDimensionA,this._needToRecreateShape=!0),t.shapeDimensionB!==e.shapeDimensionB&&(this.shapeDimensionB=e.shapeDimensionB,this._needToRecreateShape=!0),t.density!==e.density&&this.setDensity(e.density),t.friction!==e.friction&&this.setFriction(e.friction),t.restitution!==e.restitution&&this.setRestitution(e.restitution),t.linearDamping!==e.linearDamping&&this.setLinearDamping(e.linearDamping),t.angularDamping!==e.angularDamping&&this.setAngularDamping(e.angularDamping),t.gravityScale!==e.gravityScale&&this.setGravityScale(e.gravityScale),!(t.layers!==e.layers||t.masks!==e.masks||t.vertices!==e.vertices||t.bodyType!==e.bodyType||t.shape!==e.shape)}getNetworkSyncData(){let t;if(this._body){const e=this._body.GetPosition(),i=this._body.GetRotation(),s=this._body.GetLinearVelocity(),o=this._body.GetAngularVelocity();t={px:e.GetX(),py:e.GetY(),pz:e.GetZ(),rx:i.GetX(),ry:i.GetY(),rz:i.GetZ(),rw:i.GetW(),lvx:s.GetX(),lvy:s.GetY(),lvz:s.GetZ(),avx:o.GetX(),avy:o.GetY(),avz:o.GetZ(),aw:this._body.IsActive()}}else t={px:void 0,py:void 0,pz:void 0,rx:void 0,ry:void 0,rz:void 0,rw:void 0,lvx:void 0,lvy:void 0,lvz:void 0,avx:void 0,avy:void 0,avz:void 0,aw:void 0};return{...super.getNetworkSyncData(),props:{...t,layers:this.layers,masks:this.masks}}}updateFromNetworkSyncData(t){super.updateFromNetworkSyncData(t);const e=t.props;e.px!==void 0&&e.py!==void 0&&e.pz!==void 0&&this._body&&this._sharedData.bodyInterface.SetPosition(this._body.GetID(),this.getVec3(e.px,e.py,e.pz),Jolt.EActivation_DontActivate),e.rx!==void 0&&e.ry!==void 0&&e.rz!==void 0&&e.rw!==void 0&&this._body&&this._sharedData.bodyInterface.SetRotation(this._body.GetID(),this.getQuat(e.rx,e.ry,e.rz,e.rw),Jolt.EActivation_DontActivate),e.lvx!==void 0&&e.lvy!==void 0&&e.lvz!==void 0&&this._body&&this._sharedData.bodyInterface.SetLinearVelocity(this._body.GetID(),this.getVec3(e.lvx,e.lvy,e.lvz)),e.avx!==void 0&&e.avy!==void 0&&e.avz!==void 0&&this._body&&this._sharedData.bodyInterface.SetAngularVelocity(this._body.GetID(),this.getVec3(e.avx,e.avy,e.avz)),e.layers!==void 0&&(this.layers=e.layers),e.masks!==void 0&&(this.masks=e.masks)}onDeActivate(){this._sharedData.removeFromBehaviorsList(this),this._body!==null&&(this._sharedData.bodyInterface.RemoveBody(this._body.GetID()),this._sharedData.bodyInterface.DestroyBody(this._body.GetID()),this._body=null),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0}onActivate(){this._sharedData.addToBehaviorsList(this),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0,this.updateBodyFromObject()}onDestroy(){this._destroyedDuringFrameLogic=!0,this.onDeActivate()}createShape(){let t=this.owner3D.getWidth()*this._sharedData.worldInvScale,e=this.owner3D.getHeight()*this._sharedData.worldInvScale,i=this.owner3D.getDepth()*this._sharedData.worldInvScale;if(this.shapeOrientation==="X"){const c=i;i=t,t=c}else if(this.shapeOrientation==="Y"){const c=i;i=e,e=c}const s=this.shapeScale*this._sharedData.worldInvScale,o=this.shapeDimensionA*s,a=this.shapeDimensionB*s,h=this.shapeDimensionC*s,d=this._sharedData.worldInvScale;let l,r;if(this.shape==="Box"){const c=o>0?o:t>0?t:d,y=a>0?a:e>0?e:d,_=h>0?h:i>0?i:d,D=Math.min(d,Math.min(c,y,_)/4);l=new Jolt.BoxShapeSettings(this.getVec3(c/2,y/2,_/2),D),r=this.getQuat(0,0,0,1),this._shapeHalfDepth=_/2}else if(this.shape==="Capsule"){const c=o>0?o:t>0?Math.sqrt(t*e)/2:d,y=a>0?a:i>0?i:d;l=new Jolt.CapsuleShapeSettings(Math.max(0,y/2-c),c),r=this._getShapeOrientationQuat(),this._shapeHalfDepth=this.shapeOrientation!=="Z"?c:y/2}else if(this.shape==="Cylinder"){const c=o>0?o:t>0?Math.sqrt(t*e)/2:d,y=a>0?a:i>0?i:d,_=Math.min(d,Math.min(y,c)/4);l=new Jolt.CylinderShapeSettings(y/2,c,_),r=this._getShapeOrientationQuat(),this._shapeHalfDepth=this.shapeOrientation!=="Z"?c:y/2}else{const c=o>0?o:t>0?Math.pow(t*e*i,1/3)/2:d;l=new Jolt.SphereShapeSettings(c),r=this.getQuat(0,0,0,1),this._shapeHalfDepth=c}l.mDensity=this.density;const f=new Jolt.RotatedTranslatedShapeSettings(this.getVec3(0,0,0),r,l).Create().Get();return Jolt.destroy(l),f}_getShapeOrientationQuat(){return this.shapeOrientation==="X"?this.getQuat(0,0,Math.sqrt(2)/2,-Math.sqrt(2)/2):this.shapeOrientation==="Y"?this.getQuat(0,0,0,1):this.getQuat(Math.sqrt(2)/2,0,0,Math.sqrt(2)/2)}_recreateShape(){this.bodyUpdater.recreateShape(),this._objectOldWidth=this.owner3D.getWidth(),this._objectOldHeight=this.owner3D.getHeight(),this._objectOldDepth=this.owner3D.getDepth()}getShapeScale(){return this.shapeScale}setShapeScale(t){t!==this.shapeScale&&t>0&&(this.shapeScale=t,this._needToRecreateShape=!0)}getBody(){return this._body===null&&this._createBody(),this._body}_createBody(){return this._needToRecreateBody=!1,this._needToRecreateShape=!1,!this.activated()||this._destroyedDuringFrameLogic?!1:(this._body=this.bodyUpdater.createAndAddBody(),this._body.gdjsAssociatedBehavior=this,this._objectOldWidth=this.owner3D.getWidth(),this._objectOldHeight=this.owner3D.getHeight(),this._objectOldDepth=this.owner3D.getDepth(),!0)}getBodyLayer(){return Jolt.ObjectLayerPairFilterMask.prototype.sGetObjectLayer(this.bodyType==="Static"?this.layers&n.Physics3DSharedData.staticLayersMask:this.layers&n.Physics3DSharedData.dynamicLayersMask,this.bodyType==="Static"?n.Physics3DSharedData.allLayersMask:this.masks)}doStepPreEvents(t){!this._sharedData.stepped&&!t.getScene().getTimeManager().isFirstFrame()&&this._sharedData.step(t.getScene().getTimeManager().getElapsedTime()/1e3)}doStepPostEvents(t){this._sharedData.stepped=!1}onObjectHotReloaded(){this.updateBodyFromObject()}recreateBody(){if(!this._body){this._createBody();return}const t=this._sharedData.bodyInterface,e=this._body.GetLinearVelocity(),i=e.GetX(),s=e.GetY(),o=e.GetZ(),a=this._body.GetAngularVelocity(),h=a.GetX(),d=a.GetY(),l=a.GetZ();let r=this._body.GetID();t.RemoveBody(r),t.DestroyBody(r),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0,this._createBody(),!!this._body&&(r=this._body.GetID(),t.SetLinearVelocity(r,this.getVec3(i,s,o)),t.SetAngularVelocity(r,this.getVec3(h,d,l)))}updateObjectFromBody(){this.bodyUpdater.updateObjectFromBody(),this._objectOldX=this.owner3D.getX(),this._objectOldY=this.owner3D.getY(),this._objectOldZ=this.owner3D.getZ(),this._objectOldRotationX=this.owner3D.getRotationX(),this._objectOldRotationY=this.owner3D.getRotationY(),this._objectOldRotationZ=this.owner3D.getAngle()}updateBodyFromObject(){this._body===null&&!this._createBody()||(this._needToRecreateBody&&this.recreateBody(),(this._needToRecreateShape||!this.hasCustomShapeDimension()&&(this._objectOldWidth!==this.owner3D.getWidth()||this._objectOldHeight!==this.owner3D.getHeight()||this._objectOldDepth!==this.owner3D.getDepth()))&&(this._needToRecreateShape=!1,this._recreateShape()),this.bodyUpdater.updateBodyFromObject())}hasCustomShapeDimension(){return this.shapeDimensionA>0||this.shapeDimensionB>0||this.shapeDimensionC>0}getPhysicsPosition(t){return t.Set(this.owner3D.getCenterXInScene()*this._sharedData.worldInvScale,this.owner3D.getCenterYInScene()*this._sharedData.worldInvScale,this.owner3D.getCenterZInScene()*this._sharedData.worldInvScale),t}getPhysicsRotation(t){const e=this.owner3D.get3DRendererObject();return t.Set(e.quaternion.x,e.quaternion.y,e.quaternion.z,e.quaternion.w),t}moveObjectToPhysicsPosition(t){this.owner3D.setCenterXInScene(t.GetX()*this._sharedData.worldScale),this.owner3D.setCenterYInScene(t.GetY()*this._sharedData.worldScale),this.owner3D.setCenterZInScene(t.GetZ()*this._sharedData.worldScale)}moveObjectToPhysicsRotation(t){const e=this.owner3D.get3DRendererObject();e.quaternion.x=t.GetX(),e.quaternion.y=t.GetY(),e.quaternion.z=t.GetZ(),e.quaternion.w=t.GetW();const i=new THREE.Euler(0,0,0,"ZYX");i.setFromQuaternion(e.quaternion),this.owner3D.setRotationX(n.toDegrees(i.x)),this.owner3D.setRotationY(n.toDegrees(i.y)),this.owner3D.setAngle(n.toDegrees(i.z))}getWorldScale(){return this._sharedData.worldScale}getGravityX(){return this._sharedData.gravityX}getGravityY(){return this._sharedData.gravityY}getGravityZ(){return this._sharedData.gravityZ}setGravityX(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityX=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}setGravityY(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityX=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}setGravityZ(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityZ=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}isDynamic(){return this.bodyType==="Dynamic"}isStatic(){return this.bodyType==="Static"}isKinematic(){return this.bodyType==="Kinematic"}isBullet(){return this.bullet}setBullet(t){if(this.bullet===t||(this.bullet=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetMotionQuality(e.GetID(),this.bullet?Jolt.EMotionQuality_LinearCast:Jolt.EMotionQuality_Discrete)}hasFixedRotation(){return this.fixedRotation}setFixedRotation(t){this.fixedRotation!==t&&(this.fixedRotation=t,this._needToRecreateBody=!0)}getDensity(){return this.density}setDensity(t){t<0&&(t=0),this.density!==t&&(this.density=t,this._needToRecreateShape=!0)}getFriction(){return this.friction}setFriction(t){if(t<0&&(t=0),this.friction===t||(this.friction=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetFriction(e.GetID(),t)}getRestitution(){return this.restitution}setRestitution(t){if(t<0&&(t=0),this.restitution===t||(this.restitution=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetRestitution(e.GetID(),t)}getLinearDamping(){return this.linearDamping}setLinearDamping(t){if(t<0&&(t=0),this.linearDamping===t||(this.linearDamping=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetLinearDamping(t)}getAngularDamping(){return this.angularDamping}setAngularDamping(t){if(t<0&&(t=0),this.angularDamping===t||(this.angularDamping=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetAngularDamping(t)}getGravityScale(){return this.gravityScale}setGravityScale(t){if(this.gravityScale===t||(this.gravityScale=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetGravityFactor(t)}layerEnabled(t){return t=Math.floor(t),t<1||t>8?!1:!!(this.layers&1<<t-1)}enableLayer(t,e){t=Math.floor(t),!(t<1||t>8)&&(e?this.layers|=1<<t-1:this.layers&=~(1<<t-1),this._needToRecreateBody=!0)}maskEnabled(t){return t=Math.floor(t),t<1||t>16?!1:!!(this.masks&1<<t-1)}enableMask(t,e){t=Math.floor(t),!(t<1||t>16)&&(e?this.masks|=1<<t-1:this.masks&=~(1<<t-1),this._needToRecreateBody=!0)}getLinearVelocityX(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetX()*this._sharedData.worldScale}setLinearVelocityX(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(t*this._sharedData.worldInvScale,e.GetLinearVelocity().GetY(),e.GetLinearVelocity().GetZ()))}getLinearVelocityY(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetY()*this._sharedData.worldScale}setLinearVelocityY(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(e.GetLinearVelocity().GetX(),t*this._sharedData.worldInvScale,e.GetLinearVelocity().GetZ()))}getLinearVelocityZ(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetZ()*this._sharedData.worldScale}setLinearVelocityZ(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(e.GetLinearVelocity().GetX(),e.GetLinearVelocity().GetY(),t*this._sharedData.worldInvScale))}getLinearVelocityLength(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().Length()*this._sharedData.worldScale}getAngularVelocityX(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetX())}setAngularVelocityX(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(n.toRad(t),e.GetAngularVelocity().GetY(),e.GetAngularVelocity().GetZ()))}getAngularVelocityY(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetY())}setAngularVelocityY(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(e.GetAngularVelocity().GetX(),n.toRad(t),e.GetAngularVelocity().GetZ()))}getAngularVelocityZ(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetZ())}setAngularVelocityZ(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(e.GetAngularVelocity().GetX(),e.GetAngularVelocity().GetY(),n.toRad(t)))}applyForce(t,e,i,s,o,a){if(this._body===null&&!this._createBody())return;const h=this._body;this._sharedData.bodyInterface.AddForce(h.GetID(),this.getVec3(t,e,i),this.getRVec3(s*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale),Jolt.EActivation_Activate)}applyForceAtCenter(t,e,i){if(this._body===null&&!this._createBody())return;const s=this._body;this._sharedData.bodyInterface.AddForce(s.GetID(),this.getVec3(t,e,i),Jolt.EActivation_Activate)}applyForceTowardPosition(t,e,i,s){if(this._body===null&&!this._createBody())return;const o=this._body,a=e-o.GetPosition().GetX(),h=i-o.GetPosition().GetY(),d=s-o.GetPosition().GetZ(),l=a*a+h*h+d*d;if(l===0)return;const r=t/l;this._sharedData.bodyInterface.AddForce(o.GetID(),this.getVec3(a*r,h*r,d*r),Jolt.EActivation_Activate)}applyImpulse(t,e,i,s,o,a){if(this._body===null&&!this._createBody())return;const h=this._body;this._sharedData.bodyInterface.AddImpulse(h.GetID(),this.getVec3(t,e,i),this.getRVec3(s*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale))}applyImpulseAtCenter(t,e,i){if(this._body===null&&!this._createBody())return;const s=this._body;this._sharedData.bodyInterface.AddImpulse(s.GetID(),this.getVec3(t,e,i))}applyImpulseTowardPosition(t,e,i,s,o,a,h){if(this._body===null&&!this._createBody())return;const d=this._body,l=e-o,r=i-a,f=s-h,c=l*l+r*r+f*f;if(c===0)return;const y=t/c;this._sharedData.bodyInterface.AddImpulse(d.GetID(),this.getVec3(l*y,r*y,f*y),this.getRVec3(o*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale,h*this._sharedData.worldInvScale))}applyTorque(t,e,i){if(this._body===null&&!this._createBody())return;const s=this._body;this._sharedData.bodyInterface.AddTorque(s.GetID(),this.getVec3(n.toRad(t),n.toRad(e),n.toRad(i)),Jolt.EActivation_Activate)}applyAngularImpulse(t,e,i){if(this._body===null&&!this._createBody())return;const s=this._body;this._sharedData.bodyInterface.AddAngularImpulse(s.GetID(),this.getVec3(n.toRad(t),n.toRad(e),n.toRad(i)))}getMass(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseMass()}getInertiaAroundX(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetX()}getInertiaAroundY(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetY()}getInertiaAroundZ(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetZ()}getMassCenterX(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetX()*this._sharedData.worldScale}getMassCenterY(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetY()*this._sharedData.worldScale}getMassCenterZ(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetZ()*this._sharedData.worldScale}onContactBegin(t){this._currentContacts.push(t);let e=this._contactsEndedThisFrame.indexOf(t);e!==-1?this._contactsEndedThisFrame.splice(e,1):this._contactsStartedThisFrame.push(t)}onContactEnd(t){this._contactsEndedThisFrame.push(t);const e=this._currentContacts.indexOf(t);e!==-1&&this._currentContacts.splice(e,1)}static areObjectsColliding(t,e,i){const s=t.getBehavior(i);return s?!!(s._currentContacts.some(o=>o.owner===e)||s._contactsStartedThisFrame.some(o=>o.owner===e)):!1}static hasCollisionStartedBetween(t,e,i){const s=t.getBehavior(i);return s?s._contactsStartedThisFrame.some(o=>o.owner===e):!1}static hasCollisionStoppedBetween(t,e,i){const s=t.getBehavior(i);return s?s._contactsEndedThisFrame.some(o=>o.owner===e):!1}}n.Physics3DRuntimeBehavior=p,n.registerBehavior("Physics3D::Physics3DBehavior",n.Physics3DRuntimeBehavior),function(t){class u{constructor(i){this.behavior=i}createAndAddBody(){const{behavior:i}=this,{_sharedData:s}=i,o=i.createShape(),a=new Jolt.BodyCreationSettings(o,i.getPhysicsPosition(s.getRVec3(0,0,0)),i.getPhysicsRotation(s.getQuat(0,0,0,1)),i.bodyType==="Static"?Jolt.EMotionType_Static:i.bodyType==="Kinematic"?Jolt.EMotionType_Kinematic:Jolt.EMotionType_Dynamic,i.getBodyLayer());a.mMotionQuality=i.bullet?Jolt.EMotionQuality_LinearCast:Jolt.EMotionQuality_Discrete,a.mAllowedDOFs=i.fixedRotation?Jolt.EAllowedDOFs_TranslationX|Jolt.EAllowedDOFs_TranslationY|Jolt.EAllowedDOFs_TranslationZ:Jolt.EAllowedDOFs_All,a.mFriction=i.friction,a.mRestitution=i.restitution,a.mLinearDamping=i.linearDamping,a.mAngularDamping=i.angularDamping,a.mGravityFactor=i.gravityScale;const h=s.bodyInterface,d=h.CreateBody(a);return Jolt.destroy(a),h.AddBody(d.GetID(),Jolt.EActivation_Activate),d}updateObjectFromBody(){const{behavior:i}=this,{_body:s}=i;s!==null&&(i.moveObjectToPhysicsPosition(s.GetPosition()),i.moveObjectToPhysicsRotation(s.GetRotation()))}updateBodyFromObject(){const{behavior:i}=this,{owner3D:s,_sharedData:o}=i;if(i._body===null&&!i._createBody())return;const a=i._body;(this.behavior._objectOldX!==s.getX()||this.behavior._objectOldY!==s.getY()||this.behavior._objectOldZ!==s.getZ()||this.behavior._objectOldRotationX!==s.getRotationX()||this.behavior._objectOldRotationY!==s.getRotationY()||this.behavior._objectOldRotationZ!==s.getAngle())&&o.bodyInterface.SetPositionAndRotationWhenChanged(a.GetID(),this.behavior.getPhysicsPosition(o.getRVec3(0,0,0)),this.behavior.getPhysicsRotation(o.getQuat(0,0,0,1)),Jolt.EActivation_Activate)}recreateShape(){const{behavior:i}=this,{_sharedData:s}=i;if(i._body===null&&!i._createBody())return;const o=i._body;s.bodyInterface.SetShape(o.GetID(),i.createShape(),!0,Jolt.EActivation_Activate)}}t.DefaultBodyUpdater=u}(p=n.Physics3DRuntimeBehavior||(n.Physics3DRuntimeBehavior={}))})(gdjs||(gdjs={}));
1
+ var gdjs;(function(n){const g=async()=>{try{const t=(await import("./jolt-physics.wasm.js")).default;if(!t)throw new Error("No default export found in Jolt.");const e=await t();window.Jolt=e}catch(u){throw console.error("Unable to load Jolt physics library.",u),u}};n.registerAsynchronouslyLoadingLibraryPromise(g());class b{constructor(t,e){this._tempVec3=new Jolt.Vec3;this._tempRVec3=new Jolt.RVec3;this._tempQuat=new Jolt.Quat;this.stepped=!1;this._physics3DHooks=[];this._registeredBehaviors=new Set,this.gravityX=e.gravityX,this.gravityY=e.gravityY,this.gravityZ=e.gravityZ,this.worldScale=e.worldScale,this.worldInvScale=1/this.worldScale;const o=new Jolt.JoltSettings;n.Physics3DSharedData.setupCollisionFiltering(o),this.jolt=new Jolt.JoltInterface(o),Jolt.destroy(o),this.physicsSystem=this.jolt.GetPhysicsSystem(),this.physicsSystem.SetGravity(this.getVec3(this.gravityX,this.gravityY,this.gravityZ)),this.bodyInterface=this.physicsSystem.GetBodyInterface(),this.contactListener=new Jolt.ContactListenerJS,this.physicsSystem.SetContactListener(this.contactListener),this.contactListener.OnContactAdded=(i,s,a,r)=>{const d=Jolt.wrapPointer(i,Jolt.Body),l=Jolt.wrapPointer(s,Jolt.Body),h=d.gdjsAssociatedBehavior,f=l.gdjsAssociatedBehavior;!h||!f||(h.onContactBegin(f),f.onContactBegin(h))},this.contactListener.OnContactRemoved=i=>{const s=Jolt.wrapPointer(i,Jolt.SubShapeIDPair),a=this.physicsSystem.GetBodyLockInterface(),r=a.TryGetBody(s.GetBody1ID()),d=a.TryGetBody(s.GetBody2ID()),l=r.gdjsAssociatedBehavior,h=d.gdjsAssociatedBehavior;!l||!h||(l.onContactEnd(h),h.onContactEnd(l))},this.contactListener.OnContactPersisted=(i,s,a,r)=>{},this.contactListener.OnContactValidate=(i,s,a,r)=>Jolt.ValidateResult_AcceptAllContactsForThisBodyPair}getVec3(t,e,o){const i=this._tempVec3;return i.Set(t,e,o),i}getRVec3(t,e,o){const i=this._tempRVec3;return i.Set(t,e,o),i}getQuat(t,e,o,i){const s=this._tempQuat;return s.Set(t,e,o,i),s}static getSharedData(t,e){if(!t.physics3DSharedData){const o=t.getInitialSharedDataForBehavior(e);t.physics3DSharedData=new n.Physics3DSharedData(t,o)}return t.physics3DSharedData}static setupCollisionFiltering(t){const e=new Jolt.ObjectLayerPairFilterMask,o=new Jolt.BroadPhaseLayer(n.Physics3DSharedData.staticBroadPhaseLayerIndex),i=new Jolt.BroadPhaseLayer(n.Physics3DSharedData.dynamicBroadPhaseLayerIndex),s=new Jolt.BroadPhaseLayerInterfaceMask(2);s.ConfigureLayer(o,n.Physics3DSharedData.staticLayersMask,0),s.ConfigureLayer(i,n.Physics3DSharedData.dynamicLayersMask,0),Jolt.destroy(o),Jolt.destroy(i),t.mObjectLayerPairFilter=e,t.mBroadPhaseLayerInterface=s,t.mObjectVsBroadPhaseLayerFilter=new Jolt.ObjectVsBroadPhaseLayerFilterMask(s)}addToBehaviorsList(t){this._registeredBehaviors.add(t)}removeFromBehaviorsList(t){this._registeredBehaviors.delete(t)}step(t){for(const o of this._registeredBehaviors)o._contactsStartedThisFrame.length=0,o._contactsEndedThisFrame.length=0;for(const o of this._registeredBehaviors)o.updateBodyFromObject();for(const o of this._physics3DHooks)o.doBeforePhysicsStep(t);const e=t>1/55?2:1;this.jolt.Step(t,e),this.stepped=!0;for(const o of this._registeredBehaviors)o.updateObjectFromBody()}registerHook(t){this._physics3DHooks.push(t)}}b.staticLayersMask=15,b.dynamicLayersMask=240,b.allLayersMask=255,b.staticBroadPhaseLayerIndex=1,b.dynamicBroadPhaseLayerIndex=1,n.Physics3DSharedData=b,n.registerRuntimeSceneUnloadedCallback(function(u){const t=u.physics3DSharedData;t&&(Jolt.destroy(t.jolt),Jolt.destroy(t.contactListener),Jolt.destroy(t._tempVec3),Jolt.destroy(t._tempRVec3),Jolt.destroy(t._tempQuat),u.physics3DSharedData=null)});class p extends n.RuntimeBehavior{constructor(t,e,o){super(t,e,o);this.shapeScale=1;this._contactsStartedThisFrame=[];this._contactsEndedThisFrame=[];this._currentContacts=[];this._body=null;this._needToRecreateBody=!1;this._needToRecreateShape=!1;this._shapeHalfDepth=0;this._objectOldX=0;this._objectOldY=0;this._objectOldZ=0;this._objectOldRotationX=0;this._objectOldRotationY=0;this._objectOldRotationZ=0;this._objectOldWidth=0;this._objectOldHeight=0;this._objectOldDepth=0;this.bodyUpdater=new n.Physics3DRuntimeBehavior.DefaultBodyUpdater(this),this.collisionChecker=new n.Physics3DRuntimeBehavior.DefaultCollisionChecker(this),this.owner3D=o,this.bodyType=e.bodyType,this.bullet=e.bullet,this.fixedRotation=e.fixedRotation,this.shape=e.shape,this.shapeOrientation=e.shapeOrientation,this.shapeDimensionA=e.shapeDimensionA,this.shapeDimensionB=e.shapeDimensionB,this.shapeDimensionC=e.shapeDimensionC,this.density=e.density,this.friction=e.friction,this.restitution=e.restitution,this.linearDamping=Math.max(0,e.linearDamping),this.angularDamping=Math.max(0,e.angularDamping),this.gravityScale=e.gravityScale,this.layers=e.layers,this.masks=e.masks,this._destroyedDuringFrameLogic=!1,this._sharedData=b.getSharedData(t.getScene(),e.name),this._sharedData.addToBehaviorsList(this)}getVec3(t,e,o){const i=this._sharedData._tempVec3;return i.Set(t,e,o),i}getRVec3(t,e,o){const i=this._sharedData._tempRVec3;return i.Set(t,e,o),i}getQuat(t,e,o,i){const s=this._sharedData._tempQuat;return s.Set(t,e,o,i),s}updateFromBehaviorData(t,e){return t.bullet!==e.bullet&&this.setBullet(e.bullet),t.fixedRotation!==e.fixedRotation&&this.setFixedRotation(e.fixedRotation),t.shapeDimensionA!==e.shapeDimensionA&&(this.shapeDimensionA=e.shapeDimensionA,this._needToRecreateShape=!0),t.shapeDimensionB!==e.shapeDimensionB&&(this.shapeDimensionB=e.shapeDimensionB,this._needToRecreateShape=!0),t.density!==e.density&&this.setDensity(e.density),t.friction!==e.friction&&this.setFriction(e.friction),t.restitution!==e.restitution&&this.setRestitution(e.restitution),t.linearDamping!==e.linearDamping&&this.setLinearDamping(e.linearDamping),t.angularDamping!==e.angularDamping&&this.setAngularDamping(e.angularDamping),t.gravityScale!==e.gravityScale&&this.setGravityScale(e.gravityScale),!(t.layers!==e.layers||t.masks!==e.masks||t.vertices!==e.vertices||t.bodyType!==e.bodyType||t.shape!==e.shape)}getNetworkSyncData(){let t;if(this._body){const e=this._body.GetPosition(),o=this._body.GetRotation(),i=this._body.GetLinearVelocity(),s=this._body.GetAngularVelocity();t={px:e.GetX(),py:e.GetY(),pz:e.GetZ(),rx:o.GetX(),ry:o.GetY(),rz:o.GetZ(),rw:o.GetW(),lvx:i.GetX(),lvy:i.GetY(),lvz:i.GetZ(),avx:s.GetX(),avy:s.GetY(),avz:s.GetZ(),aw:this._body.IsActive()}}else t={px:void 0,py:void 0,pz:void 0,rx:void 0,ry:void 0,rz:void 0,rw:void 0,lvx:void 0,lvy:void 0,lvz:void 0,avx:void 0,avy:void 0,avz:void 0,aw:void 0};return{...super.getNetworkSyncData(),props:{...t,layers:this.layers,masks:this.masks}}}updateFromNetworkSyncData(t){super.updateFromNetworkSyncData(t);const e=t.props;e.px!==void 0&&e.py!==void 0&&e.pz!==void 0&&this._body&&this._sharedData.bodyInterface.SetPosition(this._body.GetID(),this.getRVec3(e.px,e.py,e.pz),Jolt.EActivation_DontActivate),e.rx!==void 0&&e.ry!==void 0&&e.rz!==void 0&&e.rw!==void 0&&this._body&&this._sharedData.bodyInterface.SetRotation(this._body.GetID(),this.getQuat(e.rx,e.ry,e.rz,e.rw),Jolt.EActivation_DontActivate),e.lvx!==void 0&&e.lvy!==void 0&&e.lvz!==void 0&&this._body&&this._sharedData.bodyInterface.SetLinearVelocity(this._body.GetID(),this.getVec3(e.lvx,e.lvy,e.lvz)),e.avx!==void 0&&e.avy!==void 0&&e.avz!==void 0&&this._body&&this._sharedData.bodyInterface.SetAngularVelocity(this._body.GetID(),this.getVec3(e.avx,e.avy,e.avz)),e.layers!==void 0&&(this.layers=e.layers),e.masks!==void 0&&(this.masks=e.masks)}onDeActivate(){this._sharedData.removeFromBehaviorsList(this),this._body!==null&&(this._sharedData.bodyInterface.RemoveBody(this._body.GetID()),this._sharedData.bodyInterface.DestroyBody(this._body.GetID()),this._body=null),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0}onActivate(){this._sharedData.addToBehaviorsList(this),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0,this.updateBodyFromObject()}onDestroy(){this._destroyedDuringFrameLogic=!0,this.onDeActivate()}createShape(){let t=this.owner3D.getWidth()*this._sharedData.worldInvScale,e=this.owner3D.getHeight()*this._sharedData.worldInvScale,o=this.owner3D.getDepth()*this._sharedData.worldInvScale;if(this.shapeOrientation==="X"){const c=o;o=t,t=c}else if(this.shapeOrientation==="Y"){const c=o;o=e,e=c}const i=this.shapeScale*this._sharedData.worldInvScale,s=this.shapeDimensionA*i,a=this.shapeDimensionB*i,r=this.shapeDimensionC*i,d=this._sharedData.worldInvScale;let l,h;if(this.shape==="Box"){const c=s>0?s:t>0?t:d,y=a>0?a:e>0?e:d,_=r>0?r:o>0?o:d,D=Math.min(d,Math.min(c,y,_)/4);l=new Jolt.BoxShapeSettings(this.getVec3(c/2,y/2,_/2),D),h=this.getQuat(0,0,0,1),this._shapeHalfDepth=_/2}else if(this.shape==="Capsule"){const c=s>0?s:t>0?Math.sqrt(t*e)/2:d,y=a>0?a:o>0?o:d;l=new Jolt.CapsuleShapeSettings(Math.max(0,y/2-c),c),h=this._getShapeOrientationQuat(),this._shapeHalfDepth=this.shapeOrientation!=="Z"?c:y/2}else if(this.shape==="Cylinder"){const c=s>0?s:t>0?Math.sqrt(t*e)/2:d,y=a>0?a:o>0?o:d,_=Math.min(d,Math.min(y,c)/4);l=new Jolt.CylinderShapeSettings(y/2,c,_),h=this._getShapeOrientationQuat(),this._shapeHalfDepth=this.shapeOrientation!=="Z"?c:y/2}else{const c=s>0?s:t>0?Math.pow(t*e*o,1/3)/2:d;l=new Jolt.SphereShapeSettings(c),h=this.getQuat(0,0,0,1),this._shapeHalfDepth=c}l.mDensity=this.density;const f=new Jolt.RotatedTranslatedShapeSettings(this.getVec3(0,0,0),h,l).Create().Get();return Jolt.destroy(l),f}_getShapeOrientationQuat(){return this.shapeOrientation==="X"?this.getQuat(0,0,Math.sqrt(2)/2,-Math.sqrt(2)/2):this.shapeOrientation==="Y"?this.getQuat(0,0,0,1):this.getQuat(Math.sqrt(2)/2,0,0,Math.sqrt(2)/2)}_recreateShape(){this.bodyUpdater.recreateShape(),this._objectOldWidth=this.owner3D.getWidth(),this._objectOldHeight=this.owner3D.getHeight(),this._objectOldDepth=this.owner3D.getDepth()}getShapeScale(){return this.shapeScale}setShapeScale(t){t!==this.shapeScale&&t>0&&(this.shapeScale=t,this._needToRecreateShape=!0)}getBody(){return this._body===null&&this._createBody(),this._body}_createBody(){return this._needToRecreateBody=!1,this._needToRecreateShape=!1,!this.activated()||this._destroyedDuringFrameLogic?!1:(this._body=this.bodyUpdater.createAndAddBody(),this._body.gdjsAssociatedBehavior=this,this._objectOldWidth=this.owner3D.getWidth(),this._objectOldHeight=this.owner3D.getHeight(),this._objectOldDepth=this.owner3D.getDepth(),!0)}getBodyLayer(){return Jolt.ObjectLayerPairFilterMask.prototype.sGetObjectLayer(this.bodyType==="Static"?this.layers&n.Physics3DSharedData.staticLayersMask:this.layers&n.Physics3DSharedData.dynamicLayersMask,this.bodyType==="Static"?n.Physics3DSharedData.allLayersMask:this.masks)}doStepPreEvents(t){!this._sharedData.stepped&&!t.getScene().getTimeManager().isFirstFrame()&&this._sharedData.step(t.getScene().getTimeManager().getElapsedTime()/1e3)}doStepPostEvents(t){this._sharedData.stepped=!1}onObjectHotReloaded(){this.updateBodyFromObject()}recreateBody(){if(!this._body){this._createBody();return}const t=this._sharedData.bodyInterface,e=this._body.GetLinearVelocity(),o=e.GetX(),i=e.GetY(),s=e.GetZ(),a=this._body.GetAngularVelocity(),r=a.GetX(),d=a.GetY(),l=a.GetZ();let h=this._body.GetID();t.RemoveBody(h),t.DestroyBody(h),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0,this._createBody(),!!this._body&&(h=this._body.GetID(),t.SetLinearVelocity(h,this.getVec3(o,i,s)),t.SetAngularVelocity(h,this.getVec3(r,d,l)))}updateObjectFromBody(){this.bodyUpdater.updateObjectFromBody(),this._objectOldX=this.owner3D.getX(),this._objectOldY=this.owner3D.getY(),this._objectOldZ=this.owner3D.getZ(),this._objectOldRotationX=this.owner3D.getRotationX(),this._objectOldRotationY=this.owner3D.getRotationY(),this._objectOldRotationZ=this.owner3D.getAngle()}updateBodyFromObject(){this._body===null&&!this._createBody()||(this._needToRecreateBody&&this.recreateBody(),(this._needToRecreateShape||!this.hasCustomShapeDimension()&&(this._objectOldWidth!==this.owner3D.getWidth()||this._objectOldHeight!==this.owner3D.getHeight()||this._objectOldDepth!==this.owner3D.getDepth()))&&(this._needToRecreateShape=!1,this._recreateShape()),this.bodyUpdater.updateBodyFromObject())}hasCustomShapeDimension(){return this.shapeDimensionA>0||this.shapeDimensionB>0||this.shapeDimensionC>0}getPhysicsPosition(t){return t.Set(this.owner3D.getCenterXInScene()*this._sharedData.worldInvScale,this.owner3D.getCenterYInScene()*this._sharedData.worldInvScale,this.owner3D.getCenterZInScene()*this._sharedData.worldInvScale),t}getPhysicsRotation(t){const e=this.owner3D.get3DRendererObject();return t.Set(e.quaternion.x,e.quaternion.y,e.quaternion.z,e.quaternion.w),t}moveObjectToPhysicsPosition(t){this.owner3D.setCenterXInScene(t.GetX()*this._sharedData.worldScale),this.owner3D.setCenterYInScene(t.GetY()*this._sharedData.worldScale),this.owner3D.setCenterZInScene(t.GetZ()*this._sharedData.worldScale)}moveObjectToPhysicsRotation(t){const e=this.owner3D.get3DRendererObject();e.quaternion.x=t.GetX(),e.quaternion.y=t.GetY(),e.quaternion.z=t.GetZ(),e.quaternion.w=t.GetW();const o=new THREE.Euler(0,0,0,"ZYX");o.setFromQuaternion(e.quaternion),this.owner3D.setRotationX(n.toDegrees(o.x)),this.owner3D.setRotationY(n.toDegrees(o.y)),this.owner3D.setAngle(n.toDegrees(o.z))}getWorldScale(){return this._sharedData.worldScale}getGravityX(){return this._sharedData.gravityX}getGravityY(){return this._sharedData.gravityY}getGravityZ(){return this._sharedData.gravityZ}setGravityX(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityX=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}setGravityY(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityX=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}setGravityZ(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityZ=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}isDynamic(){return this.bodyType==="Dynamic"}isStatic(){return this.bodyType==="Static"}isKinematic(){return this.bodyType==="Kinematic"}isBullet(){return this.bullet}setBullet(t){if(this.bullet===t||(this.bullet=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetMotionQuality(e.GetID(),this.bullet?Jolt.EMotionQuality_LinearCast:Jolt.EMotionQuality_Discrete)}hasFixedRotation(){return this.fixedRotation}setFixedRotation(t){this.fixedRotation!==t&&(this.fixedRotation=t,this._needToRecreateBody=!0)}getDensity(){return this.density}setDensity(t){t<0&&(t=0),this.density!==t&&(this.density=t,this._needToRecreateShape=!0)}getFriction(){return this.friction}setFriction(t){if(t<0&&(t=0),this.friction===t||(this.friction=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetFriction(e.GetID(),t)}getRestitution(){return this.restitution}setRestitution(t){if(t<0&&(t=0),this.restitution===t||(this.restitution=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetRestitution(e.GetID(),t)}getLinearDamping(){return this.linearDamping}setLinearDamping(t){if(t<0&&(t=0),this.linearDamping===t||(this.linearDamping=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetLinearDamping(t)}getAngularDamping(){return this.angularDamping}setAngularDamping(t){if(t<0&&(t=0),this.angularDamping===t||(this.angularDamping=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetAngularDamping(t)}getGravityScale(){return this.gravityScale}setGravityScale(t){if(this.gravityScale===t||(this.gravityScale=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetGravityFactor(t)}layerEnabled(t){return t=Math.floor(t),t<1||t>8?!1:!!(this.layers&1<<t-1)}enableLayer(t,e){t=Math.floor(t),!(t<1||t>8)&&(e?this.layers|=1<<t-1:this.layers&=~(1<<t-1),this._needToRecreateBody=!0)}maskEnabled(t){return t=Math.floor(t),t<1||t>16?!1:!!(this.masks&1<<t-1)}enableMask(t,e){t=Math.floor(t),!(t<1||t>16)&&(e?this.masks|=1<<t-1:this.masks&=~(1<<t-1),this._needToRecreateBody=!0)}getLinearVelocityX(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetX()*this._sharedData.worldScale}setLinearVelocityX(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(t*this._sharedData.worldInvScale,e.GetLinearVelocity().GetY(),e.GetLinearVelocity().GetZ()))}getLinearVelocityY(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetY()*this._sharedData.worldScale}setLinearVelocityY(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(e.GetLinearVelocity().GetX(),t*this._sharedData.worldInvScale,e.GetLinearVelocity().GetZ()))}getLinearVelocityZ(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetZ()*this._sharedData.worldScale}setLinearVelocityZ(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(e.GetLinearVelocity().GetX(),e.GetLinearVelocity().GetY(),t*this._sharedData.worldInvScale))}getLinearVelocityLength(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().Length()*this._sharedData.worldScale}getAngularVelocityX(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetX())}setAngularVelocityX(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(n.toRad(t),e.GetAngularVelocity().GetY(),e.GetAngularVelocity().GetZ()))}getAngularVelocityY(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetY())}setAngularVelocityY(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(e.GetAngularVelocity().GetX(),n.toRad(t),e.GetAngularVelocity().GetZ()))}getAngularVelocityZ(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetZ())}setAngularVelocityZ(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(e.GetAngularVelocity().GetX(),e.GetAngularVelocity().GetY(),n.toRad(t)))}applyForce(t,e,o,i,s,a){if(this._body===null&&!this._createBody())return;const r=this._body;this._sharedData.bodyInterface.AddForce(r.GetID(),this.getVec3(t,e,o),this.getRVec3(i*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale),Jolt.EActivation_Activate)}applyForceAtCenter(t,e,o){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddForce(i.GetID(),this.getVec3(t,e,o),Jolt.EActivation_Activate)}applyForceTowardPosition(t,e,o,i){if(this._body===null&&!this._createBody())return;const s=this._body,a=e-s.GetPosition().GetX(),r=o-s.GetPosition().GetY(),d=i-s.GetPosition().GetZ(),l=a*a+r*r+d*d;if(l===0)return;const h=t/l;this._sharedData.bodyInterface.AddForce(s.GetID(),this.getVec3(a*h,r*h,d*h),Jolt.EActivation_Activate)}applyImpulse(t,e,o,i,s,a){if(this._body===null&&!this._createBody())return;const r=this._body;this._sharedData.bodyInterface.AddImpulse(r.GetID(),this.getVec3(t,e,o),this.getRVec3(i*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale))}applyImpulseAtCenter(t,e,o){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddImpulse(i.GetID(),this.getVec3(t,e,o))}applyImpulseTowardPosition(t,e,o,i,s,a,r){if(this._body===null&&!this._createBody())return;const d=this._body,l=e-s,h=o-a,f=i-r,c=l*l+h*h+f*f;if(c===0)return;const y=t/c;this._sharedData.bodyInterface.AddImpulse(d.GetID(),this.getVec3(l*y,h*y,f*y),this.getRVec3(s*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale,r*this._sharedData.worldInvScale))}applyTorque(t,e,o){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddTorque(i.GetID(),this.getVec3(n.toRad(t),n.toRad(e),n.toRad(o)),Jolt.EActivation_Activate)}applyAngularImpulse(t,e,o){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddAngularImpulse(i.GetID(),this.getVec3(n.toRad(t),n.toRad(e),n.toRad(o)))}getMass(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseMass()}getInertiaAroundX(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetX()}getInertiaAroundY(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetY()}getInertiaAroundZ(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetZ()}getMassCenterX(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetX()*this._sharedData.worldScale}getMassCenterY(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetY()*this._sharedData.worldScale}getMassCenterZ(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetZ()*this._sharedData.worldScale}onContactBegin(t){this._currentContacts.push(t);let e=this._contactsEndedThisFrame.indexOf(t);e!==-1?this._contactsEndedThisFrame.splice(e,1):this._contactsStartedThisFrame.push(t)}onContactEnd(t){this._contactsEndedThisFrame.push(t);const e=this._currentContacts.indexOf(t);e!==-1&&this._currentContacts.splice(e,1)}static areObjectsColliding(t,e,o){const i=t.getBehavior(o);return i?i.collisionChecker.isColliding(e):!1}static hasCollisionStartedBetween(t,e,o){const i=t.getBehavior(o);return i?i.collisionChecker.hasCollisionStartedWith(e):!1}static hasCollisionStoppedBetween(t,e,o){const i=t.getBehavior(o);return i?i.collisionChecker.hasCollisionStoppedWith(e):!1}}n.Physics3DRuntimeBehavior=p,n.registerBehavior("Physics3D::Physics3DBehavior",n.Physics3DRuntimeBehavior),function(e){class u{constructor(i){this.behavior=i}createAndAddBody(){const{behavior:i}=this,{_sharedData:s}=i,a=i.createShape(),r=new Jolt.BodyCreationSettings(a,i.getPhysicsPosition(s.getRVec3(0,0,0)),i.getPhysicsRotation(s.getQuat(0,0,0,1)),i.bodyType==="Static"?Jolt.EMotionType_Static:i.bodyType==="Kinematic"?Jolt.EMotionType_Kinematic:Jolt.EMotionType_Dynamic,i.getBodyLayer());r.mMotionQuality=i.bullet?Jolt.EMotionQuality_LinearCast:Jolt.EMotionQuality_Discrete,r.mAllowedDOFs=i.fixedRotation?Jolt.EAllowedDOFs_TranslationX|Jolt.EAllowedDOFs_TranslationY|Jolt.EAllowedDOFs_TranslationZ:Jolt.EAllowedDOFs_All,r.mFriction=i.friction,r.mRestitution=i.restitution,r.mLinearDamping=i.linearDamping,r.mAngularDamping=i.angularDamping,r.mGravityFactor=i.gravityScale;const d=s.bodyInterface,l=d.CreateBody(r);return Jolt.destroy(r),d.AddBody(l.GetID(),Jolt.EActivation_Activate),l}updateObjectFromBody(){const{behavior:i}=this,{_body:s}=i;s!==null&&(i.moveObjectToPhysicsPosition(s.GetPosition()),i.moveObjectToPhysicsRotation(s.GetRotation()))}updateBodyFromObject(){const{behavior:i}=this,{owner3D:s,_sharedData:a}=i;if(i._body===null&&!i._createBody())return;const r=i._body;(this.behavior._objectOldX!==s.getX()||this.behavior._objectOldY!==s.getY()||this.behavior._objectOldZ!==s.getZ()||this.behavior._objectOldRotationX!==s.getRotationX()||this.behavior._objectOldRotationY!==s.getRotationY()||this.behavior._objectOldRotationZ!==s.getAngle())&&a.bodyInterface.SetPositionAndRotationWhenChanged(r.GetID(),this.behavior.getPhysicsPosition(a.getRVec3(0,0,0)),this.behavior.getPhysicsRotation(a.getQuat(0,0,0,1)),Jolt.EActivation_Activate)}recreateShape(){const{behavior:i}=this,{_sharedData:s}=i;if(i._body===null&&!i._createBody())return;const a=i._body;s.bodyInterface.SetShape(a.GetID(),i.createShape(),!0,Jolt.EActivation_Activate)}}e.DefaultBodyUpdater=u;class t{constructor(i){this.behavior=i}isColliding(i){return this.behavior._currentContacts.some(s=>s.owner===i)?!0:this.behavior._contactsStartedThisFrame.some(s=>s.owner===i)}hasCollisionStartedWith(i){return this.behavior._contactsStartedThisFrame.some(s=>s.owner===i)}hasCollisionStoppedWith(i){return this.behavior._contactsEndedThisFrame.some(s=>s.owner===i)}}e.DefaultCollisionChecker=t}(p=n.Physics3DRuntimeBehavior||(n.Physics3DRuntimeBehavior={}))})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=Physics3DRuntimeBehavior.js.map