@drincs/nqtr
Version:
A complete system introducing the concepts of location, time and event, producing the framework of a not-quite-point-and-click adventure game.
1 lines • 7.39 kB
JavaScript
;var handlers=require('@drincs/nqtr/handlers'),registries=require('@drincs/nqtr/registries'),pixiVnInk=require('@drincs/pixi-vn-ink'),zod=require('zod');var d;(s=>(s.log=(t,...r)=>console.log(`[NQTR] ${t}`,...r),s.warn=(t,...r)=>console.warn(`[NQTR] ${t}`,...r),s.error=(t,...r)=>console.error(`[NQTR] ${t}`,...r),s.info=(t,...r)=>console.info(`[NQTR] ${t}`,...r)))(d||={});function b(a){a||(a={hours:handlers.timeTracker.defaultTimeSpent}),typeof a=="number"&&(a={hours:a});let{hours:c,days:l}=a;l&&handlers.timeTracker.increaseDate(l,handlers.timeTracker.dayStartTime),c&&handlers.timeTracker.increaseTime(c);}function I(a={}){let{timeConverter:c=t=>Number(t.replace(":",".")),dateConverter:l=t=>Number(t),wait:y=b}=a;function s(t){return t&&t.length>0?zod.z.enum(Object.fromEntries(t.map(r=>[r,r]))):zod.z.string()}pixiVnInk.VariableGetter.add((t,r)=>{if(t&&typeof t=="object"&&"type"in t&&"key"in t&&"storageOperationType"in t&&"storageType"in t&&t.storageOperationType==="get"&&(t.storageType==="storage"||t.storageType==="tempstorage"||t.storageType==="flagStorage")){let o=t;if(o.key.endsWith("_currentStageIndex")){let n=o.key.replace("_currentStageIndex",""),i=registries.RegisteredQuests.get(n);return i?i.currentStageIndex:(d.warn(`Quest ${n} not found`),r(t))}else if(o.key.endsWith("_started")){let n=o.key.replace("_started",""),i=registries.RegisteredQuests.get(n);return i?i.started:(d.warn(`Quest ${n} not found`),r(t))}else if(o.key.endsWith("_completed")){let n=o.key.replace("_completed",""),i=registries.RegisteredQuests.get(n);return i?i.completed:(d.warn(`Quest ${n} not found`),r(t))}else if(o.key.endsWith("_failed")){let n=o.key.replace("_failed",""),i=registries.RegisteredQuests.get(n);return i?i.failed:(d.warn(`Quest ${n} not found`),r(t))}}return r(t)}),pixiVnInk.HashtagCommands.add(t=>{let r=registries.RegisteredRooms.get(t[2]);return r?handlers.navigator.currentRoom=r:d.warn(`Room ${t[2]} not found`),true},{name:"Enter room",description:"Enter a room by its ID. This command sets the current room in the navigator to the specified room.\n\n```ink\n# enter room <roomId>\n```",validation:zod.z.tuple([zod.z.literal("enter"),zod.z.literal("room"),s(a.roomIds)])}),pixiVnInk.HashtagCommands.add(t=>{let r=c(t[2]);return Number.isNaN(r)?d.warn(`Invalid time format: ${t[2]}`):handlers.timeTracker.currentTime=r,true},{name:"Set time",description:'Set the current time in the time tracker. The time should be provided in a valid format (e.g., "HH:MM").\n\n```ink\n# set time <time>\n```',validation:zod.z.tuple([zod.z.literal("set"),zod.z.literal("time"),zod.z.string()])}),pixiVnInk.HashtagCommands.add(t=>{let r=l(t[2]);return Number.isNaN(r)?d.warn(`Invalid date format: ${t[2]}`):handlers.timeTracker.currentDate=r,true},{name:"Set date",description:'Set the current date in the time tracker. The date should be provided in a valid format (e.g., "YYYY-MM-DD").\n\n```ink\n# set date <date>\n```',validation:zod.z.tuple([zod.z.literal("set"),zod.z.literal("date"),zod.z.string()])}),pixiVnInk.HashtagCommands.add(t=>{let r=c(t[1]);return Number.isNaN(r)?d.warn(`Invalid time format: ${t[1]}`):y(r),true},{name:"Wait for time",description:'Wait for a specified amount of time. The time should be provided in a valid format (e.g., "HH:MM").\n\n```ink\n# wait <time>\n```',validation:zod.z.tuple([zod.z.literal("wait"),zod.z.string()])}),pixiVnInk.HashtagCommands.add(t=>(y(),true),{name:"Wait",description:"Wait for the default amount of time specified in the time tracker.\n\n```ink\n# wait\n```",validation:zod.z.tuple([zod.z.literal("wait")])}),pixiVnInk.HashtagCommands.add((t,r,o)=>{let n=false,i=o(t.slice(1));return i.hours!==void 0&&typeof i.hours=="string"&&(i.hours=c(i.hours),n=true),i.days!==void 0&&typeof i.days=="string"&&(i.days=l(i.days),n=true),n&&y(i),n},{name:"Wait with options",description:'Wait for a specified amount of time and/or days. You can provide options for hours and days in the format "hours=<time>" and "days=<date>".\n\n```ink\n# wait hours <time> days <date>\n```',validation:zod.z.tuple([zod.z.literal("wait"),zod.z.string(),zod.z.string()]).rest(zod.z.string()),keySchemas:{wait:{type:"object",properties:{hours:{type:["string","number"]},days:{type:["string","number"]}},additionalProperties:false}}}),pixiVnInk.HashtagCommands.add((t,r,o)=>{let n=registries.RegisteredActivities.get(t[2]);if(!n)return d.warn(`Activity ${t[2]} not found`),true;let{in:i}=o(t.slice(3)),u=registries.RegisteredRooms.get(i);return u?u.addActivity(n):d.warn(`Room ${i} not found`),true},{name:"Add activity to room",description:"Add an activity to a specified room. You need to provide the activity ID and the room ID.\n\n```ink\n# add activity <activityId> in <roomId>\n```",validation:zod.z.tuple([zod.z.literal("add"),zod.z.literal("activity"),s(a.activityIds),zod.z.literal("in"),s(a.roomIds)])}),pixiVnInk.HashtagCommands.add((t,r,o)=>{let n=registries.RegisteredActivities.get(t[2]);if(!n)return d.warn(`Activity ${t[2]} not found`),true;let{from:i}=o(t.slice(3)),u=registries.RegisteredRooms.get(i);return u?u.removeActivity(n):d.warn(`Room ${i} not found`),true},{name:"Remove activity from room",description:"Remove an activity from a specified room. You need to provide the activity ID and the room ID.\n\n```ink\n# remove activity <activityId> from <roomId>\n```",validation:zod.z.tuple([zod.z.literal("remove"),zod.z.literal("activity"),s(a.activityIds),zod.z.literal("from"),s(a.roomIds)])}),pixiVnInk.HashtagCommands.add((t,r,o)=>{let n=registries.RegisteredCommitments.get(t[2]);if(!n)return d.warn(`Commitment ${t[2]} not found`),true;let{in:i}=o(t.slice(3)),u=registries.RegisteredRooms.get(i);return u?u.addCommitment(n):d.warn(`Room ${i} not found`),true},{name:"Add commitment to room",description:"Add a commitment to a specified room. You need to provide the commitment ID and the room ID.\n\n```ink\n# add routine <commitmentId> in <roomId>\n```",validation:zod.z.tuple([zod.z.literal("add"),zod.z.literal("routine"),s(a.commitmentIds),zod.z.literal("in"),s(a.roomIds)])}),pixiVnInk.HashtagCommands.add(t=>{let r=registries.RegisteredCommitments.get(t[2]);return r?(handlers.routine.remove(r),true):(d.warn(`Commitment ${t[2]} not found`),true)},{name:"Remove commitment from room",description:"Remove a commitment from the routine. You need to provide the commitment ID.\n\n```ink\n# remove routine <commitmentId>\n```",validation:zod.z.tuple([zod.z.literal("remove"),zod.z.literal("routine"),s(a.commitmentIds)])}),pixiVnInk.HashtagCommands.add((t,r)=>{let o=registries.RegisteredQuests.get(t[2]);return o?(o.start(r),true):(d.warn(`Quest ${t[2]} not found`),true)},{name:"Start quest",description:"Start a quest by its ID. This command will initiate the quest and set it as started.\n\n```ink\n# start quest <questId>\n```",validation:zod.z.tuple([zod.z.literal("start"),zod.z.literal("quest"),s(a.questIds)])}),pixiVnInk.HashtagCommands.add((t,r)=>{let o=registries.RegisteredQuests.get(t[2]);return o?(o.continue(r),true):(d.warn(`Quest ${t[2]} not found`),true)},{name:"Continue quest",description:"Continue a quest by its ID. This command will proceed with the quest if it has been started.\n\n```ink\n# continue quest <questId>\n```",validation:zod.z.tuple([zod.z.literal("continue"),zod.z.literal("quest"),s(a.questIds)])});}function N(a){I(a);}exports.createNqtrHandler=I;exports.nqtrHandler=N;