Skip to content

Commit

Permalink
inferinput
Browse files Browse the repository at this point in the history
  • Loading branch information
jacc committed Oct 30, 2024
1 parent b2a86dc commit 5c3b69e
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 25 deletions.
101 changes: 89 additions & 12 deletions src/pages/editor/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ const formSchema = v.object({
),
gameVersion: v.string(),
questsCompleted: v.optional(
v.pipe(v.number(), v.minValue(0), v.maxValue(100000)),
v.pipe(
v.union([v.string(), v.number()]),
v.minValue(0),
v.maxValue(100000),
v.transform((v) => Number(v)),
),
),
farmName: v.pipe(
v.string(),
Expand All @@ -67,20 +72,92 @@ const formSchema = v.object({
),
farmType: v.pipe(v.string(), v.minLength(1), v.maxLength(32), v.trim()),
totalMoneyEarned: v.optional(
v.pipe(v.number(), v.minValue(0), v.maxValue(1000000000)),
v.pipe(
v.number(),
v.minValue(0),
v.maxValue(1000000000),
v.transform((v) => Number(v)),
),
),
fishCaught: v.optional(
v.pipe(
v.union([v.string(), v.number()]),
v.minValue(0),
v.maxValue(100000),
v.transform((v) => Number(v)),
),
),
numObelisks: v.optional(
v.pipe(
v.union([v.string(), v.number()]),
v.minValue(0),
v.maxValue(4),
v.transform((v) => Number(v)),
),
),
fishCaught: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(100000))),
numObelisks: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(4))),
goldenClock: v.optional(v.boolean()),
childrenCount: v.optional(v.pipe(v.number(), v.minValue(2), v.maxValue(10))),
childrenCount: v.optional(
v.pipe(
v.string(), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(2),
),
),
houseUpgradeLevel: v.optional(
v.pipe(v.number(), v.minValue(0), v.maxValue(3)),
v.pipe(
v.union([v.string(), v.number()]),
v.minValue(0),
v.maxValue(3),
v.transform((v) => Number(v)),
),
),
farming: v.optional(
v.pipe(
v.string(), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
fishing: v.optional(
v.pipe(
v.string(), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
foraging: v.optional(
v.pipe(
v.string(), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
mining: v.optional(
v.pipe(
v.string(), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
combat: v.optional(
v.pipe(
v.string(), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
farming: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
fishing: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
foraging: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
mining: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
combat: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
});

export default function Editor() {
Expand Down Expand Up @@ -112,7 +189,7 @@ export default function Editor() {
},
});

const onSubmit = async (values: v.InferInput<typeof formSchema>) => {
const onSubmit = async (values: v.InferOutput<typeof formSchema>) => {
setDisabled(true);
const player: PlayerType = {
_id: generateUniqueIdentifier(),
Expand Down
103 changes: 90 additions & 13 deletions src/pages/editor/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ const formSchema = v.object({
),
gameVersion: v.string(),
questsCompleted: v.optional(
v.pipe(v.number(), v.minValue(0), v.maxValue(100000)),
v.pipe(
v.union([v.string(), v.number()]),
v.minValue(0),
v.maxValue(100000),
v.transform((v) => Number(v)),
),
),
farmName: v.pipe(
v.string(),
Expand All @@ -58,20 +63,92 @@ const formSchema = v.object({
),
farmType: v.pipe(v.string(), v.minLength(1), v.maxLength(32), v.trim()),
totalMoneyEarned: v.optional(
v.pipe(v.number(), v.minValue(0), v.maxValue(1000000000)),
v.pipe(
v.number(),
v.minValue(0),
v.maxValue(1000000000),
v.transform((v) => Number(v)),
),
),
fishCaught: v.optional(
v.pipe(
v.union([v.string(), v.number()]),
v.minValue(0),
v.maxValue(100000),
v.transform((v) => Number(v)),
),
),
numObelisks: v.optional(
v.pipe(
v.union([v.string(), v.number()]),
v.minValue(0),
v.maxValue(4),
v.transform((v) => Number(v)),
),
),
fishCaught: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(100000))),
numObelisks: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(4))),
goldenClock: v.optional(v.boolean()),
childrenCount: v.optional(v.pipe(v.number(), v.minValue(2), v.maxValue(10))),
childrenCount: v.optional(
v.pipe(
v.union([v.string(), v.number()]), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(2),
),
),
houseUpgradeLevel: v.optional(
v.pipe(v.number(), v.minValue(0), v.maxValue(3)),
v.pipe(
v.union([v.string(), v.number()]),
v.minValue(0),
v.maxValue(3),
v.transform((v) => Number(v)),
),
),
farming: v.optional(
v.pipe(
v.union([v.string(), v.number()]), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
fishing: v.optional(
v.pipe(
v.union([v.string(), v.number()]), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
foraging: v.optional(
v.pipe(
v.union([v.string(), v.number()]), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
mining: v.optional(
v.pipe(
v.union([v.string(), v.number()]), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
combat: v.optional(
v.pipe(
v.union([v.string(), v.number()]), // Accepts both string and number inputs
v.transform(Number), // Converts to a number
v.number(),
v.minValue(0),
v.maxValue(10),
),
),
farming: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
fishing: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
foraging: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
mining: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
combat: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(10))),
});

export default function Editor() {
Expand Down Expand Up @@ -107,7 +184,7 @@ export default function Editor() {
return [farmName, farmType];
}, [activePlayer]);

const form = useForm<v.InferInput<typeof formSchema>>({
const form = useForm<v.InferOutput<typeof formSchema>>({
resolver: valibotResolver(formSchema as any),
defaultValues: {
name: "",
Expand Down Expand Up @@ -174,7 +251,7 @@ export default function Editor() {
_setGameVersion(activePlayer?.general?.gameVersion ?? undefined);
}, [activePlayer, form, farmListInfo]);

const onSubmit = async (values: v.InferInput<typeof formSchema>) => {
const onSubmit = async (values: v.InferOutput<typeof formSchema>) => {
if (!activePlayer?._id) {
toast.error("An error occurred creating your farmhand.", {
description: (
Expand Down

0 comments on commit 5c3b69e

Please sign in to comment.