Retrieving Apartment Data and Creating an inventory for furniture

Today I will (hopefully) be getting the apartments loading on the client and populating with furniture. It's been a rough couple of weeks and it'll be nice to be able to see some progress visually in the client. I expect many pitfalls and bugs as that is the way of complex projects, but let's see if I can actually get it done today.

First I need to eat something and get some caffeine in me, didn't get much sleep but that's kinda the norm the last... lifetime for me so I'll be fine.

Music Today

Alright, let's get the data from the DB into the Player's node on the server and then get it sent over to the Client.

Formatted queries to only return data relevant to the tasks.

I need a couple more queries, one to get the SceneName of the Background and one to get the SceneName of each furniture item. I don't want to send any IDs to the client.

Looks like an apartment to me.

Now that that is sitting nice and neat in the player's apartment_data dictionary I can send it over to the client. Hope things keep going this smoothly.

Client is getting the data.

Now to actually USE the data to set up the apartment. I will first need to change where the apartment data is loaded in the client, I should also create a singleton to hold data and functions to deal with apartment data I think, that way I wont have to ask the server for apartment data every time the client loads into the apartment, only when something changes. There are other reasons too, like not wanting to clutter the character data handler with functions meant to handle placing furniture and accessing the apartment's inventory.

Nice place you got here, crazy man in underwear.

Now to furnish with our glorious ugly table. Hope this works as intended.

SHIT DAMN! We got an ugly table.

Welp, I guess I need another apartment and furniture item to test things out a bit more thoroughly.

Now I will use another account and change some stuff in the DB to see if everything is as it should be.

BEFORE

What a nice, ugly table.
New stuff.
Alright, looks like we got what we need.
So, now what? Move the table around?

MOVE, TABLE!

Oh shit, my table's fucking off to space...

It does the thing I want it to do. I will check the remote to make sure I didn't flip x and y though, would be embarassing.

Good, yes. No flipping.

I will make that space background better and probably add twinkly stars when I get around to the detailing and polishing phase, for now I need to decide exactly what my next task is.

Decorating the apartment, well, adding furniture would require me to make an apartment inventory and then write some client-side code to handle placement. I could do that or I can start working on tanks which are basically just tiny apartments inside the apartment...

Should probably finish the apartment functionality, then I can copy and paste a lot.

I guess the next thing to do is model the inventory.

Neat.

Hmm, I can picture the inventory model in my head but I am having a hard time getting an idea what this will all look like client side to materialize. Well, an apartment should have an inventory, that inventory should have many items.

The player should be able to view the inventory, click an item and then it should snap to the mouse cursor? It would require some... fenagling if I wanted to make a mobile client. I'm not a big fan of mobile gaming myself but I know that it's a large audience. Maybe I will deal with that later down the line, it wouldn't be too hard to remap things based on device information. No use overcomplicating what is already complicated.

The object should have collision and prevent the player from overlapping colliders, probably. I think I will allow placement outside of the apartment walls for the time being, I have some stuff in place to make it easier to keep things within but maybe I should just see what happens, might come up with a good reason to allow it. I have a few ideas now but I think I will go through some testing first.

When the player clicks it should place down the item and send it's data to the apartment server so it can be saved. The apartment server should check if the item is in the inventory and not already placed and if all is well, place the item down and save it's placement to the database.

Once the item is placed it should be marked in the inventory as Placed=True so it doesn't show in the inventory anymore.

The player should be able to right-click the items to pick them up and right-click again to put them back in the apartment inventory, I think.

While the item is picked up there should be a rotate button that basically just flips the sprite horizontally, maybe scroll mouse wheel or something, keeping it all in the mouse?

I will need to add a bool field to the placement table for flip_h.

I have an idea to add a radio furniture item(all furniture is scenes, not just simple sprites, so they can be as simple as a sprite or as complex as we need.) that will play a radio stream or some local files if the radio stream is unavailable. Was considering having a community radio station kind of thing with approved tracks and hosts and whatnot. Something for later, maybe. Anyway, on to the database.

Flip_H.

Need to also add this to the server and the client, may as well do it now. But first migrations must be run.

Capital F for false in Python, dummy.

There, flippy.

It does some dumb crap with the shading but that's a problem for future me and that guy's an asshole so fuck 'im.

Now for the apartment inventory... we need to know what the item ID is and if it is currently placed or not. What else? Hmm...

Lunch time, maybe I will think of something while I deal with that.

I'm sure there's something I am missing but not sure what it is.

Good enough to get started, methinks. Now when we generate an apartment we should generate it with two furniture items I guess. The one table that is placed already and one in the inventory to use for testing.

A start.

Now I need to write the inventory creation code in the apartment generator since it's part of the apartment, well, a separate function called at the end of the generation function, but you know I mean, probably.

And now the querying starts...

As I started writing the second inventory item insert statement I realized I should just abstract it to it's own function. Glad I realized that before I got too much further.

func generate_apartment_inventory(apartment_id):
	# Create the apartment inventory, then create a couple items in it.
	var apartment_inventory_id = UUID.v4()
	var apt_inv = database.execute("""
		BEGIN;
		INSERT INTO apartment_house_inventory (id, house_id) values ('%s', '%s');
		COMMIT;
	""" % [apartment_inventory_id, apartment_id])
	# A basic table and a basic table 2 go into the inventory.
	# Who needs a bed?
	add_house_inv_item(1, apartment_inventory_id, true)
	add_house_inv_item(2, apartment_inventory_id)


func add_house_inv_item(item_id, inv_id, in_use = false):
	var inv_item = database.execute("""
		BEGIN;
		INSERT INTO apartment_house_inventory_item (house_inventory_id, item_id, in_use) values ('%s', '%s', '%s');
		COMMIT;
	""" % [inv_id, item_id, in_use])
	return true

Now I wonder where I messed this one up.

I realize I was kinda out of it when I wrote these models, explains the issues I had yesterday with IDs and why I just deleted a bunch of unrelated data because of the cascade. Glad I saw my stupidity NOW rather than later.

Fixing that. Damn mental auto-pilot.

Ah, yeah, I can see my mental powers are dimming, starting to get sleepy and my eyes are stinging. I'll get this inventory generating and probably get out of the office for today. I got a lot done and I face diminishing returns at this point, haven't been doing well the last couple weeks so I should probably listen to my body.

Dumb crap starts now.
func add_house_inv_item(item_id, inv_id, in_use = false):
	var inv_item = database.execute("""
		BEGIN;
		INSERT INTO apartment_house_inventory_item (inventory_id, item_id, in_use) values ('%s', '%s', '%s');
		COMMIT;
	""" % [inv_id, item_id, in_use])
	return true
Offending code, fixed.

Since I blew up Testiclese his son showed up, I think he's out for revenge.

Oh, Hello there.
House generated.
Inventory Generated
Items added to inventory.

Alright, inventory generates correctly now and items are added correctly.

Probably didn't need to model the Inventory, could have just had items belonging to the Apartment itself. Maybe later I will add an item limit or something to justify this.

Inventory data is loading.

I do need to have an item lookup to get the correct data for sending to the client but I feel like if I keep going today there will be more errors to correct than progress made so I am going to go do some chores that require very little of my dwindling brain juice.

Tomorrow I will wire up the inventory to the client and get started with the furniture placement functionality.