Skip to content

Commit

Permalink
Merge pull request #110 from Moros1138/example-dropdown
Browse files Browse the repository at this point in the history
Example dropdown
  • Loading branch information
Moros1138 authored Jun 29, 2024
2 parents 6ec94ab + a2cd934 commit 30ef560
Show file tree
Hide file tree
Showing 26 changed files with 690 additions and 207 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file. Each batch

It is a summary of changes that would be pertinent to the end user of the PGEtinker website. For a comprehensive history of changes made to the project, please refer to the repository's commit history.

## 2024-06-29

- Added example code menu to navbar
- Added example code menu to mobile navigation
- Added PGEtinker Classic Demo to the example code menu
- Added Bare olcPixelGameEngine to the example code menu
- Changed default code to PGEtinker Classic Demo example code
- Removed default code button from settings dialog
- Removed unused api endpoint for default code
- Removed unused function to retrieve default code
- Fixed fieldId should always refresh with each instance of the settings dialog
- Added button to a form group to make the width uniform on the settings dialog
- Changed select now has label and value rather than just label

## 2024-06-25

- Fixed light theme persistence
Expand Down
15 changes: 15 additions & 0 deletions phpunit.dusk.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<testsuites>
<testsuite name="Browser Test Suite">
<directory suffix="Test.php">./tests/Browser</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
colors="true"
>
<testsuites>
<testsuite name="Unit">
<!-- <testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuite> -->
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
Expand Down
11 changes: 8 additions & 3 deletions resources/css/app/navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
display: none;
list-style-type: none;
position: absolute;
margin: 0;
margin: 1px 0 0 0;
padding: 0;
white-space: nowrap;
z-index: 1;
Expand Down Expand Up @@ -108,11 +108,12 @@
}
}

@media screen and (min-width: 761px) and (max-width: 900px) {
@media screen and (min-width: 761px) and (max-width: 1024px) {
#header {
nav {
.menu {
&.left-menu {
&.left-menu,
&.right-menu {
.item > a span {
display: none;
}
Expand All @@ -130,6 +131,10 @@
width: 100%;
}

#examples-menu {
display: none;
}

#settings-menu {
order: 1;
}
Expand Down
119 changes: 119 additions & 0 deletions resources/example1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#endif

// EMSCRIPTEN ONLY!
//
// At runtime, this function attempts to load a file
// from the provided URL, and maps it to emscripten's
// filesystem. You can then use the file in any C/C++
// filesystem function as if it were on the local disk.
void FILE_RESOLVE(const char* url, const char* file)
{
#if defined(__EMSCRIPTEN__)
emscripten_wget(url, file);
emscripten_sleep(0);
#endif
}

// Override base class with your custom functionality
class Example : public olc::PixelGameEngine
{
public:
Example()
{
// Name your application
sAppName = "PGEtinker Classic Example";
}

public:

// OnUserCreate is Called once at the start and
// is where you do things like load files and
// initilize variables.
bool OnUserCreate() override
{
// load "assets/gfx/broken.png" from a URL
FILE_RESOLVE("https://pit.pgetinker.com/MwpptUlwPhnc.png", "assets/gfx/broken.png");

renImageFromUrl.Load("assets/gfx/broken.png");

color = RandomColor();
return true;
}

// OnUserUpdate is called once per frame and
// is where you draw things to the screen
bool OnUserUpdate(float fElapsedTime) override
{
// when you left click the mouse
if(GetMouse(0).bPressed)
{
// change the color
color = RandomColor();

// print out the current mouse position (x, y)
std::cout << GetMousePos() << "\n";
}

// clear the screen to the provided color
Clear(color);

// Draw the yellow outline
DrawRect(0,0,ScreenWidth()-1, ScreenHeight()-1, olc::YELLOW);

// draw some test
DrawStringDropShadow(5, 5, "Hello, PGE", olc::WHITE, olc::BLACK);
DrawStringDropShadow(5, 25, "Mouse position SHOULD match\nclosely to the circle.\n\nYellow borders should ALWAYS\nbe visible\n\nLEFT MOUSE to change color.", olc::WHITE, olc::BLACK);
DrawStringDropShadow(5, 220, GetMousePos().str(), olc::WHITE, olc::BLACK);

// draw the loaded sprite
DrawSprite(5, 100, renImageFromUrl.Sprite());

// draw a circle where the mouse is currently located
FillCircle(GetMousePos(), 3, olc::RED);

// draw a point where the mouse is currently located
Draw(GetMousePos(), olc::WHITE);

return true;
}

void DrawStringDropShadow(const int x, const int y, const std::string& text, const olc::Pixel& foregroundColor, const olc::Pixel& backgroundColor)
{
DrawString(x + 1, y + 1, text, backgroundColor);
DrawString( x, y, text, foregroundColor);
}

olc::Pixel RandomColor()
{
// we limit to the darker half of the colors
return olc::Pixel(rand() % 128, rand() % 128, rand() % 128);
}

public: // class variables

// this is the color that is changed every mouse click
olc::Pixel color;

// this is the sprite that is loaded from a URL
olc::Renderable renImageFromUrl;
};

int main()
{
// an instance of the Example, called demo
Example demo;

// attempt to construct the window/screen 256x240 pixels,
// with pixels that are 2x2. If successful, start
// the demo.
if (demo.Construct(256, 240, 2, 2))
demo.Start();

// this is the end of the program
return 0;
}
46 changes: 46 additions & 0 deletions resources/example2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#endif

void FILE_RESOLVE(const char* url, const char* file)
{
#if defined(__EMSCRIPTEN__)
emscripten_wget(url, file);
emscripten_sleep(0);
#endif
}

// Override base class with your custom functionality
class Example : public olc::PixelGameEngine
{
public:
Example()
{
// Name your application
sAppName = "Bare PGE";
}

public:
bool OnUserCreate() override
{
// Called once at the start, so create things here
return true;
}

bool OnUserUpdate(float fElapsedTime) override
{
// Called once per frame, draws random coloured pixels
return true;
}
};

int main()
{
Example demo;
if (demo.Construct(256, 240, 2, 2))
demo.Start();
return 0;
}
13 changes: 9 additions & 4 deletions resources/example.cpp → resources/example3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@

#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#define FILE_RESOLVE(url, file) emscripten_wget(url, file); emscripten_sleep(0)
#else
#define FILE_RESOLVE(url, file)
#endif

void FILE_RESOLVE(const char* url, const char* file)
{
#if defined(__EMSCRIPTEN__)
emscripten_wget(url, file);
emscripten_sleep(0);
#endif
}

// Override base class with your custom functionality
class Example : public olc::PixelGameEngine
{
public:
Example()
{
// Name your application
sAppName = "Example";
sAppName = "Example 3";
}

public:
Expand Down
81 changes: 81 additions & 0 deletions resources/example4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#endif

void FILE_RESOLVE(const char* url, const char* file)
{
#if defined(__EMSCRIPTEN__)
emscripten_wget(url, file);
emscripten_sleep(0);
#endif
}

// Override base class with your custom functionality
class Example : public olc::PixelGameEngine
{
public:
Example()
{
// Name your application
sAppName = "Example 4";
}

public:
bool OnUserCreate() override
{
// Called once at the start, so create things here

// built with emscripten, maps the url to the virtual filesystem and makes it
// available to the standard C/C++ file i/o functions without change!
//
// built with any other native toolchain, the macro does nothing and all file
// access is done just as it would in any other normal scenario.
FILE_RESOLVE("https://pit.pgetinker.com/MwpptUlwPhnc.png", "assets/gfx/broken.png");

renBroken.Load("assets/gfx/broken.png");

color = RandomColor();
return true;
}

bool OnUserUpdate(float fElapsedTime) override
{
// Called once per frame, draws random coloured pixels
if(GetMouse(0).bPressed)
color = RandomColor();

Clear(color);
DrawRect(0,0,ScreenWidth()-1, ScreenHeight()-1, olc::YELLOW);
DrawString(6, 6, "Hello, PGE", olc::BLACK);
DrawString(5, 5, "Hello, PGE", olc::WHITE);
DrawString(6, 26, "Mouse position SHOULD match\nclosely to the circle.\n\nYellow borders should ALWAYS\nbe visible\n\nLEFT MOUSE to change color.", olc::BLACK);
DrawString(5, 25, "Mouse position SHOULD match\nclosely to the circle.\n\nYellow borders should ALWAYS\nbe visible\n\nLEFT MOUSE to change color.", olc::WHITE);

DrawSprite(5, 100, renBroken.Sprite());

DrawString(6, 221, GetMousePos().str(), olc::BLACK);
DrawString(5, 220, GetMousePos().str(), olc::WHITE);
FillCircle(GetMousePos(), 3, olc::RED);
Draw(GetMousePos(), olc::WHITE);
return true;
}

olc::Pixel RandomColor()
{
return olc::Pixel(rand() % 128, rand() % 128, rand() % 128);
}

olc::Pixel color;
olc::Renderable renBroken;
};

int main()
{
Example demo;
if (demo.Construct(256, 240, 2, 2))
demo.Start();
return 0;
}
Loading

0 comments on commit 30ef560

Please sign in to comment.