From f24ad2d00b6838932a2f107c52176f0633d30060 Mon Sep 17 00:00:00 2001 From: Bram Dingelstad Date: Wed, 12 Aug 2020 15:05:48 +0300 Subject: [PATCH] First commit --- .gitignore | 2 + Game.gd | 30 ++++ Game.tscn | 80 +++++++++ Player.gd | 35 ++++ addons/.DS_Store | Bin 0 -> 6148 bytes addons/NotionGodot/Notion.gd | 96 ++++++++++ addons/NotionGodot/NotionGodot.gd | 10 ++ addons/NotionGodot/notion_godot_list.svg | 164 ++++++++++++++++++ .../NotionGodot/notion_godot_list.svg.import | 34 ++++ addons/NotionGodot/plugin.cfg | 7 + default_env.tres | 7 + notion_godot.svg | 164 ++++++++++++++++++ notion_godot.svg.import | 34 ++++ project.godot | 28 +++ 14 files changed, 691 insertions(+) create mode 100644 .gitignore create mode 100644 Game.gd create mode 100644 Game.tscn create mode 100644 Player.gd create mode 100644 addons/.DS_Store create mode 100644 addons/NotionGodot/Notion.gd create mode 100644 addons/NotionGodot/NotionGodot.gd create mode 100644 addons/NotionGodot/notion_godot_list.svg create mode 100644 addons/NotionGodot/notion_godot_list.svg.import create mode 100644 addons/NotionGodot/plugin.cfg create mode 100644 default_env.tres create mode 100644 notion_godot.svg create mode 100644 notion_godot.svg.import create mode 100644 project.godot diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..271f639 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.import +.DS_Store diff --git a/Game.gd b/Game.gd new file mode 100644 index 0000000..0952b16 --- /dev/null +++ b/Game.gd @@ -0,0 +1,30 @@ +extends Node + +var table + +func _ready(): + $StaticBody2D/Polygon2D.polygon = $StaticBody2D/CollisionPolygon2D.polygon + $Notion.get_page() + table = $Notion.get_table('https://www.notion.so/4564a0a4d8b847919ad25ef705c097a1?v=9694b8b608634ea4bd802d83cddf0122') + +func _on_Notion_block(id, block, _url): + if id == $Notion.blocks[0]: + var text = '' + for piece in block.value.properties.title: + text += piece[0] + + $UI/RichTextLabel.text = text + +func _on_Notion_data(data, return_id): + if table == return_id: + for row in data: + if row.Name == 'Movement speed': + $Player.movement_speed = int(row.Value) + if row.Name == 'Button label': + $UI/Button.text = row.Value + if row.Name == 'Jumping enabled': + $Player.jumping_enabled = row.Value.to_lower() == 'true' + +func _on_Button_pressed(): + var url = 'https://notion.so/' + $Notion.page.replace('-', '') + OS.shell_open(url) diff --git a/Game.tscn b/Game.tscn new file mode 100644 index 0000000..a695c6e --- /dev/null +++ b/Game.tscn @@ -0,0 +1,80 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://addons/NotionGodot/Notion.gd" type="Script" id=1] +[ext_resource path="res://Game.gd" type="Script" id=2] +[ext_resource path="res://notion_godot.svg" type="Texture" id=3] +[ext_resource path="res://Player.gd" type="Script" id=4] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 57.685, 59.8311 ) + +[node name="Game" type="Node2D"] +script = ExtResource( 2 ) + +[node name="Notion" type="Node" parent="."] +script = ExtResource( 1 ) +page = "77351428-f2f8-4386-a559-a5da7eebffa4" +blocks = [ "https://www.notion.so/NotionGodot-77351428f2f84386a559a5da7eebffa4#a6ea70faa47f4ec1831a0c609b5ed9a1" ] + +[node name="UI" type="Control" parent="."] +margin_right = 1024.0 +margin_bottom = 600.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label" type="Label" parent="UI"] +margin_left = 147.47 +margin_top = 43.7246 +margin_right = 229.47 +margin_bottom = 57.7246 +rect_scale = Vector2( 4, 4 ) +text = "NotionGodot" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="RichTextLabel" type="RichTextLabel" parent="UI"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -450.0 +margin_top = -149.0 +margin_right = 6.0 +margin_bottom = 28.0 +rect_scale = Vector2( 2, 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Button" type="Button" parent="UI"] +margin_left = 806.089 +margin_top = 23.0736 +margin_right = 976.089 +margin_bottom = 81.0736 +text = "Placeholder text" + +[node name="StaticBody2D" type="StaticBody2D" parent="."] +position = Vector2( 0, 104 ) + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] +polygon = PoolVector2Array( 1.30652, 468.015, 575.402, 462.353, 634.284, 364.972, 706.754, 428.383, 1029.47, 428.383, 1027.21, -3.03777, 1031.73, 669.571, 0.174164, 665.042, -3.22284, -4.1701 ) + +[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D"] +color = Color( 0.329412, 0.0431373, 0.00784314, 1 ) + +[node name="Player" type="KinematicBody2D" parent="."] +position = Vector2( 80, 64 ) +script = ExtResource( 4 ) +movement_speed = 250 + +[node name="Sprite" type="Sprite" parent="Player"] +scale = Vector2( 0.466924, 0.466924 ) +texture = ExtResource( 3 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"] +shape = SubResource( 1 ) +[connection signal="block" from="Notion" to="." method="_on_Notion_block"] +[connection signal="data" from="Notion" to="." method="_on_Notion_data"] +[connection signal="pressed" from="UI/Button" to="." method="_on_Button_pressed"] diff --git a/Player.gd b/Player.gd new file mode 100644 index 0000000..db957df --- /dev/null +++ b/Player.gd @@ -0,0 +1,35 @@ +extends KinematicBody2D + +export var movement_speed = 100 +export var jumping_enabled = false + +var gravity = 0 +var direction = Vector2.ZERO +var jump_strength = 50 + + +func _ready(): + pass + +func _input(event): + if event is InputEventKey: + if event.pressed: + match event.scancode: + KEY_A: + direction.x = -1 + KEY_D: + direction.x = 1 + KEY_SPACE: + if is_on_floor() and jumping_enabled: + gravity = -9.81 * jump_strength + else: + if [KEY_A, KEY_D].has(event.scancode): + direction = Vector2.ZERO + +func _physics_process(delta): + gravity += 9.81 * 100 * delta + + move_and_slide(Vector2(direction.x * movement_speed, gravity), Vector2(0, -1)) + if is_on_floor(): + gravity = 0 + diff --git a/addons/.DS_Store b/addons/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..da391b139026f5a444eedf7eb77f479e285d8bd3 GIT binary patch literal 6148 zcmeHKyK2Kg5ZrZC2-LVtdB2c9IE+lXH2wh>h7brc1Ua>;d{;g#vkweH7^`s;W?^^k z_I6Ha3awT|bay$uh-^iqg&WF`g{9fK`NB4tQ6L<5oMn(##1nj-8Ml)+)Q|EpQ2{FOuN2UxKlD4iQufxx%UQ22@FU!6e&J?VI|aepG0@vF gHr9@xy(sF6t#Muxr$DD8?{px4222+k6?n7)e>qAO%>V!Z literal 0 HcmV?d00001 diff --git a/addons/NotionGodot/Notion.gd b/addons/NotionGodot/Notion.gd new file mode 100644 index 0000000..bfb48ee --- /dev/null +++ b/addons/NotionGodot/Notion.gd @@ -0,0 +1,96 @@ +tool +extends Node + +signal data(data, url) +signal block(id, block, url) + +const API_ENDPOINT = 'https://notion-api.splitbee.io/v1' + +export(String) var page setget set_page +export(String) var table setget set_table +export(String) var token +export(Array, String) var blocks + +func _ready(): + assert(token != null, 'No token given') + +func get_page(id = page): + assert(id != null, 'No page selected') + if id.begins_with('https://'): + id = strip_url_to_id(id) + return do_request('/page/' + id) + +func get_table(id = table): + assert(id != null, 'No table selected') + if id.begins_with('https://'): + id = strip_url_to_id(id) + return do_request('/table/' + id) + +func do_request(url): + var http = HTTPRequest.new() + var random_id = randi() + add_child(http) + http.connect('request_completed', self, '_on_request_completed', [http, random_id]) + var headers = [ + 'Authorization: Bearer ' + token, + 'Pragma: no-cache', + 'Cache-Control: no-cache' + ] + http.request(API_ENDPOINT + url, headers) + + return random_id + +func id_to_dashed_id(id): + return id.substr(0, 8) + '-' + id.substr(8, 4) + '-' + id.substr(12, 4) + '-' + id.substr(16, 4) + '-' + id.substr(20) + +func strip_url_to_id(url): + if url.find('/') != -1: + url = url.split('/', false)[url.split('/', false).size() - 1] + + if url.find('-') != -1 and url.find('-') == url.rfind('-'): + url = url.split('-')[1] + + if url.find('-') == -1: + url = id_to_dashed_id(url) + + return url + +func _on_request_completed(result, response_code, headers, body, http, return_id): + remove_child(http) + http.queue_free() + + var json_result = JSON.parse(body.get_string_from_utf8()) + if json_result.error != OK: + printerr('Something went wrong parsing the JSON we got back from Notion') + return + + var data = json_result.result + emit_signal('data', data, return_id) + + for block in blocks: + var id + if block.find('#') == -1: + id = block + else: + id = block.split('#')[1] + + if id.find('-') == -1: + id = id_to_dashed_id(id) + + if data.has(id): + emit_signal('block', block, data[id], return_id) + +func set_page(_page): + if _page == null or _page == '': + page = '' + return + + page = strip_url_to_id(_page) + +func set_table(_table): + if _table == null or _table == '': + table = '' + return + + table = strip_url_to_id(_table) + diff --git a/addons/NotionGodot/NotionGodot.gd b/addons/NotionGodot/NotionGodot.gd new file mode 100644 index 0000000..41e7bb8 --- /dev/null +++ b/addons/NotionGodot/NotionGodot.gd @@ -0,0 +1,10 @@ +tool +extends EditorPlugin + + +func _enter_tree(): + add_custom_type("Notion", "Node", preload("Notion.gd"), preload("notion_godot_list.svg")) + + +func _exit_tree(): + remove_custom_type("Notion") diff --git a/addons/NotionGodot/notion_godot_list.svg b/addons/NotionGodot/notion_godot_list.svg new file mode 100644 index 0000000..ce5db5f --- /dev/null +++ b/addons/NotionGodot/notion_godot_list.svg @@ -0,0 +1,164 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/addons/NotionGodot/notion_godot_list.svg.import b/addons/NotionGodot/notion_godot_list.svg.import new file mode 100644 index 0000000..c0aedd9 --- /dev/null +++ b/addons/NotionGodot/notion_godot_list.svg.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/notion_godot_list.svg-d06ab3cc860cb3496e8b90d172a0fb42.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/NotionGodot/notion_godot_list.svg" +dest_files=[ "res://.import/notion_godot_list.svg-d06ab3cc860cb3496e8b90d172a0fb42.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=2.0 diff --git a/addons/NotionGodot/plugin.cfg b/addons/NotionGodot/plugin.cfg new file mode 100644 index 0000000..3e395be --- /dev/null +++ b/addons/NotionGodot/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="NotionGodot" +description="" +author="Bram Dingelstad" +version="0.1" +script="NotionGodot.gd" diff --git a/default_env.tres b/default_env.tres new file mode 100644 index 0000000..20207a4 --- /dev/null +++ b/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment" load_steps=2 format=2] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/notion_godot.svg b/notion_godot.svg new file mode 100644 index 0000000..b00247e --- /dev/null +++ b/notion_godot.svg @@ -0,0 +1,164 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/notion_godot.svg.import b/notion_godot.svg.import new file mode 100644 index 0000000..613f6f3 --- /dev/null +++ b/notion_godot.svg.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/notion_godot.svg-314204e7313cb5b9656f6c08d41886e0.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://notion_godot.svg" +dest_files=[ "res://.import/notion_godot.svg-314204e7313cb5b9656f6c08d41886e0.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=16.0 diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..3df40f4 --- /dev/null +++ b/project.godot @@ -0,0 +1,28 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +_global_script_classes=[ ] +_global_script_class_icons={ + +} + +[application] + +config/name="NotionGodot" +run/main_scene="res://Game.tscn" +config/icon="res://icon.png" + +[editor_plugins] + +enabled=PoolStringArray( "NotionGodot" ) + +[rendering] + +environment/default_environment="res://default_env.tres"