Improve shop UX, starting balance, and top bar branding.
Give new users 100 free points, allow shop previews regardless of balance, rename clothing items with descriptive labels, and show only the HaBit logo in the top-left.
This commit is contained in:
@@ -24,15 +24,15 @@ where id in (
|
||||
|
||||
insert into public.shop_items (id, name, type, price, image_path)
|
||||
values
|
||||
('pants-3', 'Pants 3', 'pants', 30, '/character/pants/pants-3.png'),
|
||||
('shoes-3', 'Shoes 3', 'shoes', 30, '/character/shoes/shoes-3.png'),
|
||||
('torso-3', 'Torso 3', 'torso', 35, '/character/torso/torso-3.png'),
|
||||
('torso-4', 'Torso 4', 'torso', 40, '/character/torso/torso-4.png'),
|
||||
('head-3', 'Head 3', 'head', 40, '/character/head/head-3.png'),
|
||||
('head-4', 'Head 4', 'head', 45, '/character/head/head-4.png'),
|
||||
('head-5', 'Head 5', 'head', 50, '/character/head/head-5.png'),
|
||||
('head-6', 'Head 6', 'head', 55, '/character/head/head-6.png'),
|
||||
('head-7', 'Head 7', 'head', 60, '/character/head/head-7.png'),
|
||||
('pants-3', 'Utility Cargo Pants', 'pants', 30, '/character/pants/pants-3.png'),
|
||||
('shoes-3', 'Neon Glow Runners', 'shoes', 30, '/character/shoes/shoes-3.png'),
|
||||
('torso-3', 'Cropped Tank Top', 'torso', 35, '/character/torso/torso-3.png'),
|
||||
('torso-4', 'Crimson Plate Armor', 'torso', 40, '/character/torso/torso-4.png'),
|
||||
('head-3', 'Retro Snapback Cap', 'head', 40, '/character/head/head-3.png'),
|
||||
('head-4', 'Fiery Side Mohawk', 'head', 45, '/character/head/head-4.png'),
|
||||
('head-5', 'Crested Warrior Helm', 'head', 50, '/character/head/head-5.png'),
|
||||
('head-6', 'Flowing Side Locks', 'head', 55, '/character/head/head-6.png'),
|
||||
('head-7', 'Messy Shag Cut', 'head', 60, '/character/head/head-7.png'),
|
||||
('room-night', 'Starlit Night', 'room', 40, '/shop/room-night.svg'),
|
||||
('room-forest', 'Mystic Forest', 'room', 50, '/shop/room-forest.svg')
|
||||
on conflict (id) do update
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
-- Replace generic shop item names with descriptive labels.
|
||||
update public.shop_items set name = 'Utility Cargo Pants' where id = 'pants-3';
|
||||
update public.shop_items set name = 'Neon Glow Runners' where id = 'shoes-3';
|
||||
update public.shop_items set name = 'Cropped Tank Top' where id = 'torso-3';
|
||||
update public.shop_items set name = 'Crimson Plate Armor' where id = 'torso-4';
|
||||
update public.shop_items set name = 'Retro Snapback Cap' where id = 'head-3';
|
||||
update public.shop_items set name = 'Fiery Side Mohawk' where id = 'head-4';
|
||||
update public.shop_items set name = 'Crested Warrior Helm' where id = 'head-5';
|
||||
update public.shop_items set name = 'Flowing Side Locks' where id = 'head-6';
|
||||
update public.shop_items set name = 'Messy Shag Cut' where id = 'head-7';
|
||||
@@ -0,0 +1,84 @@
|
||||
-- New users start with 100 free shop points.
|
||||
alter table public.avatar_state
|
||||
alter column coins set default 100;
|
||||
|
||||
create or replace function public.handle_new_user()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
security definer
|
||||
set search_path = public
|
||||
as $$
|
||||
begin
|
||||
insert into public.profiles (id, display_name)
|
||||
values (
|
||||
new.id,
|
||||
coalesce(new.raw_user_meta_data ->> 'display_name', split_part(new.email, '@', 1))
|
||||
)
|
||||
on conflict (id) do nothing;
|
||||
|
||||
insert into public.avatar_state (user_id, coins)
|
||||
values (new.id, 100)
|
||||
on conflict (user_id) do nothing;
|
||||
|
||||
return new;
|
||||
end;
|
||||
$$;
|
||||
|
||||
create or replace function public.purchase_shop_item(p_item_id text)
|
||||
returns jsonb
|
||||
language plpgsql
|
||||
security definer
|
||||
set search_path = public
|
||||
as $$
|
||||
declare
|
||||
v_user_id uuid := auth.uid();
|
||||
v_item public.shop_items%rowtype;
|
||||
v_coins int;
|
||||
begin
|
||||
if v_user_id is null then
|
||||
raise exception 'You must be signed in to purchase items.';
|
||||
end if;
|
||||
|
||||
select * into v_item from public.shop_items where id = p_item_id;
|
||||
if not found then
|
||||
raise exception 'That shop item is no longer available.';
|
||||
end if;
|
||||
|
||||
if exists (
|
||||
select 1 from public.user_items
|
||||
where user_id = v_user_id and item_id = p_item_id
|
||||
) then
|
||||
raise exception 'You already own this item.';
|
||||
end if;
|
||||
|
||||
select coins into v_coins
|
||||
from public.avatar_state
|
||||
where user_id = v_user_id
|
||||
for update;
|
||||
|
||||
if not found then
|
||||
insert into public.avatar_state (user_id, coins) values (v_user_id, 100);
|
||||
v_coins := 100;
|
||||
end if;
|
||||
|
||||
if v_coins < v_item.price then
|
||||
raise exception 'Not enough points for this purchase.';
|
||||
end if;
|
||||
|
||||
update public.avatar_state
|
||||
set coins = v_coins - v_item.price, updated_at = now()
|
||||
where user_id = v_user_id;
|
||||
|
||||
insert into public.user_items (user_id, item_id)
|
||||
values (v_user_id, p_item_id);
|
||||
|
||||
return jsonb_build_object(
|
||||
'item_id', v_item.id,
|
||||
'name', v_item.name,
|
||||
'type', v_item.type,
|
||||
'price', v_item.price,
|
||||
'image_path', v_item.image_path,
|
||||
'coins', v_coins - v_item.price
|
||||
);
|
||||
end;
|
||||
$$;
|
||||
@@ -24,15 +24,15 @@ where id in (
|
||||
|
||||
insert into public.shop_items (id, name, type, price, image_path)
|
||||
values
|
||||
('pants-3', 'Pants 3', 'pants', 30, '/character/pants/pants-3.png'),
|
||||
('shoes-3', 'Shoes 3', 'shoes', 30, '/character/shoes/shoes-3.png'),
|
||||
('torso-3', 'Torso 3', 'torso', 35, '/character/torso/torso-3.png'),
|
||||
('torso-4', 'Torso 4', 'torso', 40, '/character/torso/torso-4.png'),
|
||||
('head-3', 'Head 3', 'head', 40, '/character/head/head-3.png'),
|
||||
('head-4', 'Head 4', 'head', 45, '/character/head/head-4.png'),
|
||||
('head-5', 'Head 5', 'head', 50, '/character/head/head-5.png'),
|
||||
('head-6', 'Head 6', 'head', 55, '/character/head/head-6.png'),
|
||||
('head-7', 'Head 7', 'head', 60, '/character/head/head-7.png'),
|
||||
('pants-3', 'Utility Cargo Pants', 'pants', 30, '/character/pants/pants-3.png'),
|
||||
('shoes-3', 'Neon Glow Runners', 'shoes', 30, '/character/shoes/shoes-3.png'),
|
||||
('torso-3', 'Cropped Tank Top', 'torso', 35, '/character/torso/torso-3.png'),
|
||||
('torso-4', 'Crimson Plate Armor', 'torso', 40, '/character/torso/torso-4.png'),
|
||||
('head-3', 'Retro Snapback Cap', 'head', 40, '/character/head/head-3.png'),
|
||||
('head-4', 'Fiery Side Mohawk', 'head', 45, '/character/head/head-4.png'),
|
||||
('head-5', 'Crested Warrior Helm', 'head', 50, '/character/head/head-5.png'),
|
||||
('head-6', 'Flowing Side Locks', 'head', 55, '/character/head/head-6.png'),
|
||||
('head-7', 'Messy Shag Cut', 'head', 60, '/character/head/head-7.png'),
|
||||
('room-night', 'Starlit Night', 'room', 40, '/shop/room-night.svg'),
|
||||
('room-forest', 'Mystic Forest', 'room', 50, '/shop/room-forest.svg')
|
||||
on conflict (id) do update
|
||||
|
||||
Reference in New Issue
Block a user