This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def book_to_json(book: Book): | |
return { | |
"isbn": book.isbn, | |
"title": book.title, | |
"author": book.author, | |
} | |
def book_from_json(data: dict) -> Book: | |
return Book( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def book_list(request: HttpRequest) -> HttpResponse: | |
if request.method == "GET": | |
books = Book.objects.filter(visible=True) | |
if "author" in request.GET: | |
books = books.filter(author__icontains=request.GET["author"]) | |
if "title" in request.GET: | |
books = books.filter(title__icontains=request.GET["title"]) | |
response_data = [book_to_json(book) for book in books] | |
return JsonResponse(response_data, safe=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book(models.Model): | |
isbn = models.CharField(max_length=13) | |
title = models.TextField() | |
author = models.TextField() | |
visible = models.BooleanField(default=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://w3c.github.io/gamepad/#dfn-standard-gamepad-layout | |
const Dpad = { | |
UP: 12, | |
LEFT: 14, | |
RIGHT: 15, | |
DOWN: 13, | |
}; | |
const Buttons = { | |
A: 0, | |
B: 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.signal import convolve2d | |
def get_neighbour_counts(array): | |
kernel = np.array([[1, 1, 1], [1, 0, 1], [1, 1, 1]], dtype=int) | |
return convolve2d(array, kernel, mode="same", boundary="wrap") | |
def get_next_state(state, neighbours): |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.decorators import api_view | |
from rest_framework.response import Response | |
import ajaxmelt | |
@ajaxmelt.register('POST') | |
@api_view | |
@login_required | |
def edit_name(request): | |
campaign = get_object_or_404(Campaign.objects.visible_to(request.user), id=campaign_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) First thing I'd do would be to disconnect all the graphics rendering code from your World and Entity; it's going to be complicated enough without them :-) | |
2) I don't like that an Entity remember its index into the world. Let's revisit a typical roguelike data model: | |
> a World or a Level has a tilemap (floor, walls, or generally - a tight "grid" of walkable and non walkable scenery) and in addition - a number of entities, where every entity stays on one place in the grid. | |
You can have zero or more entities in the same slot - a goblin can stand over a pile of items, for instance. | |
3) Now let's think about the processes that happen. There are processes like movement, attack or picking things up. Let's take movement. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
import subprocess | |
import tempfile | |
import uuid | |
from compressor import base | |
from compressor.conf import settings as compressor_settings | |
from compressor.js import JsCompressor | |
from django.conf import settings | |
from django.core.files import File |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Image format (sized) | Unsized | Compr | Pixel format | Pixel type | | |
|---------------------------------------|--------------------|-------|--------------------|-----------------------------------| | |
| GL_R8 | GL_RED | False | GL_RED | GL_UNSIGNED_BYTE | | |
| GL_R8_SNORM | GL_RED | False | GL_RED | GL_BYTE | | |
| GL_R16 | GL_RED | False | GL_RED | GL_UNSIGNED_SHORT | | |
| GL_R16_SNORM | GL_RED | False | GL_RED | GL_SHORT | | |
| GL_R32F | GL_RED | False | GL_RED | GL_FLOAT | | |
| GL_R8I | GL_RED | False | GL_RED_INTEGER | GL_INT | |
NewerOlder