Skip to content

Commit

Permalink
Move all game assets into an assets folder to clean up root
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopson97 committed Jan 13, 2025
1 parent d955965 commit 7329fe6
Show file tree
Hide file tree
Showing 75 changed files with 195 additions and 145 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local WIDGET_WIDTH = 800
local WIDGET_HEIGHT = 90
local BUTTON_SIZE = GuiDim.new(0, WIDGET_WIDTH, 0, WIDGET_HEIGHT)
local widgetTexture = game.getTexture("res/button.png")
local checkboxTexture_unchecked = game.getTexture("res/checkbox-unchecked.png")
local checkboxTexture_checked = game.getTexture("res/checkbox-checked.png")
local widgetTexture = game.getTexture("assets/textures/button.png")
local checkboxTexture_unchecked = game.getTexture("assets/textures/checkbox-unchecked.png")
local checkboxTexture_checked = game.getTexture("assets/textures/checkbox-checked.png")

StackMenu = {}
StackMenu.__index = StackMenu
Expand Down
4 changes: 2 additions & 2 deletions game/client/hud.lua → assets/game/client/hud.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local crosshairTexture = game.getTexture("res/crosshair.png")
local grass = game.getTexture("texture_packs/default/voxels/grass_side.png")
local crosshairTexture = game.getTexture("assets/textures/crosshair.png")
local grass = game.getTexture("assets/texture_packs/default/voxels/grass_side.png")

local function createHUD(hud)
local crosshair = hud:addImage()
Expand Down
22 changes: 11 additions & 11 deletions game/client/main.lua → assets/game/client/main.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
--
-- Helpers
--
dofile("game/client/gui_helpers/common.lua")
dofile("game/client/gui_helpers/stack_menu.lua")
dofile("assets/game/client/gui_helpers/common.lua")
dofile("assets/game/client/gui_helpers/stack_menu.lua")

--
-- Menus
--
dofile("game/client/menus/main_menu.lua")
dofile("game/client/menus/settings_menu.lua")
dofile("game/client/menus/new_world_menu.lua")
dofile("game/client/menus/join_world_menu.lua")
dofile("game/client/menus/world_select.lua")
dofile("game/client/menus/pause_menu.lua")
dofile("game/client/menus/error_screen.lua")
dofile("game/client/menus/transition_screen.lua")
dofile("assets/game/client/menus/main_menu.lua")
dofile("assets/game/client/menus/settings_menu.lua")
dofile("assets/game/client/menus/new_world_menu.lua")
dofile("assets/game/client/menus/join_world_menu.lua")
dofile("assets/game/client/menus/world_select.lua")
dofile("assets/game/client/menus/pause_menu.lua")
dofile("assets/game/client/menus/error_screen.lua")
dofile("assets/game/client/menus/transition_screen.lua")

--
-- In Game GUIs
--
dofile("game/client/hud.lua")
dofile("assets/game/client/hud.lua")

game.onClientStartup(function()
game.gui():change("main_menu")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

local backgroundTexture = game.getTexture("res/error_bg.png")
local logoTexture = game.getTexture("res/logo.png")
local backgroundTexture = game.getTexture("assets/textures/error_bg.png")
local logoTexture = game.getTexture("assets/textures/logo.png")

local function onCreate(overlay, data)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

local backgroundTexture = game.getTexture("res/menu_bg.png")
local logoTexture = game.getTexture("res/logo.png")
local checkboxTexture_unchecked = game.getTexture("res/checkbox-unchecked.png")
local checkboxTexture_checked = game.getTexture("res/checkbox-checked.png")
local backgroundTexture = game.getTexture("assets/textures/menu_bg.png")
local logoTexture = game.getTexture("assets/textures/logo.png")
local checkboxTexture_unchecked = game.getTexture("assets/textures/checkbox-unchecked.png")
local checkboxTexture_checked = game.getTexture("assets/textures/checkbox-checked.png")

local function onCreate(overlay)
local menu = StackMenu:create(900, overlay, 15)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

local backgroundTexture = game.getTexture("res/menu_bg.png")
local backgroundTexture = game.getTexture("assets/textures/menu_bg.png")

local function onCreate(overlay, data)
local menu = StackMenu:create(900, overlay, 15, "New World")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

local backgroundTexture = game.getTexture("res/menu_bg.png")
local logoTexture = game.getTexture("res/logo.png")
local backgroundTexture = game.getTexture("assets/textures/menu_bg.png")
local logoTexture = game.getTexture("assets/textures/logo.png")

local function onCreate(overlay)
local menu = StackMenu:create(900, overlay, 15, "Settings")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

local backgroundTexture = game.getTexture("res/menu_bg.png")
local backgroundTexture = game.getTexture("assets/textures/menu_bg.png")

local function onCreate(overlay, data)
local label = overlay:addLabel()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

local backgroundTexture = game.getTexture("res/menu_bg.png")
local buttonTexture = game.getTexture("res/button_small.png")
local backgroundTexture = game.getTexture("assets/textures/menu_bg.png")
local buttonTexture = game.getTexture("assets/textures/button_small.png")


local function createWorldSelectButton(menu, slot)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
26 changes: 15 additions & 11 deletions src/client/client_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ bool ClientEngine::init(sf::Window& window)
luaInitClientControlApi(m_lua, m_controller);
luaInitGuiApi(m_lua, m_gui, &m_guiRenderer);

m_lua.runLuaFile("game/client/main.lua");
m_lua.runLuaFile("assets/game/client/main.lua");
m_luaCallbacks.onClientStartup();

m_guiRenderTarget.create(GUI_WIDTH, GUI_HEIGHT);
m_worldRenderTarget.create(ClientConfig::get().windowHeight,
ClientConfig::get().windowWidth);
m_worldRenderTarget.create(ClientConfig::get().windowHeight, ClientConfig::get().windowWidth);

m_screenShader.create("minimal", "minimal");
m_screenBuffer = makeScreenQuadVertexArray();
Expand All @@ -30,13 +29,15 @@ bool ClientEngine::init(sf::Window& window)

void ClientEngine::runClient()
{
while (mp_window->isOpen()) {
while (mp_window->isOpen())
{
pollWindowEvents();
m_game.handleInput(m_keyboard, m_inputState);
update();
render();

if (!m_controller.executeAction(m_game, m_luaCallbacks)) {
if (!m_controller.executeAction(m_game, m_luaCallbacks))
{
mp_window->close();
}
}
Expand All @@ -48,7 +49,8 @@ void ClientEngine::update()
m_fpsCounter.update();
m_game.tick(clock.restart().asSeconds());
m_gui.update();
if (((int)m_fpsCounter.frameCount % 256) == 0) {
if (((int)m_fpsCounter.frameCount % 256) == 0)
{
std::cout << m_fpsCounter.frameTime << '\n';
}
}
Expand All @@ -68,8 +70,7 @@ void ClientEngine::render()
m_gui.render(m_guiRenderer);

// Buffer to window
gl::unbindFramebuffers(ClientConfig::get().windowWidth,
ClientConfig::get().windowHeight);
gl::unbindFramebuffers(ClientConfig::get().windowWidth, ClientConfig::get().windowHeight);
glDisable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT);
auto drawable = m_screenBuffer.getDrawable();
Expand All @@ -91,13 +92,16 @@ void ClientEngine::render()
void ClientEngine::pollWindowEvents()
{
sf::Event event;
while (mp_window->pollEvent(event)) {
if (mp_window->hasFocus()) {
while (mp_window->pollEvent(event))
{
if (mp_window->hasFocus())
{
m_keyboard.update(event);
m_gui.handleEvent(event);
m_game.handleEvent(event);
}
switch (event.type) {
switch (event.type)
{
case sf::Event::MouseWheelScrolled:
m_luaCallbacks.onMouseWheelScroll(event.mouseWheelScroll);
break;
Expand Down
57 changes: 38 additions & 19 deletions src/client/client_state_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include "game/game_type.h"
#include "lua/client_lua_callback.h"

namespace {
namespace
{
using State = ClientStateController::StateId;

class CreateWorldAction final : public ClientStateController::ControlAction {
class CreateWorldAction final : public ClientStateController::ControlAction
{
public:
CreateWorldAction(const std::string& name, const std::string& seed)
: m_worldName(name)
Expand All @@ -18,11 +20,13 @@ namespace {
ClientLuaCallbacks& callbacks) final override
{
game.setGameDefintion<LocalGame>("Test");
if (game.start()) {
if (game.start())
{
callbacks.onEnterGame();
m_currentState = State::InGame;
}
else {
else
{
callbacks.onError("Failed to create world.");
m_currentState = State::InMenu;
}
Expand All @@ -34,7 +38,8 @@ namespace {
const std::string m_worldSeed;
};

class LoadWorldActon final : public ClientStateController::ControlAction {
class LoadWorldActon final : public ClientStateController::ControlAction
{
public:
LoadWorldActon(const std::string& name)
: m_worldName(name)
Expand All @@ -45,11 +50,13 @@ namespace {
ClientLuaCallbacks& callbacks) final override
{
game.setGameDefintion<LocalGame>("Test");
if (game.start()) {
if (game.start())
{
callbacks.onEnterGame();
m_currentState = State::InGame;
}
else {
else
{
callbacks.onError("Failed to load world.");
m_currentState = State::InMenu;
}
Expand All @@ -60,7 +67,8 @@ namespace {
const std::string m_worldName;
};

class JoinServerAction final : public ClientStateController::ControlAction {
class JoinServerAction final : public ClientStateController::ControlAction
{
public:
JoinServerAction(const std::string& serverIp)
: m_serverIp(serverIp)
Expand All @@ -71,11 +79,13 @@ namespace {
ClientLuaCallbacks& callbacks) final override
{
game.setGameDefintion<RemoteGame>(m_serverIp);
if (game.start()) {
if (game.start())
{
callbacks.onEnterGame();
m_currentState = State::InGame;
}
else {
else
{
callbacks.onError("Failed to join world.");
m_currentState = State::InMenu;
}
Expand All @@ -86,7 +96,8 @@ namespace {
const std::string m_serverIp;
};

class ExitGameAction final : public ClientStateController::ControlAction {
class ExitGameAction final : public ClientStateController::ControlAction
{
public:
bool executeAction(Game& game, State& m_currentState,
ClientLuaCallbacks& callbacks) final override
Expand All @@ -98,7 +109,8 @@ namespace {
}
};

class ShutdownGameAction final : public ClientStateController::ControlAction {
class ShutdownGameAction final : public ClientStateController::ControlAction
{
public:
bool executeAction(Game&, State&, ClientLuaCallbacks&) final override
{
Expand All @@ -109,42 +121,48 @@ namespace {

void ClientStateController::createWorld(const std::string& name, const std::string& seed)
{
if (m_currentState == StateId::InMenu) {
if (m_currentState == StateId::InMenu)
{
m_nextAction = std::make_unique<CreateWorldAction>(name, seed);
}
}

void ClientStateController::loadWorld(const std::string& name)
{
if (m_currentState == StateId::InMenu) {
if (m_currentState == StateId::InMenu)
{
m_nextAction = std::make_unique<LoadWorldActon>(name);
}
}

void ClientStateController::joinWorld(const std::string& ipAddress)
{
if (m_currentState == StateId::InMenu) {
if (m_currentState == StateId::InMenu)
{
m_nextAction = std::make_unique<JoinServerAction>(ipAddress);
}
}

void ClientStateController::pauseGame()
{
if (m_currentState == StateId::InGame) {
if (m_currentState == StateId::InGame)
{
m_currentState = StateId::Paused;
}
}

void ClientStateController::resumeGame()
{
if (m_currentState == StateId::Paused) {
if (m_currentState == StateId::Paused)
{
m_currentState = StateId::InGame;
}
}

void ClientStateController::exitGame()
{
if (m_currentState == StateId::Paused || m_currentState == StateId::InGame) {
if (m_currentState == StateId::Paused || m_currentState == StateId::InGame)
{
m_nextAction = std::make_unique<ExitGameAction>();
}
}
Expand All @@ -156,7 +174,8 @@ void ClientStateController::shutdown()

bool ClientStateController::executeAction(Game& game, ClientLuaCallbacks& callbacks)
{
if (m_nextAction) {
if (m_nextAction)
{
bool result = m_nextAction->executeAction(game, m_currentState, callbacks);
m_nextAction.reset();
return result;
Expand Down
Loading

0 comments on commit 7329fe6

Please sign in to comment.