@doodle-engine/core 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/core.cjs +2 -2
- package/dist/core.js +582 -536
- package/dist/effects/index.d.ts.map +1 -1
- package/dist/engine/index.d.ts +9 -0
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/parser/index.d.ts.map +1 -1
- package/dist/snapshot/index.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/effects.d.ts +10 -1
- package/dist/types/effects.d.ts.map +1 -1
- package/dist/types/entities.d.ts +28 -0
- package/dist/types/entities.d.ts.map +1 -1
- package/dist/types/registry.d.ts +3 -1
- package/dist/types/registry.d.ts.map +1 -1
- package/dist/types/snapshot.d.ts +25 -0
- package/dist/types/snapshot.d.ts.map +1 -1
- package/dist/types/state.d.ts +2 -0
- package/dist/types/state.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/core.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var V=Object.defineProperty;var k=(n,t,e)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var E=(n,t,e)=>k(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function w(n,t){switch(n.type){case"hasFlag":return R(n.flag,t);case"notFlag":return D(n.flag,t);case"hasItem":return P(n.itemId,t);case"variableEquals":return $(n.variable,n.value,t);case"variableGreaterThan":return q(n.variable,n.value,t);case"variableLessThan":return F(n.variable,n.value,t);case"atLocation":return W(n.locationId,t);case"questAtStage":return M(n.questId,n.stageId,t);case"characterAt":return G(n.characterId,n.locationId,t);case"characterInParty":return H(n.characterId,t);case"relationshipAbove":return j(n.characterId,n.value,t);case"relationshipBelow":return Q(n.characterId,n.value,t);case"timeIs":return J(n.startHour,n.endHour,t);case"itemAt":return U(n.itemId,n.locationId,t);default:return!1}}function S(n,t){return n.every(e=>w(e,t))}function R(n,t){return t.flags[n]===!0}function D(n,t){return t.flags[n]!==!0}function P(n,t){return t.inventory.includes(n)}function $(n,t,e){return e.variables[n]===t}function q(n,t,e){const r=e.variables[n];return typeof r=="number"&&r>t}function F(n,t,e){const r=e.variables[n];return typeof r=="number"&&r<t}function W(n,t){return t.currentLocation===n}function M(n,t,e){return e.questProgress[n]===t}function G(n,t,e){const r=e.characterState[n];return(r==null?void 0:r.location)===t}function H(n,t){const e=t.characterState[n];return(e==null?void 0:e.inParty)===!0}function j(n,t,e){const r=e.characterState[n];return r!==void 0&&r.relationship>t}function Q(n,t,e){const r=e.characterState[n];return r!==void 0&&r.relationship<t}function J(n,t,e){const r=e.currentTime.hour;return n<t?r>=n&&r<t:r>=n||r<t}function U(n,t,e){return e.itemLocations[n]===t}function C(n,t){switch(n.type){case"setFlag":return B(n.flag,t);case"clearFlag":return _(n.flag,t);case"setVariable":return z(n.variable,n.value,t);case"addVariable":return Y(n.variable,n.value,t);case"addItem":return K(n.itemId,t);case"removeItem":return X(n.itemId,t);case"moveItem":return Z(n.itemId,n.locationId,t);case"goToLocation":return tt(n.locationId,t);case"advanceTime":return et(n.hours,t);case"setQuestStage":return nt(n.questId,n.stageId,t);case"addJournalEntry":return rt(n.entryId,t);case"startDialogue":return at(n.dialogueId,t);case"endDialogue":return it(t);case"setCharacterLocation":return ot(n.characterId,n.locationId,t);case"addToParty":return st(n.characterId,t);case"removeFromParty":return lt(n.characterId,t);case"setRelationship":return ct(n.characterId,n.value,t);case"addRelationship":return ut(n.characterId,n.value,t);case"setCharacterStat":return dt(n.characterId,n.stat,n.value,t);case"addCharacterStat":return ht(n.characterId,n.stat,n.value,t);case"setMapEnabled":return pt(n.enabled,t);case"playMusic":return t;case"playSound":return ft(n.sound,t);case"notify":return gt(n.message,t);case"playVideo":return mt(n.file,t);default:return t}}function y(n,t){return n.reduce((e,r)=>C(r,e),t)}function B(n,t){return{...t,flags:{...t.flags,[n]:!0}}}function _(n,t){return{...t,flags:{...t.flags,[n]:!1}}}function z(n,t,e){return{...e,variables:{...e.variables,[n]:t}}}function Y(n,t,e){const r=e.variables[n],a=typeof r=="number"?r+t:t;return{...e,variables:{...e.variables,[n]:a}}}function K(n,t){return t.inventory.includes(n)?t:{...t,inventory:[...t.inventory,n],itemLocations:{...t.itemLocations,[n]:"inventory"}}}function X(n,t){return{...t,inventory:t.inventory.filter(e=>e!==n)}}function Z(n,t,e){return{...e,inventory:e.inventory.filter(r=>r!==n),itemLocations:{...e.itemLocations,[n]:t}}}function tt(n,t){return{...t,currentLocation:n}}function et(n,t){const e=t.currentTime.hour+n,r=Math.floor(e/24),a=e%24;return{...t,currentTime:{day:t.currentTime.day+r,hour:a}}}function nt(n,t,e){return{...e,questProgress:{...e.questProgress,[n]:t}}}function rt(n,t){return t.unlockedJournalEntries.includes(n)?t:{...t,unlockedJournalEntries:[...t.unlockedJournalEntries,n]}}function at(n,t){return{...t,dialogueState:{dialogueId:n,nodeId:""}}}function it(n){return{...n,dialogueState:null}}function ot(n,t,e){const r=e.characterState[n];return r?{...e,characterState:{...e.characterState,[n]:{...r,location:t}}}:e}function st(n,t){const e=t.characterState[n];return e?{...t,characterState:{...t.characterState,[n]:{...e,inParty:!0}}}:t}function lt(n,t){const e=t.characterState[n];return e?{...t,characterState:{...t.characterState,[n]:{...e,inParty:!1}}}:t}function ct(n,t,e){const r=e.characterState[n];return r?{...e,characterState:{...e.characterState,[n]:{...r,relationship:t}}}:e}function ut(n,t,e){const r=e.characterState[n];return r?{...e,characterState:{...e.characterState,[n]:{...r,relationship:r.relationship+t}}}:e}function dt(n,t,e,r){const a=r.characterState[n];return a?{...r,characterState:{...r.characterState,[n]:{...a,stats:{...a.stats,[t]:e}}}}:r}function ht(n,t,e,r){const a=r.characterState[n];if(!a)return r;const o=a.stats[t],i=typeof o=="number"?o+e:e;return{...r,characterState:{...r.characterState,[n]:{...a,stats:{...a.stats,[t]:i}}}}}function pt(n,t){return{...t,mapEnabled:n}}function gt(n,t){return{...t,notifications:[...t.notifications,n]}}function ft(n,t){return{...t,pendingSounds:[...t.pendingSounds,n]}}function mt(n,t){return{...t,pendingVideo:n}}function N(n,t){if(!n.startsWith("@"))return n;const e=n.slice(1);return t[e]??n}function bt(n){return t=>N(t,n)}function L(n,t){const e=t.locales[n.currentLocale]??{},r=O=>N(O,e),a=yt(n.currentLocation,t,r),o=St(n,t,r),i=vt(n,t,r),{dialogue:s,choices:l}=It(n,t,r),c=Tt(n,t,r),d=Et(n,t,r),f=Nt(n,t,r),m=At(n,t,r),u=n.mapEnabled?wt(n,t,r):null,g=t.locations[n.currentLocation],h=(g==null?void 0:g.music)??"",p=(g==null?void 0:g.ambient)??"",b=n.notifications.map(r),T=[...n.pendingSounds],x=n.pendingVideo;return{location:a,charactersHere:o,itemsHere:i,choices:l,dialogue:s,party:c,inventory:d,quests:f,journal:m,variables:{...n.variables},time:n.currentTime,map:u,music:h,ambient:p,notifications:b,pendingSounds:T,pendingVideo:x}}function yt(n,t,e){const r=t.locations[n];return r?{id:r.id,name:e(r.name),description:e(r.description),banner:r.banner}:{id:n,name:n,description:`Location not found: ${n}`,banner:""}}function St(n,t,e){const r=[];for(const[a,o]of Object.entries(n.characterState))if(o.location===n.currentLocation){const i=t.characters[a];i&&r.push({id:i.id,name:e(i.name),biography:e(i.biography),portrait:i.portrait,location:o.location,inParty:o.inParty,relationship:o.relationship,stats:o.stats})}return r}function vt(n,t,e){const r=[];for(const[a,o]of Object.entries(n.itemLocations))if(o===n.currentLocation){const i=t.items[a];i&&r.push({id:i.id,name:e(i.name),description:e(i.description),icon:i.icon,image:i.image,stats:i.stats})}return r}function It(n,t,e){var l,c;if(!n.dialogueState)return{dialogue:null,choices:[]};const r=t.dialogues[n.dialogueState.dialogueId];if(!r)return{dialogue:null,choices:[]};const a=r.nodes.find(d=>{var f;return d.id===((f=n.dialogueState)==null?void 0:f.nodeId)});if(!a)return{dialogue:null,choices:[]};const o=a.speaker?e(((l=t.characters[a.speaker])==null?void 0:l.name)??a.speaker):"Narrator",i={speaker:a.speaker,speakerName:o,text:e(a.text),portrait:a.portrait??((c=t.characters[a.speaker??""])==null?void 0:c.portrait),voice:a.voice},s=a.choices.filter(d=>!d.conditions||d.conditions.length===0?!0:S(d.conditions,n)).map(d=>({id:d.id,text:e(d.text)}));return{dialogue:i,choices:s}}function Tt(n,t,e){const r=[];for(const[a,o]of Object.entries(n.characterState))if(o.inParty){const i=t.characters[a];i&&r.push({id:i.id,name:e(i.name),biography:e(i.biography),portrait:i.portrait,location:o.location,inParty:o.inParty,relationship:o.relationship,stats:o.stats})}return r}function Et(n,t,e){return n.inventory.map(r=>{const a=t.items[r];return a?{id:a.id,name:e(a.name),description:e(a.description),icon:a.icon,image:a.image,stats:a.stats}:null}).filter(r=>r!==null)}function Nt(n,t,e){const r=[];for(const[a,o]of Object.entries(n.questProgress)){const i=t.quests[a];if(!i)continue;const s=i.stages.find(l=>l.id===o);s&&r.push({id:i.id,name:e(i.name),description:e(i.description),currentStage:s.id,currentStageDescription:e(s.description)})}return r}function At(n,t,e){return n.unlockedJournalEntries.map(r=>{const a=t.journalEntries[r];return a?{id:a.id,title:e(a.title),text:e(a.text),category:a.category}:null}).filter(r=>r!==null)}function wt(n,t,e){const r=Object.keys(t.maps);if(r.length===0)return null;const a=t.maps[r[0]];if(!a)return null;const o=a.locations.map(i=>{const s=t.locations[i.id];return{id:i.id,name:s?e(s.name):i.id,x:i.x,y:i.y,isCurrent:i.id===n.currentLocation}});return{id:a.id,name:e(a.name),image:a.image,scale:a.scale,locations:o}}class Ct{constructor(t,e){E(this,"registry");E(this,"state");this.registry=t,this.state=e}newGame(t){const e={};for(const[a,o]of Object.entries(this.registry.characters))e[a]={location:o.location,inParty:!1,relationship:0,stats:{...o.stats}};const r={};for(const[a,o]of Object.entries(this.registry.items))r[a]=o.location;return this.state={currentLocation:t.startLocation,currentTime:{...t.startTime},flags:{...t.startFlags},variables:{...t.startVariables},inventory:[...t.startInventory],questProgress:{},unlockedJournalEntries:[],playerNotes:[],dialogueState:null,characterState:e,itemLocations:r,mapEnabled:!0,notifications:[],pendingSounds:[],pendingVideo:null,currentLocale:"en"},this.checkTriggeredDialogues(),this.buildSnapshotAndClearTransients()}loadGame(t){return this.state={...t.state},this.buildSnapshotAndClearTransients()}saveGame(){return{version:"1.0",timestamp:new Date().toISOString(),state:{...this.state}}}selectChoice(t){if(!this.state.dialogueState)return this.buildSnapshotAndClearTransients();const e=this.registry.dialogues[this.state.dialogueState.dialogueId];if(!e)return this.buildSnapshotAndClearTransients();const r=e.nodes.find(i=>{var s;return i.id===((s=this.state.dialogueState)==null?void 0:s.nodeId)});if(!r)return this.buildSnapshotAndClearTransients();const a=r.choices.find(i=>i.id===t);if(!a)return this.buildSnapshotAndClearTransients();a.effects&&(this.state=y(a.effects,this.state));const o=e.nodes.find(i=>i.id===a.next);if(!o)return this.state={...this.state,dialogueState:null},this.buildSnapshotAndClearTransients();if(this.state={...this.state,dialogueState:{dialogueId:e.id,nodeId:o.id}},o.effects&&(this.state=y(o.effects,this.state)),o.choices.length===0){const i=this.resolveNextNode(o);i?this.state={...this.state,dialogueState:{dialogueId:e.id,nodeId:i}}:this.state={...this.state,dialogueState:null}}return this.buildSnapshotAndClearTransients()}talkTo(t){const e=this.registry.characters[t];if(!e||!e.dialogue)return this.buildSnapshotAndClearTransients();const r=this.registry.dialogues[e.dialogue];if(!r)return this.buildSnapshotAndClearTransients();const a=r.nodes.find(o=>o.id===r.startNode);if(!a)return this.buildSnapshotAndClearTransients();if(this.state={...this.state,dialogueState:{dialogueId:r.id,nodeId:a.id}},a.effects&&(this.state=y(a.effects,this.state)),a.choices.length===0){const o=this.resolveNextNode(a);o?this.state={...this.state,dialogueState:{dialogueId:r.id,nodeId:o}}:this.state={...this.state,dialogueState:null}}return this.buildSnapshotAndClearTransients()}takeItem(t){return this.state.itemLocations[t]!==this.state.currentLocation?this.buildSnapshotAndClearTransients():(this.state={...this.state,inventory:[...this.state.inventory,t],itemLocations:{...this.state.itemLocations,[t]:"inventory"}},this.buildSnapshotAndClearTransients())}travelTo(t){if(!this.state.mapEnabled)return this.buildSnapshotAndClearTransients();const e=Object.keys(this.registry.maps);if(e.length===0)return this.buildSnapshotAndClearTransients();const r=this.registry.maps[e[0]];if(!r)return this.buildSnapshotAndClearTransients();const a=r.locations.find(f=>f.id===this.state.currentLocation),o=r.locations.find(f=>f.id===t);if(!a||!o)return this.buildSnapshotAndClearTransients();const i=Math.sqrt(Math.pow(o.x-a.x,2)+Math.pow(o.y-a.y,2)),s=Math.round(i*r.scale),l=this.state.currentTime.hour+s,c=Math.floor(l/24),d=l%24;return this.state={...this.state,currentLocation:t,dialogueState:null,currentTime:{day:this.state.currentTime.day+c,hour:d}},this.checkTriggeredDialogues(),this.buildSnapshotAndClearTransients()}writeNote(t,e){const r={id:`note_${Date.now()}`,title:t,text:e};return this.state={...this.state,playerNotes:[...this.state.playerNotes,r]},this.buildSnapshotAndClearTransients()}deleteNote(t){return this.state={...this.state,playerNotes:this.state.playerNotes.filter(e=>e.id!==t)},this.buildSnapshotAndClearTransients()}setLocale(t){return this.state={...this.state,currentLocale:t},this.buildSnapshotAndClearTransients()}getSnapshot(){return this.buildSnapshotAndClearTransients()}buildSnapshotAndClearTransients(){const t=L(this.state,this.registry);return this.state={...this.state,notifications:[],pendingSounds:[],pendingVideo:null},t}resolveNextNode(t){if(t.conditionalNext&&t.conditionalNext.length>0){for(const e of t.conditionalNext)if(S([e.condition],this.state))return e.next}return t.next??null}checkTriggeredDialogues(){for(const t of Object.values(this.registry.dialogues)){if(t.triggerLocation!==this.state.currentLocation||t.conditions&&!S(t.conditions,this.state))continue;const e=t.nodes.find(r=>r.id===t.startNode);if(e){if(this.state={...this.state,dialogueState:{dialogueId:t.id,nodeId:e.id}},e.effects&&(this.state=y(e.effects,this.state)),e.choices.length===0){const r=this.resolveNextNode(e);r?this.state={...this.state,dialogueState:{dialogueId:t.id,nodeId:r}}:this.state={...this.state,dialogueState:null}}break}}}}function Lt(n){return n.split(`
|
|
2
|
-
`).map((
|
|
1
|
+
"use strict";var V=Object.defineProperty;var R=(t,e,n)=>e in t?V(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var N=(t,e,n)=>R(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function L(t,e){switch(t.type){case"hasFlag":return D(t.flag,e);case"notFlag":return P(t.flag,e);case"hasItem":return $(t.itemId,e);case"variableEquals":return q(t.variable,t.value,e);case"variableGreaterThan":return F(t.variable,t.value,e);case"variableLessThan":return W(t.variable,t.value,e);case"atLocation":return M(t.locationId,e);case"questAtStage":return G(t.questId,t.stageId,e);case"characterAt":return j(t.characterId,t.locationId,e);case"characterInParty":return H(t.characterId,e);case"relationshipAbove":return Q(t.characterId,t.value,e);case"relationshipBelow":return J(t.characterId,t.value,e);case"timeIs":return U(t.startHour,t.endHour,e);case"itemAt":return B(t.itemId,t.locationId,e);default:return!1}}function v(t,e){return t.every(n=>L(n,e))}function D(t,e){return e.flags[t]===!0}function P(t,e){return e.flags[t]!==!0}function $(t,e){return e.inventory.includes(t)}function q(t,e,n){return n.variables[t]===e}function F(t,e,n){const r=n.variables[t];return typeof r=="number"&&r>e}function W(t,e,n){const r=n.variables[t];return typeof r=="number"&&r<e}function M(t,e){return e.currentLocation===t}function G(t,e,n){return n.questProgress[t]===e}function j(t,e,n){const r=n.characterState[t];return(r==null?void 0:r.location)===e}function H(t,e){const n=e.characterState[t];return(n==null?void 0:n.inParty)===!0}function Q(t,e,n){const r=n.characterState[t];return r!==void 0&&r.relationship>e}function J(t,e,n){const r=n.characterState[t];return r!==void 0&&r.relationship<e}function U(t,e,n){const r=n.currentTime.hour;return t<e?r>=t&&r<e:r>=t||r<e}function B(t,e,n){return n.itemLocations[t]===e}function x(t,e){switch(t.type){case"setFlag":return _(t.flag,e);case"clearFlag":return z(t.flag,e);case"setVariable":return Y(t.variable,t.value,e);case"addVariable":return K(t.variable,t.value,e);case"addItem":return X(t.itemId,e);case"removeItem":return Z(t.itemId,e);case"moveItem":return ee(t.itemId,t.locationId,e);case"goToLocation":return te(t.locationId,e);case"advanceTime":return ne(t.hours,e);case"setQuestStage":return re(t.questId,t.stageId,e);case"addJournalEntry":return ae(t.entryId,e);case"startDialogue":return ie(t.dialogueId,e);case"endDialogue":return se(e);case"setCharacterLocation":return oe(t.characterId,t.locationId,e);case"addToParty":return le(t.characterId,e);case"removeFromParty":return ce(t.characterId,e);case"setRelationship":return ue(t.characterId,t.value,e);case"addRelationship":return de(t.characterId,t.value,e);case"setCharacterStat":return he(t.characterId,t.stat,t.value,e);case"addCharacterStat":return pe(t.characterId,t.stat,t.value,e);case"setMapEnabled":return ge(t.enabled,e);case"playMusic":return e;case"playSound":return me(t.sound,e);case"notify":return fe(t.message,e);case"playVideo":return be(t.file,e);case"showInterlude":return ye(t.interludeId,e);default:return e}}function S(t,e){return t.reduce((n,r)=>x(r,n),e)}function _(t,e){return{...e,flags:{...e.flags,[t]:!0}}}function z(t,e){return{...e,flags:{...e.flags,[t]:!1}}}function Y(t,e,n){return{...n,variables:{...n.variables,[t]:e}}}function K(t,e,n){const r=n.variables[t],a=typeof r=="number"?r+e:e;return{...n,variables:{...n.variables,[t]:a}}}function X(t,e){return e.inventory.includes(t)?e:{...e,inventory:[...e.inventory,t],itemLocations:{...e.itemLocations,[t]:"inventory"}}}function Z(t,e){return{...e,inventory:e.inventory.filter(n=>n!==t)}}function ee(t,e,n){return{...n,inventory:n.inventory.filter(r=>r!==t),itemLocations:{...n.itemLocations,[t]:e}}}function te(t,e){return{...e,currentLocation:t}}function ne(t,e){const n=e.currentTime.hour+t,r=Math.floor(n/24),a=n%24;return{...e,currentTime:{day:e.currentTime.day+r,hour:a}}}function re(t,e,n){return{...n,questProgress:{...n.questProgress,[t]:e}}}function ae(t,e){return e.unlockedJournalEntries.includes(t)?e:{...e,unlockedJournalEntries:[...e.unlockedJournalEntries,t]}}function ie(t,e){return{...e,dialogueState:{dialogueId:t,nodeId:""}}}function se(t){return{...t,dialogueState:null}}function oe(t,e,n){const r=n.characterState[t];return r?{...n,characterState:{...n.characterState,[t]:{...r,location:e}}}:n}function le(t,e){const n=e.characterState[t];return n?{...e,characterState:{...e.characterState,[t]:{...n,inParty:!0}}}:e}function ce(t,e){const n=e.characterState[t];return n?{...e,characterState:{...e.characterState,[t]:{...n,inParty:!1}}}:e}function ue(t,e,n){const r=n.characterState[t];return r?{...n,characterState:{...n.characterState,[t]:{...r,relationship:e}}}:n}function de(t,e,n){const r=n.characterState[t];return r?{...n,characterState:{...n.characterState,[t]:{...r,relationship:r.relationship+e}}}:n}function he(t,e,n,r){const a=r.characterState[t];return a?{...r,characterState:{...r.characterState,[t]:{...a,stats:{...a.stats,[e]:n}}}}:r}function pe(t,e,n,r){const a=r.characterState[t];if(!a)return r;const s=a.stats[e],i=typeof s=="number"?s+n:n;return{...r,characterState:{...r.characterState,[t]:{...a,stats:{...a.stats,[e]:i}}}}}function ge(t,e){return{...e,mapEnabled:t}}function fe(t,e){return{...e,notifications:[...e.notifications,t]}}function me(t,e){return{...e,pendingSounds:[...e.pendingSounds,t]}}function be(t,e){return{...e,pendingVideo:t}}function ye(t,e){return{...e,pendingInterlude:t}}function A(t,e){if(!t.startsWith("@"))return t;const n=t.slice(1);return e[n]??t}function Se(t){return e=>A(e,t)}function k(t,e){const n=e.locales[t.currentLocale]??{},r=m=>A(m,n),a=ve(t.currentLocation,e,r),s=Ie(t,e,r),i=Te(t,e,r),{dialogue:o,choices:l}=Ee(t,e,r),c=Ne(t,e,r),d=Ae(t,e,r),f=we(t,e,r),b=Ce(t,e,r),u=t.mapEnabled?Le(t,e,r):null,g=e.locations[t.currentLocation],h=(g==null?void 0:g.music)??"",p=(g==null?void 0:g.ambient)??"",y=t.notifications.map(r),E=[...t.pendingSounds],O=t.pendingVideo;let C=null;if(t.pendingInterlude){const m=e.interludes[t.pendingInterlude];m&&(C={id:m.id,background:m.background,banner:m.banner,music:m.music,voice:m.voice,sounds:m.sounds,scroll:m.scroll??!0,scrollSpeed:m.scrollSpeed??30,text:r(m.text)})}return{location:a,charactersHere:s,itemsHere:i,choices:l,dialogue:o,party:c,inventory:d,quests:f,journal:b,variables:{...t.variables},time:t.currentTime,map:u,music:h,ambient:p,notifications:y,pendingSounds:E,pendingVideo:O,pendingInterlude:C}}function ve(t,e,n){const r=e.locations[t];return r?{id:r.id,name:n(r.name),description:n(r.description),banner:r.banner}:{id:t,name:t,description:`Location not found: ${t}`,banner:""}}function Ie(t,e,n){const r=[];for(const[a,s]of Object.entries(t.characterState))if(s.location===t.currentLocation){const i=e.characters[a];i&&r.push({id:i.id,name:n(i.name),biography:n(i.biography),portrait:i.portrait,location:s.location,inParty:s.inParty,relationship:s.relationship,stats:s.stats})}return r}function Te(t,e,n){const r=[];for(const[a,s]of Object.entries(t.itemLocations))if(s===t.currentLocation){const i=e.items[a];i&&r.push({id:i.id,name:n(i.name),description:n(i.description),icon:i.icon,image:i.image,stats:i.stats})}return r}function Ee(t,e,n){var l,c;if(!t.dialogueState)return{dialogue:null,choices:[]};const r=e.dialogues[t.dialogueState.dialogueId];if(!r)return{dialogue:null,choices:[]};const a=r.nodes.find(d=>{var f;return d.id===((f=t.dialogueState)==null?void 0:f.nodeId)});if(!a)return{dialogue:null,choices:[]};const s=a.speaker?n(((l=e.characters[a.speaker])==null?void 0:l.name)??a.speaker):"Narrator",i={speaker:a.speaker,speakerName:s,text:n(a.text),portrait:a.portrait??((c=e.characters[a.speaker??""])==null?void 0:c.portrait),voice:a.voice},o=a.choices.filter(d=>!d.conditions||d.conditions.length===0?!0:v(d.conditions,t)).map(d=>({id:d.id,text:n(d.text)}));return{dialogue:i,choices:o}}function Ne(t,e,n){const r=[];for(const[a,s]of Object.entries(t.characterState))if(s.inParty){const i=e.characters[a];i&&r.push({id:i.id,name:n(i.name),biography:n(i.biography),portrait:i.portrait,location:s.location,inParty:s.inParty,relationship:s.relationship,stats:s.stats})}return r}function Ae(t,e,n){return t.inventory.map(r=>{const a=e.items[r];return a?{id:a.id,name:n(a.name),description:n(a.description),icon:a.icon,image:a.image,stats:a.stats}:null}).filter(r=>r!==null)}function we(t,e,n){const r=[];for(const[a,s]of Object.entries(t.questProgress)){const i=e.quests[a];if(!i)continue;const o=i.stages.find(l=>l.id===s);o&&r.push({id:i.id,name:n(i.name),description:n(i.description),currentStage:o.id,currentStageDescription:n(o.description)})}return r}function Ce(t,e,n){return t.unlockedJournalEntries.map(r=>{const a=e.journalEntries[r];return a?{id:a.id,title:n(a.title),text:n(a.text),category:a.category}:null}).filter(r=>r!==null)}function Le(t,e,n){const r=Object.keys(e.maps);if(r.length===0)return null;const a=e.maps[r[0]];if(!a)return null;const s=a.locations.map(i=>{const o=e.locations[i.id];return{id:i.id,name:o?n(o.name):i.id,x:i.x,y:i.y,isCurrent:i.id===t.currentLocation}});return{id:a.id,name:n(a.name),image:a.image,scale:a.scale,locations:s}}class xe{constructor(e,n){N(this,"registry");N(this,"state");this.registry=e,this.state=n}newGame(e){const n={};for(const[a,s]of Object.entries(this.registry.characters))n[a]={location:s.location,inParty:!1,relationship:0,stats:{...s.stats}};const r={};for(const[a,s]of Object.entries(this.registry.items))r[a]=s.location;return this.state={currentLocation:e.startLocation,currentTime:{...e.startTime},flags:{...e.startFlags},variables:{...e.startVariables},inventory:[...e.startInventory],questProgress:{},unlockedJournalEntries:[],playerNotes:[],dialogueState:null,characterState:n,itemLocations:r,mapEnabled:!0,notifications:[],pendingSounds:[],pendingVideo:null,pendingInterlude:null,currentLocale:"en"},this.checkTriggeredDialogues(),this.checkTriggeredInterludes(),this.buildSnapshotAndClearTransients()}loadGame(e){return this.state={...e.state},this.buildSnapshotAndClearTransients()}saveGame(){return{version:"1.0",timestamp:new Date().toISOString(),state:{...this.state}}}selectChoice(e){if(!this.state.dialogueState)return this.buildSnapshotAndClearTransients();const n=this.registry.dialogues[this.state.dialogueState.dialogueId];if(!n)return this.buildSnapshotAndClearTransients();const r=n.nodes.find(i=>{var o;return i.id===((o=this.state.dialogueState)==null?void 0:o.nodeId)});if(!r)return this.buildSnapshotAndClearTransients();const a=r.choices.find(i=>i.id===e);if(!a)return this.buildSnapshotAndClearTransients();a.effects&&(this.state=S(a.effects,this.state));const s=n.nodes.find(i=>i.id===a.next);if(!s)return this.state={...this.state,dialogueState:null},this.buildSnapshotAndClearTransients();if(this.state={...this.state,dialogueState:{dialogueId:n.id,nodeId:s.id}},s.effects&&(this.state=S(s.effects,this.state)),s.choices.length===0){const i=this.resolveNextNode(s);i?this.state={...this.state,dialogueState:{dialogueId:n.id,nodeId:i}}:this.state={...this.state,dialogueState:null}}return this.buildSnapshotAndClearTransients()}talkTo(e){const n=this.registry.characters[e];if(!n||!n.dialogue)return this.buildSnapshotAndClearTransients();const r=this.registry.dialogues[n.dialogue];if(!r)return this.buildSnapshotAndClearTransients();const a=r.nodes.find(s=>s.id===r.startNode);if(!a)return this.buildSnapshotAndClearTransients();if(this.state={...this.state,dialogueState:{dialogueId:r.id,nodeId:a.id}},a.effects&&(this.state=S(a.effects,this.state)),a.choices.length===0){const s=this.resolveNextNode(a);s?this.state={...this.state,dialogueState:{dialogueId:r.id,nodeId:s}}:this.state={...this.state,dialogueState:null}}return this.buildSnapshotAndClearTransients()}takeItem(e){return this.state.itemLocations[e]!==this.state.currentLocation?this.buildSnapshotAndClearTransients():(this.state={...this.state,inventory:[...this.state.inventory,e],itemLocations:{...this.state.itemLocations,[e]:"inventory"}},this.buildSnapshotAndClearTransients())}travelTo(e){if(!this.state.mapEnabled)return this.buildSnapshotAndClearTransients();const n=Object.keys(this.registry.maps);if(n.length===0)return this.buildSnapshotAndClearTransients();const r=this.registry.maps[n[0]];if(!r)return this.buildSnapshotAndClearTransients();const a=r.locations.find(f=>f.id===this.state.currentLocation),s=r.locations.find(f=>f.id===e);if(!a||!s)return this.buildSnapshotAndClearTransients();const i=Math.sqrt(Math.pow(s.x-a.x,2)+Math.pow(s.y-a.y,2)),o=Math.round(i*r.scale),l=this.state.currentTime.hour+o,c=Math.floor(l/24),d=l%24;return this.state={...this.state,currentLocation:e,dialogueState:null,currentTime:{day:this.state.currentTime.day+c,hour:d}},this.checkTriggeredDialogues(),this.checkTriggeredInterludes(),this.buildSnapshotAndClearTransients()}writeNote(e,n){const r={id:`note_${Date.now()}`,title:e,text:n};return this.state={...this.state,playerNotes:[...this.state.playerNotes,r]},this.buildSnapshotAndClearTransients()}deleteNote(e){return this.state={...this.state,playerNotes:this.state.playerNotes.filter(n=>n.id!==e)},this.buildSnapshotAndClearTransients()}setLocale(e){return this.state={...this.state,currentLocale:e},this.buildSnapshotAndClearTransients()}getSnapshot(){return this.buildSnapshotAndClearTransients()}buildSnapshotAndClearTransients(){const e=k(this.state,this.registry);return this.state={...this.state,notifications:[],pendingSounds:[],pendingVideo:null,pendingInterlude:null},e}resolveNextNode(e){if(e.conditionalNext&&e.conditionalNext.length>0){for(const n of e.conditionalNext)if(v([n.condition],this.state))return n.next}return e.next??null}checkTriggeredDialogues(){for(const e of Object.values(this.registry.dialogues)){if(e.triggerLocation!==this.state.currentLocation||e.conditions&&!v(e.conditions,this.state))continue;const n=e.nodes.find(r=>r.id===e.startNode);if(n){if(this.state={...this.state,dialogueState:{dialogueId:e.id,nodeId:n.id}},n.effects&&(this.state=S(n.effects,this.state)),n.choices.length===0){const r=this.resolveNextNode(n);r?this.state={...this.state,dialogueState:{dialogueId:e.id,nodeId:r}}:this.state={...this.state,dialogueState:null}}break}}}checkTriggeredInterludes(){for(const e of Object.values(this.registry.interludes))if(e.triggerLocation===this.state.currentLocation&&!(e.triggerConditions&&!v(e.triggerConditions,this.state))){this.state={...this.state,pendingInterlude:e.id};break}}}function ke(t){return t.split(`
|
|
2
|
+
`).map((e,n)=>({original:e,lineNumber:n+1})).map(({original:e,lineNumber:n})=>{let r=e;const a=e.indexOf("#");if(a===-1)r=e;else{const o=e.match(/"[^"]*"/);if(o){const l=e.indexOf(o[0]),c=l+o[0].length;a<l?r=e.substring(0,a):a>=l&&a<c?r=e.substring(0,c)+e.substring(c).split("#")[0]:r=e.substring(0,a)}else r=e.substring(0,a)}const s=r.length-r.trimStart().length;return{line:r.trim(),lineNumber:n,indent:s}}).filter(e=>e.line.length>0)}function w(t){const e=t.trim();return e.startsWith("@")?e:e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):e}function I(t){const e=t.trim().split(/\s+/),n=e[0];switch(n){case"hasFlag":return{type:"hasFlag",flag:e[1]};case"notFlag":return{type:"notFlag",flag:e[1]};case"hasItem":return{type:"hasItem",itemId:e[1]};case"variableEquals":return{type:"variableEquals",variable:e[1],value:isNaN(Number(e[2]))?e[2]:Number(e[2])};case"variableGreaterThan":return{type:"variableGreaterThan",variable:e[1],value:Number(e[2])};case"variableLessThan":return{type:"variableLessThan",variable:e[1],value:Number(e[2])};case"atLocation":return{type:"atLocation",locationId:e[1]};case"questAtStage":return{type:"questAtStage",questId:e[1],stageId:e[2]};case"characterAt":return{type:"characterAt",characterId:e[1],locationId:e[2]};case"characterInParty":return{type:"characterInParty",characterId:e[1]};case"relationshipAbove":return{type:"relationshipAbove",characterId:e[1],value:Number(e[2])};case"relationshipBelow":return{type:"relationshipBelow",characterId:e[1],value:Number(e[2])};case"timeIs":return{type:"timeIs",startHour:Number(e[1]),endHour:Number(e[2])};case"itemAt":return{type:"itemAt",itemId:e[1],locationId:e[2]};default:throw new Error(`Unknown condition type: ${n}`)}}function T(t){const e=t.trim();if(e.startsWith("NOTIFY "))return{type:"notify",message:w(e.substring(7))};if(e.startsWith("MUSIC "))return{type:"playMusic",track:e.substring(6).trim()};if(e.startsWith("SOUND "))return{type:"playSound",sound:e.substring(6).trim()};if(e.startsWith("VIDEO "))return{type:"playVideo",file:e.substring(6).trim()};if(e.startsWith("INTERLUDE "))return{type:"showInterlude",interludeId:e.substring(10).trim()};const n=e.split(/\s+/),r=n[0];switch(r){case"SET":if(n[1]==="flag")return{type:"setFlag",flag:n[2]};if(n[1]==="variable")return{type:"setVariable",variable:n[2],value:isNaN(Number(n[3]))?n[3]:Number(n[3])};if(n[1]==="questStage")return{type:"setQuestStage",questId:n[2],stageId:n[3]};if(n[1]==="characterLocation")return{type:"setCharacterLocation",characterId:n[2],locationId:n[3]};if(n[1]==="relationship")return{type:"setRelationship",characterId:n[2],value:Number(n[3])};if(n[1]==="characterStat")return{type:"setCharacterStat",characterId:n[2],stat:n[3],value:isNaN(Number(n[4]))?n[4]:Number(n[4])};if(n[1]==="mapEnabled")return{type:"setMapEnabled",enabled:n[2]==="true"};throw new Error(`Unknown SET effect: ${n[1]}`);case"CLEAR":if(n[1]==="flag")return{type:"clearFlag",flag:n[2]};throw new Error(`Unknown CLEAR effect: ${n[1]}`);case"ADD":if(n[1]==="variable")return{type:"addVariable",variable:n[2],value:Number(n[3])};if(n[1]==="item")return{type:"addItem",itemId:n[2]};if(n[1]==="journalEntry")return{type:"addJournalEntry",entryId:n[2]};if(n[1]==="toParty")return{type:"addToParty",characterId:n[2]};if(n[1]==="relationship")return{type:"addRelationship",characterId:n[2],value:Number(n[3])};if(n[1]==="characterStat")return{type:"addCharacterStat",characterId:n[2],stat:n[3],value:Number(n[4])};throw new Error(`Unknown ADD effect: ${n[1]}`);case"REMOVE":if(n[1]==="item")return{type:"removeItem",itemId:n[2]};if(n[1]==="fromParty")return{type:"removeFromParty",characterId:n[2]};throw new Error(`Unknown REMOVE effect: ${n[1]}`);case"MOVE":if(n[1]==="item")return{type:"moveItem",itemId:n[2],locationId:n[3]};throw new Error(`Unknown MOVE effect: ${n[1]}`);case"GOTO":if(n[1]==="location")return{type:"goToLocation",locationId:n[2]};throw new Error("GOTO should not be parsed as an effect");case"ADVANCE":if(n[1]==="time")return{type:"advanceTime",hours:Number(n[2])};throw new Error(`Unknown ADVANCE effect: ${n[1]}`);case"START":if(n[1]==="dialogue")return{type:"startDialogue",dialogueId:n[2]};throw new Error(`Unknown START effect: ${n[1]}`);case"END":if(n[1]==="dialogue")return{type:"endDialogue"};throw new Error("END should not be parsed as an effect");default:throw new Error(`Unknown effect keyword: ${r}`)}}function Oe(t,e,n){const r=t[e],a=w(r.line.substring(7)),s=[],i=[];let o="",l=e+1;const c=r.indent;for(;l<t.length;){const u=t[l];if(u.line==="END"&&u.indent===c){l++;break}if(u.line.startsWith("REQUIRE ")){const g=u.line.substring(8).trim();s.push(I(g)),l++}else if(u.line.startsWith("GOTO ")){const g=u.line.substring(5).trim();if(g.startsWith("location ")){const h=g.substring(9).trim();i.push({type:"goToLocation",locationId:h}),i.push({type:"endDialogue"}),o=""}else o=g;l++}else u.line.includes(":")||i.push(T(u.line)),l++}const d=a.replace(/[@"]/g,"").replace(/[^a-z0-9]/gi,"_");return{choice:{id:`${n}_choice_${d.toLowerCase().substring(0,30)}`,text:a,conditions:s.length>0?s:void 0,effects:i.length>0?i:void 0,next:o||""},nextIndex:l}}function Ve(t,e){const n=t[e],r=n.line.substring(3).trim(),a=I(r);let s;const i=[];let o=e+1;const l=n.indent;for(;o<t.length;){const c=t[o];if(c.line==="END"&&c.indent===l){o++;break}c.line.startsWith("GOTO ")?(s=c.line.substring(5).trim(),o++):(i.push(T(c.line)),o++)}return{condition:a,next:s,effects:i,nextIndex:o}}function Re(t,e){const r=t[e].line.substring(5).trim();let a=null,s="",i,o;const l=[],c=[],d=[];let f;const b=[];let u=e+1;for(;u<t.length;){const h=t[u];if(h.line.startsWith("NODE "))break;if(h.line.includes(":")&&!h.line.startsWith("VOICE")){const p=h.line.indexOf(":"),y=h.line.substring(0,p).trim(),E=h.line.substring(p+1).trim();y==="NARRATOR"?a=null:a=y.toLowerCase(),s=w(E),u++}else if(h.line.startsWith("VOICE "))i=h.line.substring(6).trim(),u++;else if(h.line.startsWith("PORTRAIT "))o=h.line.substring(9).trim(),u++;else if(h.line.startsWith("CHOICE ")){const p=Oe(t,u,r);c.push(p.choice),u=p.nextIndex}else if(h.line.startsWith("IF ")){const p=Ve(t,u);p.next&&b.push({condition:p.condition,next:p.next}),d.push(...p.effects),u=p.nextIndex}else if(h.line.startsWith("GOTO ")){const p=h.line.substring(5).trim();if(p.startsWith("location ")){const y=p.substring(9).trim();d.push({type:"goToLocation",locationId:y}),d.push({type:"endDialogue"})}else f=p;u++}else d.push(T(h.line)),u++}const g={id:r,speaker:a,text:s,voice:i,portrait:o,conditions:l.length>0?l:void 0,choices:c,effects:d.length>0?d:void 0,next:f};return b.length>0&&(g.conditionalNext=b),{node:g,nextIndex:u}}function De(t,e){const n=ke(t);let r;const a=[],s=[];let i="",o=0;for(;o<n.length;){const l=n[o];if(l.line.startsWith("TRIGGER "))r=l.line.substring(8).trim(),o++;else if(l.line.startsWith("REQUIRE ")){const c=l.line.substring(8).trim();a.push(I(c)),o++}else if(l.line.startsWith("NODE ")){const c=Re(n,o);s.push(c.node),i||(i=c.node.id),o=c.nextIndex}else throw new Error(`Unexpected token at line ${l.lineNumber}: ${l.line}`)}return{id:e,triggerLocation:r,conditions:a.length>0?a:void 0,startNode:i,nodes:s}}function Pe(t,e){const n=t;window.doodle={setFlag(r){n.state.flags[r]=!0,e(),console.log(`🐾 Flag set: ${r}`)},clearFlag(r){delete n.state.flags[r],e(),console.log(`🐾 Flag cleared: ${r}`)},setVariable(r,a){n.state.variables[r]=a,e(),console.log(`🐾 Variable set: ${r} = ${a}`)},getVariable(r){const a=n.state.variables[r];return console.log(`🐾 Variable: ${r} = ${a}`),a},teleport(r){t.travelTo(r),e(),console.log(`🐾 Teleported to: ${r}`)},triggerDialogue(r){const a=n.registry.dialogues[r];if(!a){console.error(`🐾 Dialogue not found: ${r}`);return}const s=a.nodes.find(i=>i.id===a.startNode);if(!s){console.error(`🐾 Start node not found for dialogue: ${r}`);return}n.state.dialogueState={dialogueId:a.id,nodeId:s.id},e(),console.log(`🐾 Triggered dialogue: ${r}`)},setQuestStage(r,a){n.state.questProgress[r]=a,e(),console.log(`🐾 Quest stage set: ${r} -> ${a}`)},addItem(r){n.state.inventory.includes(r)?console.log(`🐾 Item already in inventory: ${r}`):(n.state.inventory.push(r),n.state.itemLocations[r]="inventory",e(),console.log(`🐾 Item added: ${r}`))},removeItem(r){const a=n.state.inventory.indexOf(r);a!==-1?(n.state.inventory.splice(a,1),delete n.state.itemLocations[r],e(),console.log(`🐾 Item removed: ${r}`)):console.log(`🐾 Item not in inventory: ${r}`)},inspect(){const r=t.getSnapshot();console.log("🐾 DOODLE ENGINE INSPECTOR 🐾"),console.log(""),console.log("Current Location:",r.location.name),console.log("Current Time:",`Day ${r.time.day}, Hour ${r.time.hour}`),console.log("Flags:",Object.keys(n.state.flags)),console.log("Variables:",n.state.variables),console.log("Inventory:",r.inventory.map(a=>a.name)),console.log("Quest Progress:",n.state.questProgress),console.log(""),console.log("Available commands:"),console.log(" doodle.setFlag(flag)"),console.log(" doodle.clearFlag(flag)"),console.log(" doodle.setVariable(variable, value)"),console.log(" doodle.getVariable(variable)"),console.log(" doodle.teleport(locationId)"),console.log(" doodle.triggerDialogue(dialogueId)"),console.log(" doodle.setQuestStage(questId, stageId)"),console.log(" doodle.addItem(itemId)"),console.log(" doodle.removeItem(itemId)"),console.log(" doodle.inspectState()"),console.log(" doodle.inspectRegistry()")},inspectState(){return console.log("🐾 GAME STATE:",n.state),n.state},inspectRegistry(){return console.log("🐾 CONTENT REGISTRY:",n.registry),n.registry}},console.log("🐾 Doodle Engine dev tools enabled! Type `doodle.inspect()` to see available commands.")}const $e="0.0.1";exports.Engine=xe;exports.VERSION=$e;exports.applyEffect=x;exports.applyEffects=S;exports.buildSnapshot=k;exports.createResolver=Se;exports.enableDevTools=Pe;exports.evaluateCondition=L;exports.evaluateConditions=v;exports.parseCondition=I;exports.parseDialogue=De;exports.parseEffect=T;exports.resolveText=A;
|