@playcademy/sandbox 0.1.0-beta.4 → 0.1.0-beta.5

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.
Files changed (3) hide show
  1. package/dist/cli.js +52 -19
  2. package/dist/server.js +52 -19
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -77525,7 +77525,7 @@ var userLevels = pgTable("user_levels", {
77525
77525
  userId: text("user_id").primaryKey().references(() => users.id, { onDelete: "cascade" }),
77526
77526
  currentLevel: integer("current_level").notNull().default(1),
77527
77527
  currentXp: integer("current_xp").notNull().default(0),
77528
- totalXpEarned: integer("total_xp_earned").notNull().default(0),
77528
+ totalXP: integer("total_xp").notNull().default(0),
77529
77529
  lastLevelUpAt: timestamp("last_level_up_at", { withTimezone: true }),
77530
77530
  createdAt: timestamp("created_at").defaultNow().notNull(),
77531
77531
  updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().$onUpdate(() => new Date)
@@ -77547,7 +77547,7 @@ var InsertUserLevelSchema = createInsertSchema(userLevels, {
77547
77547
  userId: exports_external.string().min(1, "User ID is required"),
77548
77548
  currentLevel: exports_external.number().int().min(1, "Level must be at least 1").default(1),
77549
77549
  currentXp: exports_external.number().int().min(0, "XP cannot be negative").default(0),
77550
- totalXpEarned: exports_external.number().int().min(0, "Total XP earned cannot be negative").default(0)
77550
+ totalXP: exports_external.number().int().min(0, "Total XP cannot be negative").default(0)
77551
77551
  }).omit({ createdAt: true, updatedAt: true });
77552
77552
  var SelectUserLevelSchema = createSelectSchema(userLevels);
77553
77553
  var UpdateUserLevelSchema = createUpdateSchema(userLevels).omit({
@@ -77659,14 +77659,26 @@ async function seedDemoData(db) {
77659
77659
  function generateLevelConfigs() {
77660
77660
  const configs = [];
77661
77661
  for (let level = 1;level <= 100; level++) {
77662
- const xpRequired = level === 1 ? 0 : Math.floor(50 * Math.pow(level - 1, 1.7));
77663
- let creditsReward = 0;
77664
- if (level > 1) {
77665
- creditsReward = 25 + level * 25;
77666
- if (level % 10 === 1 && level > 1) {
77667
- creditsReward += 75;
77662
+ let xpRequired;
77663
+ if (level === 1) {
77664
+ xpRequired = 0;
77665
+ } else {
77666
+ const baseXp = Math.pow(level - 1, 1.8) * 100;
77667
+ let roundTo;
77668
+ if (level <= 10) {
77669
+ roundTo = 50;
77670
+ } else if (level <= 20) {
77671
+ roundTo = 100;
77672
+ } else if (level <= 50) {
77673
+ roundTo = 250;
77674
+ } else {
77675
+ roundTo = 500;
77668
77676
  }
77677
+ xpRequired = Math.round(baseXp / roundTo) * roundTo;
77669
77678
  }
77679
+ const baseReward = level === 1 ? 0 : 25 + (level - 1) * 25;
77680
+ const bonusReward = Math.floor((level - 1) / 10) * 50;
77681
+ const creditsReward = baseReward + bonusReward;
77670
77682
  configs.push({
77671
77683
  level,
77672
77684
  xpRequired,
@@ -77710,7 +77722,7 @@ async function seedCurrentProjectGame(db, project) {
77710
77722
  // package.json
77711
77723
  var package_default = {
77712
77724
  name: "@playcademy/sandbox",
77713
- version: "0.1.0-beta.3",
77725
+ version: "0.1.0-beta.4",
77714
77726
  description: "Local development server for Playcademy game development",
77715
77727
  type: "module",
77716
77728
  exports: {
@@ -77813,6 +77825,27 @@ async function getUserMe(ctx) {
77813
77825
  }
77814
77826
  }
77815
77827
 
77828
+ // ../data/src/constants.ts
77829
+ var ITEM_INTERNAL_NAMES = {
77830
+ PLAYCADEMY_CREDITS: "PLAYCADEMY_CREDITS",
77831
+ PLAYCADEMY_XP: "PLAYCADEMY_XP",
77832
+ FOUNDING_MEMBER_BADGE: "FOUNDING_MEMBER_BADGE",
77833
+ EARLY_ADOPTER_BADGE: "EARLY_ADOPTER_BADGE",
77834
+ FIRST_GAME_BADGE: "FIRST_GAME_BADGE",
77835
+ COMMON_SWORD: "COMMON_SWORD",
77836
+ SMALL_HEALTH_POTION: "SMALL_HEALTH_POTION",
77837
+ SMALL_BACKPACK: "SMALL_BACKPACK"
77838
+ };
77839
+ var CURRENCIES = {
77840
+ PRIMARY: ITEM_INTERNAL_NAMES.PLAYCADEMY_CREDITS,
77841
+ XP: ITEM_INTERNAL_NAMES.PLAYCADEMY_XP
77842
+ };
77843
+ var BADGES = {
77844
+ FOUNDING_MEMBER: ITEM_INTERNAL_NAMES.FOUNDING_MEMBER_BADGE,
77845
+ EARLY_ADOPTER: ITEM_INTERNAL_NAMES.EARLY_ADOPTER_BADGE,
77846
+ FIRST_GAME: ITEM_INTERNAL_NAMES.FIRST_GAME_BADGE
77847
+ };
77848
+
77816
77849
  // ../api-core/src/utils/levels.ts
77817
77850
  var levelConfigCache = null;
77818
77851
  async function getLevelConfig(db, level) {
@@ -77904,7 +77937,7 @@ async function getUserLevel(ctx) {
77904
77937
  userId: user.id,
77905
77938
  currentLevel: 1,
77906
77939
  currentXp: 0,
77907
- totalXpEarned: 0
77940
+ totalXP: 0
77908
77941
  }).returning();
77909
77942
  if (!newUserLevel) {
77910
77943
  throw ApiError.internal("Failed to create user level record");
@@ -77937,7 +77970,7 @@ async function addXP(ctx, amount) {
77937
77970
  userId: user.id,
77938
77971
  currentLevel: 1,
77939
77972
  currentXp: 0,
77940
- totalXpEarned: 0
77973
+ totalXP: 0
77941
77974
  }).returning();
77942
77975
  if (!newUserLevel) {
77943
77976
  throw ApiError.internal("Failed to create user level record");
@@ -77945,12 +77978,12 @@ async function addXP(ctx, amount) {
77945
77978
  userLevel = newUserLevel;
77946
77979
  }
77947
77980
  const newCurrentXp = userLevel.currentXp + amount;
77948
- const newTotalXpEarned = userLevel.totalXpEarned + amount;
77981
+ const newTotalXP = userLevel.totalXP + amount;
77949
77982
  const levelUpResult = await checkLevelUp(tx, userLevel.currentLevel, newCurrentXp);
77950
77983
  const [updatedUserLevel] = await tx.update(userLevels).set({
77951
77984
  currentLevel: levelUpResult.newLevel,
77952
77985
  currentXp: levelUpResult.remainingXp,
77953
- totalXpEarned: newTotalXpEarned,
77986
+ totalXP: newTotalXP,
77954
77987
  lastLevelUpAt: levelUpResult.leveledUp ? new Date : userLevel.lastLevelUpAt
77955
77988
  }).where(eq(userLevels.userId, user.id)).returning();
77956
77989
  if (!updatedUserLevel) {
@@ -77964,13 +77997,13 @@ async function addXP(ctx, amount) {
77964
77997
  oldLevel: userLevel.currentLevel,
77965
77998
  newLevel: levelUpResult.newLevel,
77966
77999
  xpAdded: amount,
77967
- totalXpEarned: newTotalXpEarned,
78000
+ totalXP: newTotalXP,
77968
78001
  creditsAwarded: creditsToAward
77969
78002
  });
77970
78003
  if (creditsToAward > 0) {
77971
- const [creditsItem] = await tx.select({ id: items.id }).from(items).where(eq(items.internalName, "PLAYCADEMY_CREDITS")).limit(1);
78004
+ const [creditsItem] = await tx.select({ id: items.id }).from(items).where(eq(items.internalName, CURRENCIES.PRIMARY)).limit(1);
77972
78005
  if (!creditsItem) {
77973
- throw ApiError.internal("PLAYCADEMY_CREDITS item not found");
78006
+ throw ApiError.internal(`${CURRENCIES.PRIMARY} item not found`);
77974
78007
  }
77975
78008
  await tx.insert(inventoryItems).values({
77976
78009
  userId: user.id,
@@ -77992,11 +78025,11 @@ async function addXP(ctx, amount) {
77992
78025
  userId: user.id,
77993
78026
  level: userLevel.currentLevel,
77994
78027
  xpAdded: amount,
77995
- totalXpEarned: newTotalXpEarned
78028
+ totalXP: newTotalXP
77996
78029
  });
77997
78030
  }
77998
78031
  return {
77999
- totalXpEarned: newTotalXpEarned,
78032
+ totalXP: newTotalXP,
78000
78033
  newLevel: levelUpResult.newLevel,
78001
78034
  leveledUp: levelUpResult.leveledUp,
78002
78035
  creditsAwarded,
@@ -78046,7 +78079,7 @@ async function getUserLevelProgress(ctx) {
78046
78079
  level: userLevel.currentLevel,
78047
78080
  currentXp: userLevel.currentXp,
78048
78081
  xpToNextLevel,
78049
- totalXpEarned: userLevel.totalXpEarned
78082
+ totalXP: userLevel.totalXP
78050
78083
  };
78051
78084
  } catch (error2) {
78052
78085
  if (error2 instanceof ApiError) {
package/dist/server.js CHANGED
@@ -75615,7 +75615,7 @@ var userLevels = pgTable("user_levels", {
75615
75615
  userId: text("user_id").primaryKey().references(() => users.id, { onDelete: "cascade" }),
75616
75616
  currentLevel: integer("current_level").notNull().default(1),
75617
75617
  currentXp: integer("current_xp").notNull().default(0),
75618
- totalXpEarned: integer("total_xp_earned").notNull().default(0),
75618
+ totalXP: integer("total_xp").notNull().default(0),
75619
75619
  lastLevelUpAt: timestamp("last_level_up_at", { withTimezone: true }),
75620
75620
  createdAt: timestamp("created_at").defaultNow().notNull(),
75621
75621
  updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().$onUpdate(() => new Date)
@@ -75637,7 +75637,7 @@ var InsertUserLevelSchema = createInsertSchema(userLevels, {
75637
75637
  userId: exports_external.string().min(1, "User ID is required"),
75638
75638
  currentLevel: exports_external.number().int().min(1, "Level must be at least 1").default(1),
75639
75639
  currentXp: exports_external.number().int().min(0, "XP cannot be negative").default(0),
75640
- totalXpEarned: exports_external.number().int().min(0, "Total XP earned cannot be negative").default(0)
75640
+ totalXP: exports_external.number().int().min(0, "Total XP cannot be negative").default(0)
75641
75641
  }).omit({ createdAt: true, updatedAt: true });
75642
75642
  var SelectUserLevelSchema = createSelectSchema(userLevels);
75643
75643
  var UpdateUserLevelSchema = createUpdateSchema(userLevels).omit({
@@ -75749,14 +75749,26 @@ async function seedDemoData(db) {
75749
75749
  function generateLevelConfigs() {
75750
75750
  const configs = [];
75751
75751
  for (let level = 1;level <= 100; level++) {
75752
- const xpRequired = level === 1 ? 0 : Math.floor(50 * Math.pow(level - 1, 1.7));
75753
- let creditsReward = 0;
75754
- if (level > 1) {
75755
- creditsReward = 25 + level * 25;
75756
- if (level % 10 === 1 && level > 1) {
75757
- creditsReward += 75;
75752
+ let xpRequired;
75753
+ if (level === 1) {
75754
+ xpRequired = 0;
75755
+ } else {
75756
+ const baseXp = Math.pow(level - 1, 1.8) * 100;
75757
+ let roundTo;
75758
+ if (level <= 10) {
75759
+ roundTo = 50;
75760
+ } else if (level <= 20) {
75761
+ roundTo = 100;
75762
+ } else if (level <= 50) {
75763
+ roundTo = 250;
75764
+ } else {
75765
+ roundTo = 500;
75758
75766
  }
75767
+ xpRequired = Math.round(baseXp / roundTo) * roundTo;
75759
75768
  }
75769
+ const baseReward = level === 1 ? 0 : 25 + (level - 1) * 25;
75770
+ const bonusReward = Math.floor((level - 1) / 10) * 50;
75771
+ const creditsReward = baseReward + bonusReward;
75760
75772
  configs.push({
75761
75773
  level,
75762
75774
  xpRequired,
@@ -75800,7 +75812,7 @@ async function seedCurrentProjectGame(db, project) {
75800
75812
  // package.json
75801
75813
  var package_default = {
75802
75814
  name: "@playcademy/sandbox",
75803
- version: "0.1.0-beta.3",
75815
+ version: "0.1.0-beta.4",
75804
75816
  description: "Local development server for Playcademy game development",
75805
75817
  type: "module",
75806
75818
  exports: {
@@ -75903,6 +75915,27 @@ async function getUserMe(ctx) {
75903
75915
  }
75904
75916
  }
75905
75917
 
75918
+ // ../data/src/constants.ts
75919
+ var ITEM_INTERNAL_NAMES = {
75920
+ PLAYCADEMY_CREDITS: "PLAYCADEMY_CREDITS",
75921
+ PLAYCADEMY_XP: "PLAYCADEMY_XP",
75922
+ FOUNDING_MEMBER_BADGE: "FOUNDING_MEMBER_BADGE",
75923
+ EARLY_ADOPTER_BADGE: "EARLY_ADOPTER_BADGE",
75924
+ FIRST_GAME_BADGE: "FIRST_GAME_BADGE",
75925
+ COMMON_SWORD: "COMMON_SWORD",
75926
+ SMALL_HEALTH_POTION: "SMALL_HEALTH_POTION",
75927
+ SMALL_BACKPACK: "SMALL_BACKPACK"
75928
+ };
75929
+ var CURRENCIES = {
75930
+ PRIMARY: ITEM_INTERNAL_NAMES.PLAYCADEMY_CREDITS,
75931
+ XP: ITEM_INTERNAL_NAMES.PLAYCADEMY_XP
75932
+ };
75933
+ var BADGES = {
75934
+ FOUNDING_MEMBER: ITEM_INTERNAL_NAMES.FOUNDING_MEMBER_BADGE,
75935
+ EARLY_ADOPTER: ITEM_INTERNAL_NAMES.EARLY_ADOPTER_BADGE,
75936
+ FIRST_GAME: ITEM_INTERNAL_NAMES.FIRST_GAME_BADGE
75937
+ };
75938
+
75906
75939
  // ../api-core/src/utils/levels.ts
75907
75940
  var levelConfigCache = null;
75908
75941
  async function getLevelConfig(db, level) {
@@ -75994,7 +76027,7 @@ async function getUserLevel(ctx) {
75994
76027
  userId: user.id,
75995
76028
  currentLevel: 1,
75996
76029
  currentXp: 0,
75997
- totalXpEarned: 0
76030
+ totalXP: 0
75998
76031
  }).returning();
75999
76032
  if (!newUserLevel) {
76000
76033
  throw ApiError.internal("Failed to create user level record");
@@ -76027,7 +76060,7 @@ async function addXP(ctx, amount) {
76027
76060
  userId: user.id,
76028
76061
  currentLevel: 1,
76029
76062
  currentXp: 0,
76030
- totalXpEarned: 0
76063
+ totalXP: 0
76031
76064
  }).returning();
76032
76065
  if (!newUserLevel) {
76033
76066
  throw ApiError.internal("Failed to create user level record");
@@ -76035,12 +76068,12 @@ async function addXP(ctx, amount) {
76035
76068
  userLevel = newUserLevel;
76036
76069
  }
76037
76070
  const newCurrentXp = userLevel.currentXp + amount;
76038
- const newTotalXpEarned = userLevel.totalXpEarned + amount;
76071
+ const newTotalXP = userLevel.totalXP + amount;
76039
76072
  const levelUpResult = await checkLevelUp(tx, userLevel.currentLevel, newCurrentXp);
76040
76073
  const [updatedUserLevel] = await tx.update(userLevels).set({
76041
76074
  currentLevel: levelUpResult.newLevel,
76042
76075
  currentXp: levelUpResult.remainingXp,
76043
- totalXpEarned: newTotalXpEarned,
76076
+ totalXP: newTotalXP,
76044
76077
  lastLevelUpAt: levelUpResult.leveledUp ? new Date : userLevel.lastLevelUpAt
76045
76078
  }).where(eq(userLevels.userId, user.id)).returning();
76046
76079
  if (!updatedUserLevel) {
@@ -76054,13 +76087,13 @@ async function addXP(ctx, amount) {
76054
76087
  oldLevel: userLevel.currentLevel,
76055
76088
  newLevel: levelUpResult.newLevel,
76056
76089
  xpAdded: amount,
76057
- totalXpEarned: newTotalXpEarned,
76090
+ totalXP: newTotalXP,
76058
76091
  creditsAwarded: creditsToAward
76059
76092
  });
76060
76093
  if (creditsToAward > 0) {
76061
- const [creditsItem] = await tx.select({ id: items.id }).from(items).where(eq(items.internalName, "PLAYCADEMY_CREDITS")).limit(1);
76094
+ const [creditsItem] = await tx.select({ id: items.id }).from(items).where(eq(items.internalName, CURRENCIES.PRIMARY)).limit(1);
76062
76095
  if (!creditsItem) {
76063
- throw ApiError.internal("PLAYCADEMY_CREDITS item not found");
76096
+ throw ApiError.internal(`${CURRENCIES.PRIMARY} item not found`);
76064
76097
  }
76065
76098
  await tx.insert(inventoryItems).values({
76066
76099
  userId: user.id,
@@ -76082,11 +76115,11 @@ async function addXP(ctx, amount) {
76082
76115
  userId: user.id,
76083
76116
  level: userLevel.currentLevel,
76084
76117
  xpAdded: amount,
76085
- totalXpEarned: newTotalXpEarned
76118
+ totalXP: newTotalXP
76086
76119
  });
76087
76120
  }
76088
76121
  return {
76089
- totalXpEarned: newTotalXpEarned,
76122
+ totalXP: newTotalXP,
76090
76123
  newLevel: levelUpResult.newLevel,
76091
76124
  leveledUp: levelUpResult.leveledUp,
76092
76125
  creditsAwarded,
@@ -76136,7 +76169,7 @@ async function getUserLevelProgress(ctx) {
76136
76169
  level: userLevel.currentLevel,
76137
76170
  currentXp: userLevel.currentXp,
76138
76171
  xpToNextLevel,
76139
- totalXpEarned: userLevel.totalXpEarned
76172
+ totalXP: userLevel.totalXP
76140
76173
  };
76141
76174
  } catch (error2) {
76142
76175
  if (error2 instanceof ApiError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/sandbox",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.5",
4
4
  "description": "Local development server for Playcademy game development",
5
5
  "type": "module",
6
6
  "exports": {